diff options
| author | Armand Philippot <git@armandphilippot.com> | 2021-12-13 12:35:10 +0100 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2021-12-13 12:35:10 +0100 |
| commit | 8c836de71b47744ec3e99cb8b3c853528fa66b52 (patch) | |
| tree | b4d1d0cf88b02457cfc4be7afd7586cc83b4ccfb /src/utils | |
| parent | 4cae14b9f86609b8c1f74d97a033e7091af49cb4 (diff) | |
chore: load i18n translations using lingui provider
Diffstat (limited to 'src/utils')
| -rw-r--r-- | src/utils/helpers/i18n.ts | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/utils/helpers/i18n.ts b/src/utils/helpers/i18n.ts new file mode 100644 index 0000000..38616a2 --- /dev/null +++ b/src/utils/helpers/i18n.ts @@ -0,0 +1,35 @@ +import type { I18n } from '@lingui/core'; +import { en, fr } from 'make-plural/plurals'; + +export interface LocaleData { + messages: object; + default: object; +} + +export const locales = { + en: 'English', + fr: 'Français', +}; + +export const defaultLocale = 'fr'; + +export function initTranslation(i18n: I18n): void { + i18n.loadLocaleData({ + en: { plurals: en }, + fr: { plurals: fr }, + }); +} + +export async function loadTranslation( + locale: string, + isProduction: boolean = true +) { + let data: LocaleData; + if (isProduction) { + data = await import(`src/i18n/${locale}/messages`); + } else { + data = await import(`@lingui/loader!src/i18n/${locale}/messages.po`); + } + + return data.messages; +} |
