2024-05-07 01:55:57 +02:00
|
|
|
import '@formatjs/intl-locale/polyfill'
|
|
|
|
import '@formatjs/intl-pluralrules/polyfill'
|
|
|
|
import '@formatjs/intl-pluralrules/locale-data/en'
|
|
|
|
|
2023-11-20 22:29:27 +01:00
|
|
|
import {useEffect} from 'react'
|
2023-12-06 02:51:50 +01:00
|
|
|
import {i18n} from '@lingui/core'
|
|
|
|
|
2024-04-04 01:50:15 +02:00
|
|
|
import {sanitizeAppLanguageSetting} from '#/locale/helpers'
|
|
|
|
import {AppLanguage} from '#/locale/languages'
|
|
|
|
import {messages as messagesCa} from '#/locale/locales/ca/messages'
|
2024-01-24 05:39:35 +01:00
|
|
|
import {messages as messagesDe} from '#/locale/locales/de/messages'
|
2024-04-04 01:50:15 +02:00
|
|
|
import {messages as messagesEn} from '#/locale/locales/en/messages'
|
2024-01-03 19:14:36 +01:00
|
|
|
import {messages as messagesEs} from '#/locale/locales/es/messages'
|
2024-02-19 07:09:49 +01:00
|
|
|
import {messages as messagesFi} from '#/locale/locales/fi/messages'
|
2024-01-03 12:34:21 +01:00
|
|
|
import {messages as messagesFr} from '#/locale/locales/fr/messages'
|
2024-04-04 02:32:53 +02:00
|
|
|
import {messages as messagesGa} from '#/locale/locales/ga/messages'
|
2024-01-03 12:34:21 +01:00
|
|
|
import {messages as messagesHi} from '#/locale/locales/hi/messages'
|
2024-04-04 01:50:15 +02:00
|
|
|
import {messages as messagesId} from '#/locale/locales/id/messages'
|
|
|
|
import {messages as messagesIt} from '#/locale/locales/it/messages'
|
2024-01-03 12:34:21 +01:00
|
|
|
import {messages as messagesJa} from '#/locale/locales/ja/messages'
|
|
|
|
import {messages as messagesKo} from '#/locale/locales/ko/messages'
|
2024-01-03 19:45:56 +01:00
|
|
|
import {messages as messagesPt_BR} from '#/locale/locales/pt-BR/messages'
|
2024-04-04 01:50:15 +02:00
|
|
|
import {messages as messagesTr} from '#/locale/locales/tr/messages'
|
2024-01-03 21:22:55 +01:00
|
|
|
import {messages as messagesUk} from '#/locale/locales/uk/messages'
|
2024-02-05 23:50:10 +01:00
|
|
|
import {messages as messagesZh_CN} from '#/locale/locales/zh-CN/messages'
|
2024-04-03 23:30:04 +02:00
|
|
|
import {messages as messagesZh_TW} from '#/locale/locales/zh-TW/messages'
|
2024-04-04 01:50:15 +02:00
|
|
|
import {useLanguagePrefs} from '#/state/preferences'
|
2023-11-09 19:04:16 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* We do a dynamic import of just the catalog that we need
|
|
|
|
*/
|
2023-12-12 19:42:11 +01:00
|
|
|
export async function dynamicActivate(locale: AppLanguage) {
|
|
|
|
switch (locale) {
|
2024-04-04 19:51:54 +02:00
|
|
|
case AppLanguage.ca: {
|
|
|
|
i18n.loadAndActivate({locale, messages: messagesCa})
|
2024-05-07 01:55:57 +02:00
|
|
|
await import('@formatjs/intl-pluralrules/locale-data/ca')
|
2024-04-04 19:51:54 +02:00
|
|
|
break
|
|
|
|
}
|
2024-01-24 05:39:35 +01:00
|
|
|
case AppLanguage.de: {
|
|
|
|
i18n.loadAndActivate({locale, messages: messagesDe})
|
2024-05-07 01:55:57 +02:00
|
|
|
await import('@formatjs/intl-pluralrules/locale-data/de')
|
2024-01-24 05:39:35 +01:00
|
|
|
break
|
|
|
|
}
|
2024-01-03 19:14:36 +01:00
|
|
|
case AppLanguage.es: {
|
|
|
|
i18n.loadAndActivate({locale, messages: messagesEs})
|
2024-05-07 01:55:57 +02:00
|
|
|
await import('@formatjs/intl-pluralrules/locale-data/es')
|
2024-01-03 19:14:36 +01:00
|
|
|
break
|
|
|
|
}
|
2024-03-19 21:04:45 +01:00
|
|
|
case AppLanguage.fi: {
|
2024-02-19 06:42:07 +01:00
|
|
|
i18n.loadAndActivate({locale, messages: messagesFi})
|
2024-05-07 01:55:57 +02:00
|
|
|
await import('@formatjs/intl-pluralrules/locale-data/fi')
|
2024-02-19 06:42:07 +01:00
|
|
|
break
|
2024-03-19 21:04:45 +01:00
|
|
|
}
|
2024-01-03 12:34:21 +01:00
|
|
|
case AppLanguage.fr: {
|
|
|
|
i18n.loadAndActivate({locale, messages: messagesFr})
|
2024-05-07 01:55:57 +02:00
|
|
|
await import('@formatjs/intl-pluralrules/locale-data/fr')
|
2024-01-03 12:34:21 +01:00
|
|
|
break
|
|
|
|
}
|
2024-04-04 02:32:53 +02:00
|
|
|
case AppLanguage.ga: {
|
|
|
|
i18n.loadAndActivate({locale, messages: messagesGa})
|
2024-05-07 01:55:57 +02:00
|
|
|
await import('@formatjs/intl-pluralrules/locale-data/ga')
|
2024-04-04 02:32:53 +02:00
|
|
|
break
|
|
|
|
}
|
2024-01-03 12:34:21 +01:00
|
|
|
case AppLanguage.hi: {
|
|
|
|
i18n.loadAndActivate({locale, messages: messagesHi})
|
2024-05-07 01:55:57 +02:00
|
|
|
await import('@formatjs/intl-pluralrules/locale-data/hi')
|
2024-01-03 12:34:21 +01:00
|
|
|
break
|
|
|
|
}
|
2024-01-11 08:07:47 +01:00
|
|
|
case AppLanguage.id: {
|
|
|
|
i18n.loadAndActivate({locale, messages: messagesId})
|
2024-05-07 01:55:57 +02:00
|
|
|
await import('@formatjs/intl-pluralrules/locale-data/id')
|
2024-01-11 08:07:47 +01:00
|
|
|
break
|
|
|
|
}
|
2024-04-04 19:51:54 +02:00
|
|
|
case AppLanguage.it: {
|
|
|
|
i18n.loadAndActivate({locale, messages: messagesIt})
|
2024-05-07 01:55:57 +02:00
|
|
|
await import('@formatjs/intl-pluralrules/locale-data/it')
|
2024-04-04 19:51:54 +02:00
|
|
|
break
|
|
|
|
}
|
2024-01-03 12:34:21 +01:00
|
|
|
case AppLanguage.ja: {
|
|
|
|
i18n.loadAndActivate({locale, messages: messagesJa})
|
2024-05-07 01:55:57 +02:00
|
|
|
await import('@formatjs/intl-pluralrules/locale-data/ja')
|
2024-01-03 12:34:21 +01:00
|
|
|
break
|
|
|
|
}
|
|
|
|
case AppLanguage.ko: {
|
|
|
|
i18n.loadAndActivate({locale, messages: messagesKo})
|
2024-05-07 01:55:57 +02:00
|
|
|
await import('@formatjs/intl-pluralrules/locale-data/ko')
|
2024-01-03 12:34:21 +01:00
|
|
|
break
|
|
|
|
}
|
2024-01-03 19:45:56 +01:00
|
|
|
case AppLanguage.pt_BR: {
|
|
|
|
i18n.loadAndActivate({locale, messages: messagesPt_BR})
|
2024-05-07 01:55:57 +02:00
|
|
|
await import('@formatjs/intl-pluralrules/locale-data/pt')
|
2024-01-03 19:45:56 +01:00
|
|
|
break
|
|
|
|
}
|
2024-04-04 19:51:54 +02:00
|
|
|
case AppLanguage.tr: {
|
|
|
|
i18n.loadAndActivate({locale, messages: messagesTr})
|
2024-05-07 01:55:57 +02:00
|
|
|
await import('@formatjs/intl-pluralrules/locale-data/tr')
|
2024-01-03 21:22:55 +01:00
|
|
|
break
|
|
|
|
}
|
2024-04-04 19:51:54 +02:00
|
|
|
case AppLanguage.uk: {
|
|
|
|
i18n.loadAndActivate({locale, messages: messagesUk})
|
2024-05-07 01:55:57 +02:00
|
|
|
await import('@formatjs/intl-pluralrules/locale-data/uk')
|
2024-01-19 06:54:00 +01:00
|
|
|
break
|
|
|
|
}
|
2024-02-05 23:50:10 +01:00
|
|
|
case AppLanguage.zh_CN: {
|
|
|
|
i18n.loadAndActivate({locale, messages: messagesZh_CN})
|
2024-05-07 01:55:57 +02:00
|
|
|
await import('@formatjs/intl-pluralrules/locale-data/zh')
|
2024-02-13 19:01:59 +01:00
|
|
|
break
|
|
|
|
}
|
2024-04-03 23:30:04 +02:00
|
|
|
case AppLanguage.zh_TW: {
|
|
|
|
i18n.loadAndActivate({locale, messages: messagesZh_TW})
|
2024-05-07 01:55:57 +02:00
|
|
|
await import('@formatjs/intl-pluralrules/locale-data/zh')
|
2024-04-04 01:50:15 +02:00
|
|
|
break
|
|
|
|
}
|
2023-12-12 19:42:11 +01:00
|
|
|
default: {
|
|
|
|
i18n.loadAndActivate({locale, messages: messagesEn})
|
|
|
|
break
|
|
|
|
}
|
2023-11-20 22:29:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function useLocaleLanguage() {
|
|
|
|
const {appLanguage} = useLanguagePrefs()
|
|
|
|
useEffect(() => {
|
2023-12-12 00:34:18 +01:00
|
|
|
dynamicActivate(sanitizeAppLanguageSetting(appLanguage))
|
2023-11-20 22:29:27 +01:00
|
|
|
}, [appLanguage])
|
2023-11-09 19:04:16 +01:00
|
|
|
}
|