Set Language After InIt
This example demonstrates how to change language after initialization. i18next library detects the language on init, this language can be changed to any available language after initialization by calling initialized event i18next.on('initialized', function(options) {})
.
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 Direct Switching
i18next
.use(window.i18nextXHRBackend)
.init({
debug: true,
fallbackLng: false,
backend: {
loadPath: "../../../app-assets/data/locales/{{lng}}/{{ns}}.json",
},
returnObjects: true
},
function (err, t) {
// Initialize Localization
jqueryI18next.init(i18next, $);
});
// After InIt Event
i18next.on('initialized', function(options) {
// Change language
i18next.changeLanguage('en', function (err, t){
$('.main-menu').localize();
});
});