Skip to content

Commit

Permalink
Fallback with old translations
Browse files Browse the repository at this point in the history
  • Loading branch information
oharsta committed Jan 27, 2025
1 parent d500f75 commit e30cd8b
Show file tree
Hide file tree
Showing 21 changed files with 112 additions and 35 deletions.
2 changes: 1 addition & 1 deletion account-gui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions account-gui/src/__tests__/locale/en.test.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions account-gui/src/locale/I18n.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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]`;
}
Expand Down
16 changes: 16 additions & 0 deletions account-gui/src/locale/I18nRemote.js
Original file line number Diff line number Diff line change
@@ -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;
3 changes: 2 additions & 1 deletion account-gui/src/locale/en.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const enTranslations = {
const en = {
login: {
requestEduId: "No eduID?",
requestEduId2: "Create one!",
Expand Down Expand Up @@ -437,3 +437,4 @@ export const enTranslations = {
next: "Open website to enter your name"
}
};
export default en;
2 changes: 1 addition & 1 deletion account-gui/src/locale/js/en/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion account-gui/src/locale/js/nl/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 2 additions & 3 deletions account-gui/src/locale/nl.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import I18n from "i18n-js";

I18n.translations.nl = {
const nl = {
login: {
requestEduId: "Geen eduID?",
requestEduId2: "Maak het aan!",
Expand Down Expand Up @@ -438,3 +436,4 @@ I18n.translations.nl = {
next: "Naar gegevens invullen"
}
};
export default nl;
6 changes: 3 additions & 3 deletions account-gui/src/locale/parser.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {enTranslations} from "./en.js";
import en from "./en";

const parse = (dict, key, index, results = {}, stack = []) => {
const value = dict[key];
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion account-gui/src/verify/ServiceDesk.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
import I18n from "i18n-js";
import I18n from "../locale/I18n";
import Button from "../components/Button.svelte";
import arrowLeftIcon from "../icons/verify/arrow-left.svg?raw";
import alertSvg from "../icons/alert-circle.svg?raw";
Expand Down
27 changes: 23 additions & 4 deletions account-gui/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1890,6 +1890,11 @@ big.js@^5.2.2:
resolved "https://registry.yarnpkg.com/big.js/-/big.js-5.2.2.tgz#65f0af382f578bcdc742bd9c281e9cb2d7768328"
integrity sha512-vyL2OymJxmarO8gxMr0mhChsO9QGwhynfuu4+MHTAW6czfq9humCB7rKpUjDd9YUiDPU4mzpyupFSvOClAwbmQ==

bignumber.js@*:
version "9.1.2"
resolved "https://registry.yarnpkg.com/bignumber.js/-/bignumber.js-9.1.2.tgz#b7c4242259c008903b13707983b5f4bbd31eda0c"
integrity sha512-2/mKyZH9K85bzOEfhXDBFZTGd1CTs+5IHpeFQo9luiBG7hghdC851Pj2WAhb6E3R6b9tZj/XKhbg4fum+Kepug==

boolbase@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/boolbase/-/boolbase-1.0.0.tgz#68dff5fbe60c51eb37725ea9e3ed310dcc1e776e"
Expand Down Expand Up @@ -2635,10 +2640,14 @@ human-signals@^2.1.0:
resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-2.1.0.tgz#dc91fcba42e4d06e4abaed33b3e7a3c02f514ea0"
integrity sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==

i18n-js@^3.3.0:
version "3.9.2"
resolved "https://registry.yarnpkg.com/i18n-js/-/i18n-js-3.9.2.tgz#4a015dcfabd4c9fc73115fc2d02d2627e4c15ca5"
integrity sha512-+Gm8h5HL0emzKhRx2avMKX+nKiVPXeaOZm7Euf2/pbbFcLQoJ3zZYiUykAzoRasijCoWos2Kl1tslmScTgAQKw==
i18n-js@^4.5.1:
version "4.5.1"
resolved "https://registry.yarnpkg.com/i18n-js/-/i18n-js-4.5.1.tgz#12ea3d6333552ff75be0904ea50705f5a263d172"
integrity sha512-n7jojFj1WC0tztgr0I8jqTXuIlY1xNzXnC3mjKX/YjJhimdM+jXM8vOmn9d3xQFNC6qDHJ4ovhdrGXrRXLIGkA==
dependencies:
bignumber.js "*"
lodash "*"
make-plural "*"

icss-utils@^5.0.0, icss-utils@^5.1.0:
version "5.1.0"
Expand Down Expand Up @@ -3279,6 +3288,11 @@ lodash.debounce@^4.0.8:
resolved "https://registry.yarnpkg.com/lodash.debounce/-/lodash.debounce-4.0.8.tgz#82d79bff30a67c4005ffd5e2515300ad9ca4d7af"
integrity sha512-FT1yDzDYEoYWhnSGnpE/4Kj1fLZkDFyqRb7fNt6FdYOSxlUWAtp42Eh6Wb0rGIv/m9Bgo7x4GhQbm5Ys4SG5ow==

lodash@*:
version "4.17.21"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==

lru-cache@^5.1.1:
version "5.1.1"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-5.1.1.tgz#1da27e6710271947695daf6848e847f01d84b920"
Expand All @@ -3300,6 +3314,11 @@ make-dir@^4.0.0:
dependencies:
semver "^7.5.3"

make-plural@*:
version "7.4.0"
resolved "https://registry.yarnpkg.com/make-plural/-/make-plural-7.4.0.tgz#fa6990dd550dea4de6b20163f74e5ed83d8a8d6d"
integrity sha512-4/gC9KVNTV6pvYg2gFeQYTW3mWaoJt7WZE5vrp1KnQDgW92JtYZnzmZT81oj/dUTqAIu0ufI2x3dkgu3bB1tYg==

[email protected]:
version "1.0.12"
resolved "https://registry.yarnpkg.com/makeerror/-/makeerror-1.0.12.tgz#3e5dd2079a82e812e983cc6610c4a2cb0eaa801a"
Expand Down
2 changes: 1 addition & 1 deletion myconext-gui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,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",
Expand Down
2 changes: 1 addition & 1 deletion myconext-gui/src/__tests__/init.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import I18n from "i18n-js";
import I18n from "../locale/I18n";
import en from "../locale/en";
import nl from "../locale/nl";

Expand Down
2 changes: 1 addition & 1 deletion myconext-gui/src/components/InstitutionRole.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
{/if}
</span>
<div class="role">
<p>{affiliations || I18n.t("Profile.Student.COPYRole")}
<p>{affiliations || I18n.t("Profile.Student.COPY")}
{#if linkedAccount.expired}
<span class="expired">{` (${I18n.t("profile.expired")})`}</span>
{/if}
Expand Down
2 changes: 1 addition & 1 deletion myconext-gui/src/components/LinkedAccountSummary.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
icon={preferredAccount ? personalInfo : null}
overrideShieldIcon={studentIcon}
readOnly={true}
value={I18n.t("Profile.Student.COPYRole")}/>
value={I18n.t("Profile.Student.COPY")}/>
{/if}

{#if (linkedAccount.idpScoping === "idin" || isEmpty(linkedAccountGivenName(linkedAccount))) &&
Expand Down
10 changes: 9 additions & 1 deletion myconext-gui/src/locale/I18n.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
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,
Expand All @@ -24,14 +26,20 @@ const format = (msg, ...args) => {
let locale = "en"

const I18n = {
changeLocale: lang => locale = lang,
changeLocale: lang => {
locale = lang;
},
currentLocale: () => locale,
t: (key, model = {}, fallback = null) => {
const msg = translations[locale][key]
if (!msg) {
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]`;
}
Expand Down
16 changes: 16 additions & 0 deletions myconext-gui/src/locale/I18nRemote.js
Original file line number Diff line number Diff line change
@@ -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;
6 changes: 3 additions & 3 deletions myconext-gui/src/locale/en.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import I18n from "i18n-js";

I18n.translations.en = {
const en = {
sidebar: {
home: "Home",
personalInfo: "Personal info",
Expand Down Expand Up @@ -621,3 +619,5 @@ I18n.translations.en = {
}
}
};

export default en;
5 changes: 2 additions & 3 deletions myconext-gui/src/locale/nl.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import I18n from "i18n-js";

I18n.translations.nl = {
const nl = {
sidebar: {
home: "Home",
personalInfo: "Persoonlijke info",
Expand Down Expand Up @@ -621,3 +619,4 @@ I18n.translations.nl = {
},
}
};
export default nl;
2 changes: 1 addition & 1 deletion myconext-gui/src/verify/ServiceDesk.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
import I18n from "i18n-js";
import I18n from "../locale/I18n";
import {flash, user} from "../stores/user";
import Button from "../components/Button.svelte";
import arrowLeftIcon from "../icons/verify/arrow-left.svg?raw";
Expand Down
24 changes: 19 additions & 5 deletions myconext-gui/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1994,6 +1994,11 @@ big.js@^5.2.2:
resolved "https://registry.yarnpkg.com/big.js/-/big.js-5.2.2.tgz#65f0af382f578bcdc742bd9c281e9cb2d7768328"
integrity sha512-vyL2OymJxmarO8gxMr0mhChsO9QGwhynfuu4+MHTAW6czfq9humCB7rKpUjDd9YUiDPU4mzpyupFSvOClAwbmQ==

bignumber.js@*:
version "9.1.2"
resolved "https://registry.yarnpkg.com/bignumber.js/-/bignumber.js-9.1.2.tgz#b7c4242259c008903b13707983b5f4bbd31eda0c"
integrity sha512-2/mKyZH9K85bzOEfhXDBFZTGd1CTs+5IHpeFQo9luiBG7hghdC851Pj2WAhb6E3R6b9tZj/XKhbg4fum+Kepug==

boolbase@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/boolbase/-/boolbase-1.0.0.tgz#68dff5fbe60c51eb37725ea9e3ed310dcc1e776e"
Expand Down Expand Up @@ -2834,10 +2839,14 @@ human-signals@^2.1.0:
resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-2.1.0.tgz#dc91fcba42e4d06e4abaed33b3e7a3c02f514ea0"
integrity sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==

i18n-js@^3.3.0:
version "3.9.2"
resolved "https://registry.yarnpkg.com/i18n-js/-/i18n-js-3.9.2.tgz#4a015dcfabd4c9fc73115fc2d02d2627e4c15ca5"
integrity sha512-+Gm8h5HL0emzKhRx2avMKX+nKiVPXeaOZm7Euf2/pbbFcLQoJ3zZYiUykAzoRasijCoWos2Kl1tslmScTgAQKw==
i18n-js@^4.5.1:
version "4.5.1"
resolved "https://registry.yarnpkg.com/i18n-js/-/i18n-js-4.5.1.tgz#12ea3d6333552ff75be0904ea50705f5a263d172"
integrity sha512-n7jojFj1WC0tztgr0I8jqTXuIlY1xNzXnC3mjKX/YjJhimdM+jXM8vOmn9d3xQFNC6qDHJ4ovhdrGXrRXLIGkA==
dependencies:
bignumber.js "*"
lodash "*"
make-plural "*"

[email protected]:
version "0.4.24"
Expand Down Expand Up @@ -3610,7 +3619,7 @@ lodash.debounce@^4.0.8:
resolved "https://registry.yarnpkg.com/lodash.debounce/-/lodash.debounce-4.0.8.tgz#82d79bff30a67c4005ffd5e2515300ad9ca4d7af"
integrity sha512-FT1yDzDYEoYWhnSGnpE/4Kj1fLZkDFyqRb7fNt6FdYOSxlUWAtp42Eh6Wb0rGIv/m9Bgo7x4GhQbm5Ys4SG5ow==

lodash@^4.7.0:
lodash@*, lodash@^4.7.0:
version "4.17.21"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
Expand All @@ -3636,6 +3645,11 @@ make-dir@^4.0.0:
dependencies:
semver "^7.5.3"

make-plural@*:
version "7.4.0"
resolved "https://registry.yarnpkg.com/make-plural/-/make-plural-7.4.0.tgz#fa6990dd550dea4de6b20163f74e5ed83d8a8d6d"
integrity sha512-4/gC9KVNTV6pvYg2gFeQYTW3mWaoJt7WZE5vrp1KnQDgW92JtYZnzmZT81oj/dUTqAIu0ufI2x3dkgu3bB1tYg==

[email protected]:
version "1.0.12"
resolved "https://registry.yarnpkg.com/makeerror/-/makeerror-1.0.12.tgz#3e5dd2079a82e812e983cc6610c4a2cb0eaa801a"
Expand Down

0 comments on commit e30cd8b

Please sign in to comment.