Set Language On InIt
This example demonstrate how to set language on init. The lookup order for keys is always: 1 - en-US language + region, 2 - en language only, 3. - fallback thats defined in options.fallbackLng (string or array of fallback language). Basically, lng option sets a specified language that is loaded on every initialization.
Example Markup
<div aria-labelledby="dropdown-flag" class="dropdown-menu dropdown-menu-right">
<a href="#" class="dropdown-item">
<i class="flag-icon flag-icon-gb"></i> English
</a>
<a href="#" class="dropdown-item">
<i class="flag-icon flag-icon-es"></i> Spanish
</a>
<a href="#" class="dropdown-item">
<i class="flag-icon flag-icon-pt"></i> Portuguese
</a>
<a href="#" class="dropdown-item">
<i class="flag-icon flag-icon-fr"></i> French
</a>
</div>
Js Code For Switching
i18next
.use(window.i18nextXHRBackend)
.init({
debug: true,
lng: 'en',
fallbackLng: false,
backend: {
loadPath: "../../../app-assets/data/locales/{{lng}}/{{ns}}.json",
},
returnObjects: true
},
function (err, t) {
// Initialize Localization
jqueryI18next.init(i18next, $);
});