refactor: i18n
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import dayjs from 'dayjs'
|
||||
import i18n from 'i18next'
|
||||
import i18n, { Resource } from 'i18next'
|
||||
import LanguageDetector from 'i18next-browser-languagedetector'
|
||||
import { initReactI18next } from 'react-i18next'
|
||||
import ar from './locales/ar'
|
||||
@@ -13,32 +13,29 @@ import pt from './locales/pt'
|
||||
import ru from './locales/ru'
|
||||
import zh from './locales/zh'
|
||||
|
||||
export const LocalizedLanguageNames = {
|
||||
en: 'English',
|
||||
zh: '简体中文',
|
||||
pl: 'Polski',
|
||||
es: 'Español',
|
||||
fr: 'Français',
|
||||
de: 'Deutsch',
|
||||
ja: '日本語',
|
||||
ru: 'Русский',
|
||||
pt: 'Português',
|
||||
ar: 'العربية'
|
||||
}
|
||||
const languages = {
|
||||
en: { resource: en, name: 'English' },
|
||||
zh: { resource: zh, name: '简体中文' },
|
||||
pl: { resource: pl, name: 'Polski' },
|
||||
es: { resource: es, name: 'Español' },
|
||||
fr: { resource: fr, name: 'Français' },
|
||||
de: { resource: de, name: 'Deutsch' },
|
||||
ja: { resource: ja, name: '日本語' },
|
||||
ru: { resource: ru, name: 'Русский' },
|
||||
pt: { resource: pt, name: 'Português' },
|
||||
ar: { resource: ar, name: 'العربية' }
|
||||
} as const
|
||||
|
||||
const resources = {
|
||||
en,
|
||||
zh,
|
||||
pl,
|
||||
es,
|
||||
fr,
|
||||
de,
|
||||
ja,
|
||||
ru,
|
||||
pt,
|
||||
ar
|
||||
export type TLanguage = keyof typeof languages
|
||||
export const LocalizedLanguageNames: { [key in TLanguage]?: string } = {}
|
||||
const resources: { [key in TLanguage]?: Resource } = {}
|
||||
const supportedLanguages: TLanguage[] = []
|
||||
for (const [key, value] of Object.entries(languages)) {
|
||||
const lang = key as TLanguage
|
||||
LocalizedLanguageNames[lang] = value.name
|
||||
resources[lang] = value.resource
|
||||
supportedLanguages.push(lang)
|
||||
}
|
||||
const supportedLanguages = Object.keys(resources)
|
||||
|
||||
i18n
|
||||
.use(LanguageDetector)
|
||||
@@ -58,34 +55,22 @@ i18n
|
||||
})
|
||||
|
||||
i18n.services.formatter?.add('date', (timestamp, lng) => {
|
||||
if (lng?.startsWith('zh')) {
|
||||
return dayjs(timestamp).format('YYYY年MM月DD日')
|
||||
switch (lng) {
|
||||
case 'zh':
|
||||
case 'ja':
|
||||
return dayjs(timestamp).format('YYYY年MM月DD日')
|
||||
case 'pl':
|
||||
case 'de':
|
||||
case 'ru':
|
||||
return dayjs(timestamp).format('DD.MM.YYYY')
|
||||
case 'es':
|
||||
case 'fr':
|
||||
case 'pt':
|
||||
case 'ar':
|
||||
return dayjs(timestamp).format('DD/MM/YYYY')
|
||||
default:
|
||||
return dayjs(timestamp).format('MMM D, YYYY')
|
||||
}
|
||||
if (lng?.startsWith('pl')) {
|
||||
return dayjs(timestamp).format('DD.MM.YYYY')
|
||||
}
|
||||
if (lng?.startsWith('ja')) {
|
||||
return dayjs(timestamp).format('YYYY年MM月DD日')
|
||||
}
|
||||
if (lng?.startsWith('de')) {
|
||||
return dayjs(timestamp).format('DD.MM.YYYY')
|
||||
}
|
||||
if (lng?.startsWith('ru')) {
|
||||
return dayjs(timestamp).format('DD.MM.YYYY')
|
||||
}
|
||||
if (lng?.startsWith('es')) {
|
||||
return dayjs(timestamp).format('DD/MM/YYYY')
|
||||
}
|
||||
if (lng?.startsWith('fr')) {
|
||||
return dayjs(timestamp).format('DD/MM/YYYY')
|
||||
}
|
||||
if (lng?.startsWith('pt')) {
|
||||
return dayjs(timestamp).format('DD/MM/YYYY')
|
||||
}
|
||||
if (lng?.startsWith('ar')) {
|
||||
return dayjs(timestamp).format('DD/MM/YYYY')
|
||||
}
|
||||
return dayjs(timestamp).format('MMM D, YYYY')
|
||||
})
|
||||
|
||||
export default i18n
|
||||
|
||||
@@ -202,6 +202,5 @@ export default {
|
||||
'تبرعك يساعد في صيانة Jumble وتحسينه! 😊',
|
||||
'Earlier notifications': 'الإشعارات السابقة',
|
||||
'Temporarily display this note': 'عرض هذه الملاحظة مؤقتاً'
|
||||
// ...existing code...
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ export default {
|
||||
'Display replies': 'Antworten anzeigen',
|
||||
Notes: 'Notizen',
|
||||
Replies: 'Antworten',
|
||||
Notifications: 'Benachr.', // shortened from 'Benachrichtigungen'
|
||||
Notifications: 'Benachr.',
|
||||
'no more notifications': 'keine weiteren Benachrichtigungen',
|
||||
'Using private key login is insecure. It is recommended to use a browser extension for login, such as alby, nostr-keyx or nos2x.':
|
||||
'Die Anmeldung mit privatem Schlüssel ist unsicher. Es wird empfohlen, eine Browsererweiterung wie alby, nostr-keyx oder nos2x zu verwenden.',
|
||||
|
||||
@@ -22,7 +22,7 @@ export default {
|
||||
'n h': '{{n}}h',
|
||||
'n days ago': 'hace {{n}} días',
|
||||
'n d': '{{n}}d',
|
||||
date: '{{timestamp, date}}', // ...existing code...
|
||||
date: '{{timestamp, date}}',
|
||||
Follow: 'Seguir',
|
||||
Unfollow: 'Dejar de seguir',
|
||||
'Follow failed': 'Error al seguir',
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
import AboutInfoDialog from '@/components/AboutInfoDialog'
|
||||
import Donation from '@/components/Donation'
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger } from '@/components/ui/select'
|
||||
import { LocalizedLanguageNames } from '@/i18n'
|
||||
import { LocalizedLanguageNames, TLanguage } from '@/i18n'
|
||||
import SecondaryPageLayout from '@/layouts/SecondaryPageLayout'
|
||||
import { toRelaySettings, toWallet } from '@/lib/link'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { useSecondaryPage } from '@/PageManager'
|
||||
import { useNostr } from '@/providers/NostrProvider'
|
||||
import { useTheme } from '@/providers/ThemeProvider'
|
||||
import { TLanguage } from '@/types'
|
||||
import { SelectValue } from '@radix-ui/react-select'
|
||||
import {
|
||||
Check,
|
||||
|
||||
Reference in New Issue
Block a user