diff --git a/src/i18n/index.ts b/src/i18n/index.ts index 409309de..09d14797 100644 --- a/src/i18n/index.ts +++ b/src/i18n/index.ts @@ -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 diff --git a/src/i18n/locales/ar.ts b/src/i18n/locales/ar.ts index b722155d..64442832 100644 --- a/src/i18n/locales/ar.ts +++ b/src/i18n/locales/ar.ts @@ -202,6 +202,5 @@ export default { 'تبرعك يساعد في صيانة Jumble وتحسينه! 😊', 'Earlier notifications': 'الإشعارات السابقة', 'Temporarily display this note': 'عرض هذه الملاحظة مؤقتاً' - // ...existing code... } } diff --git a/src/i18n/locales/de.ts b/src/i18n/locales/de.ts index 074a5c8f..d540b7e4 100644 --- a/src/i18n/locales/de.ts +++ b/src/i18n/locales/de.ts @@ -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.', diff --git a/src/i18n/locales/es.ts b/src/i18n/locales/es.ts index 2a988052..4679b69b 100644 --- a/src/i18n/locales/es.ts +++ b/src/i18n/locales/es.ts @@ -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', diff --git a/src/pages/secondary/SettingsPage/index.tsx b/src/pages/secondary/SettingsPage/index.tsx index bd1fa198..21755bc6 100644 --- a/src/pages/secondary/SettingsPage/index.tsx +++ b/src/pages/secondary/SettingsPage/index.tsx @@ -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,