diff --git a/account-gui/package.json b/account-gui/package.json index 951d5b46..176facf1 100644 --- a/account-gui/package.json +++ b/account-gui/package.json @@ -42,7 +42,7 @@ "@github/webauthn-json": "^2.1.1", "@picnicsupermarket/localicious": "^1.0.1", "dompurify": "^3.2.2", - "i18n-js": "^3.3.0", + "i18n-js": "^4.5.1", "js-cookie": "^3.0.5", "postcss": "^8.4.49", "sass": "^1.82.0", diff --git a/account-gui/src/__tests__/locale/en.test.js b/account-gui/src/__tests__/locale/en.test.js index d0e7cf53..1803e5c9 100644 --- a/account-gui/src/__tests__/locale/en.test.js +++ b/account-gui/src/__tests__/locale/en.test.js @@ -1,6 +1,6 @@ -import I18n from "i18n-js"; -import en from "../../locale/en"; -import nl from "../../locale/nl"; +// import I18n from "i18n-js"; +// import en from "../../locale/en"; +// import nl from "../../locale/nl"; expect.extend({ toContainKey(translation, key) { diff --git a/account-gui/src/locale/I18n.js b/account-gui/src/locale/I18n.js index 24011f62..2f078ca7 100644 --- a/account-gui/src/locale/I18n.js +++ b/account-gui/src/locale/I18n.js @@ -1,6 +1,7 @@ import en from "./js/en/strings.json"; import nl from "./js/nl/strings.json"; import {reportError} from "../api"; +import I18nLocal from "./I18nRemote"; const translations = { en: en, @@ -32,6 +33,10 @@ const I18n = { if (fallback) { return fallback; } + const oldTranslation = I18nLocal.t(key, model); + if (oldTranslation) { + return oldTranslation; + } reportError({"Missing translation": `${key} in ${locale} translation`}); return `[missing "${key}" translation]`; } diff --git a/account-gui/src/locale/I18nRemote.js b/account-gui/src/locale/I18nRemote.js new file mode 100644 index 00000000..71be37a6 --- /dev/null +++ b/account-gui/src/locale/I18nRemote.js @@ -0,0 +1,16 @@ +import {I18n as I18nRemote} from "i18n-js"; + +import en from "./en"; +import nl from "./nl"; + +const I18nLocal = new I18nRemote({ + en: en, + nl: nl, +}); + +I18nLocal.missingTranslation.register("report-error", (i18n, scope) => { + return null; +}); +I18nLocal.missingBehavior = "report-error"; + +export default I18nLocal; diff --git a/account-gui/src/locale/en.js b/account-gui/src/locale/en.js index 52a2a962..edc42cc0 100644 --- a/account-gui/src/locale/en.js +++ b/account-gui/src/locale/en.js @@ -1,4 +1,4 @@ -export const enTranslations = { +const en = { login: { requestEduId: "No eduID?", requestEduId2: "Create one!", @@ -437,3 +437,4 @@ export const enTranslations = { next: "Open website to enter your name" } }; +export default en; diff --git a/account-gui/src/locale/js/en/strings.json b/account-gui/src/locale/js/en/strings.json index 02cfee73..cc68e5e6 100644 --- a/account-gui/src/locale/js/en/strings.json +++ b/account-gui/src/locale/js/en/strings.json @@ -580,7 +580,7 @@ "MagicLink.OpenMailTitle.COPY": "Open your e-mail", "MagicLink.OpenMailDisclaimer.COPY": "Can't find the email? Check the spam folder", "MagicLink.Header.COPY": "Check your email", - "MagicLink.Info.COPY": "Press the link we sent to %1$s.", + "MagicLink.Info.COPY": "Press the link we sent to ", "MagicLink.Awaiting.COPY": "Waiting for you to press the link…", "MagicLink.OpenGMail.COPY": "Open gmail.com", "MagicLink.OpenOutlook.COPY": "Open outlook.com", diff --git a/account-gui/src/locale/js/nl/strings.json b/account-gui/src/locale/js/nl/strings.json index 63f1968b..fa9cebb0 100644 --- a/account-gui/src/locale/js/nl/strings.json +++ b/account-gui/src/locale/js/nl/strings.json @@ -580,7 +580,7 @@ "MagicLink.OpenMailTitle.COPY": "Open je e-mail", "MagicLink.OpenMailDisclaimer.COPY": "Kun je de mail niet vinden? Kijk ook in de spam folder", "MagicLink.Header.COPY": "Controleer je e-mail", - "MagicLink.Info.COPY": "Druk op de link die we verstuurd hebben naar %1$s.", + "MagicLink.Info.COPY": "Druk op de link die we verstuurd hebben naar ", "MagicLink.Awaiting.COPY": "Wachten tot je op de link drukt…", "MagicLink.OpenGMail.COPY": "Open gmail.com", "MagicLink.OpenOutlook.COPY": "Open outlook.com", diff --git a/account-gui/src/locale/nl.js b/account-gui/src/locale/nl.js index 81121f18..0a051b0e 100644 --- a/account-gui/src/locale/nl.js +++ b/account-gui/src/locale/nl.js @@ -1,6 +1,4 @@ -import I18n from "i18n-js"; - -I18n.translations.nl = { +const nl = { login: { requestEduId: "Geen eduID?", requestEduId2: "Maak het aan!", @@ -438,3 +436,4 @@ I18n.translations.nl = { next: "Naar gegevens invullen" } }; +export default nl; \ No newline at end of file diff --git a/account-gui/src/locale/parser.js b/account-gui/src/locale/parser.js index d77c9930..e0024fff 100644 --- a/account-gui/src/locale/parser.js +++ b/account-gui/src/locale/parser.js @@ -1,4 +1,4 @@ -import {enTranslations} from "./en.js"; +import en from "./en"; const parse = (dict, key, index, results = {}, stack = []) => { const value = dict[key]; @@ -16,8 +16,8 @@ const parse = (dict, key, index, results = {}, stack = []) => { } } const results = {}; -Object.keys(enTranslations).forEach((key, index) => { - parse(enTranslations, key, index, results); +Object.keys(en).forEach((key, index) => { + parse(en, key, index, results); }); console.log(results); diff --git a/account-gui/src/verify/ServiceDesk.svelte b/account-gui/src/verify/ServiceDesk.svelte index 92fbf352..2c579875 100644 --- a/account-gui/src/verify/ServiceDesk.svelte +++ b/account-gui/src/verify/ServiceDesk.svelte @@ -1,5 +1,5 @@