I am currently utilizing I18Next as a JavaScript-based Translation Solution, and here is the specific functionality that I require:
- By default, a namespace called "Core" is loaded. While it contains most of the keys I need for translation, there are some keys missing.
- There isn't a fixed list of namespaces available, so I cannot simply specify the namespaces I want to load using
i18n.init
. - When the page loads, certain "Modules" may be added to the Application and these modules also need to undergo translation. These modules should indicate their i18n namespace name somewhere, then i18n should make the keys within that namespace accessible.
Essentially, I am seeking a way for i18next to automatically load namespaces when they are called. It can be assured that any namespaces accessed through t("[SomeNamespace]Key.Key2");
are valid and do exist. The challenge lies in the fact that i18next does not have an automatic "autoload" feature and I haven't discovered a method to manually load a resource file after i18n.init has been executed.
Below is the current code snippet I am working with:
$.i18n.init(
{
lng: "en",
fallbackLng: "en",
useCookie: false,
resGetPath: "System/i18n/__ns__/__lng__.json",
ns: "Core"
},
function(t) {
System.I18N = t;
alert(System.I18N("LoginUI:Messages.Name"));
}
);
Upon execution, it only displays LoginUI:Messages.Name
instead of the desired translation found in System/i18n/LoginUI/en.json
:
{
"Messages": {
"Name": "Logon Interface"
}
}
(In this scenario, Core/en.json is irrelevant. At present, my primary focus is on autoloading "LoginUI/en.json," or alternatively, being able to manually trigger its loading process.)