aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Utilities/i18n.js15
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;
}
};