diff options
| author | Andrew Lee <alee14498@protonmail.com> | 2024-02-21 16:51:28 -0500 |
|---|---|---|
| committer | Andrew Lee <alee14498@protonmail.com> | 2024-02-21 16:52:50 -0500 |
| commit | 872e352ea582a77a27c810c3d3461413c5b37dd7 (patch) | |
| tree | dddf1a449a556a58dda22f6266ea10d14272aa16 /Utilities | |
| parent | 680b0ab217f76fc2bbcc5d108ce6ce65bb41fdd5 (diff) | |
| download | DLAP-872e352ea582a77a27c810c3d3461413c5b37dd7.tar.gz DLAP-872e352ea582a77a27c810c3d3461413c5b37dd7.tar.bz2 DLAP-872e352ea582a77a27c810c3d3461413c5b37dd7.zip | |
Added a fallback when there is empty strings
Diffstat (limited to 'Utilities')
| -rw-r--r-- | Utilities/i18n.js | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/Utilities/i18n.js b/Utilities/i18n.js index 9b431a1..e9614ea 100644 --- a/Utilities/i18n.js +++ b/Utilities/i18n.js @@ -22,11 +22,12 @@ import i18next from 'i18next'; import fsBackend from 'i18next-fs-backend'; import { readFileSync } from 'node:fs'; const { locale } = JSON.parse(readFileSync('./config.json', 'utf-8')); +const fallbackLanguage = 'en'; i18next.use(fsBackend).init({ lng: locale, // if you're using a language detector, do not define the lng option debug: false, - fallbackLng: 'en', + fallbackLng: fallbackLanguage, backend: { loadPath: './Locales/{{lng}}/{{ns}}.json' } @@ -34,7 +35,15 @@ i18next.use(fsBackend).init({ export default { i18next, - t(key, option) { - return i18next.t(key, option); + t(key, options) { + let translation = i18next.t(key, options); + if (translation === '') { + // Change language to fallback language, translate the key, then change back to original language + const originalLanguage = i18next.language; + i18next.changeLanguage(fallbackLanguage); + translation = i18next.t(key, options); + i18next.changeLanguage(originalLanguage); + } + return translation; } }; |
