diff --git a/js/src/i18n/en_US.json b/js/src/i18n/en_US.json index 08a09e54d..33f56d792 100644 --- a/js/src/i18n/en_US.json +++ b/js/src/i18n/en_US.json @@ -174,7 +174,7 @@ "Instance Terms": "Instance Terms", "Instance settings": "Instance settings", "Instances": "Instances", - "Join {instance}, a Mobilizon instance": "Join {instance}, a Mobilizon instance", + "Join {instance}, a Mobilizon instance": "Join {instance}, a Mobilizon instance", "Last published event": "Last published event", "Last week": "Last week", "Learn more about Mobilizon": "Learn more about Mobilizon", @@ -466,7 +466,6 @@ "Contact": "Contact", "Website": "Website", "Actor": "Actor", - "Statut": "Statut", "Text": "Text", "All group members and other eventual server admins will still be able to view this information.": "All group members and other eventual server admins will still be able to view this information.", "Upcoming events": "Upcoming events", diff --git a/js/src/i18n/fr_FR.json b/js/src/i18n/fr_FR.json index 49de14720..f2591f631 100644 --- a/js/src/i18n/fr_FR.json +++ b/js/src/i18n/fr_FR.json @@ -336,7 +336,7 @@ "Invited": "Invité·e", "Italic": "Italique", "Join group": "Rejoindre le groupe", - "Join {instance}, a Mobilizon instance": "Rejoignez {instance}, une instance Mobilizon", + "Join {instance}, a Mobilizon instance": "Rejoignez {instance}, une instance Mobilizon", "Keep the entire conversation about a specific topic together on a single page.": "Rassemblez sur une seule page toute la conversation à propos d'un sujet spécifique.", "Key words": "Mots clés", "Language": "Langue", diff --git a/js/src/utils/i18n.ts b/js/src/utils/i18n.ts index 7c412204d..cd28c6953 100644 --- a/js/src/utils/i18n.ts +++ b/js/src/utils/i18n.ts @@ -4,7 +4,7 @@ import { DateFnsPlugin } from "@/plugins/dateFns"; import en from "../i18n/en_US.json"; import langs from "../i18n/langs.json"; -const DEFAULT_LOCALE = "en"; +const DEFAULT_LOCALE = "en_US"; let language = document.documentElement.getAttribute("lang") as string; language = language || ((window.navigator as any).userLanguage || window.navigator.language).replace(/-/, "_"); @@ -13,36 +13,47 @@ export const locale = Vue.use(VueI18n); -console.log(en); -console.log(locale); export const i18n = new VueI18n({ locale: DEFAULT_LOCALE, // set locale - messages: (en as unknown) as VueI18n.LocaleMessages, // set locale messages - fallbackLocale: "en", + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + messages: en, // set locale messages + fallbackLocale: DEFAULT_LOCALE, }); -console.log(i18n); -Vue.use(DateFnsPlugin, { locale }); - -const loadedLanguages = ["en"]; +const loadedLanguages = [DEFAULT_LOCALE]; function setI18nLanguage(lang: string): string { i18n.locale = lang; return lang; } -function fileForLanguage(lang: string) { - const matches: Record = { - fr: "fr_FR", - en: "en_US", - }; +function fileForLanguage(matches: Record, lang: string) { if (Object.prototype.hasOwnProperty.call(matches, lang)) { return matches[lang]; } return lang; } -export async function loadLanguageAsync(lang: string): Promise { +function vueI18NfileForLanguage(lang: string) { + const matches: Record = { + fr: "fr_FR", + en: "en_US", + }; + return fileForLanguage(matches, lang); +} + +function dateFnsfileForLanguage(lang: string) { + const matches: Record = { + en_US: "en-US", + en: "en-US", + }; + return fileForLanguage(matches, lang); +} + +Vue.use(DateFnsPlugin, { locale: dateFnsfileForLanguage(locale) }); + +async function loadLanguageAsync(lang: string): Promise { // If the same language if (i18n.locale === lang) { return Promise.resolve(setI18nLanguage(lang)); @@ -53,15 +64,13 @@ export async function loadLanguageAsync(lang: string): Promise { return Promise.resolve(setI18nLanguage(lang)); } - console.log(fileForLanguage(lang)); // If the language hasn't been loaded yet - return import(/* webpackChunkName: "lang-[request]" */ `@/i18n/${fileForLanguage(lang)}.json`).then( - (newMessages: any) => { - i18n.setLocaleMessage(lang, newMessages.default); - loadedLanguages.push(lang); - return setI18nLanguage(lang); - } + const newMessages = await import( + /* webpackChunkName: "lang-[request]" */ `@/i18n/${vueI18NfileForLanguage(lang)}.json` ); + i18n.setLocaleMessage(lang, newMessages.default); + loadedLanguages.push(lang); + return setI18nLanguage(lang); } loadLanguageAsync(locale); diff --git a/js/src/views/Home.vue b/js/src/views/Home.vue index 3478c1001..f8689a8e3 100644 --- a/js/src/views/Home.vue +++ b/js/src/views/Home.vue @@ -4,7 +4,9 @@ {{ $t("Gather ⋅ Organize ⋅ Mobilize") }} - {{ $t("Join {instance}, a Mobilizon instance", { instance: config.name }) }} + {{ config.description }}
{{ $t("Join {instance}, a Mobilizon instance", { instance: config.name }) }}
{{ config.description }}