I am using Backbone.js in my application and the i18next plugin for my language switch function on my application. When I pass a value to the lng
option in the init
function call, then it translates my page correctly.
Now I want to do this dynamically via a language selector. I have a <select>
of four languages and I want to pass the value of the selected language to the lng
option of the init function.
Here is my code:
HTML
<div class="col-xs-6>
<select class="form-control language-selector">
<option value="de">Deutsch</option>
<option value="en">English</option>
<option value="fr">Français</option>
<option value="it">Italiano</option>
</select>
</div>
JavaScript
i18next.init({
debug: true,
languages: ['de','en','fr','it'],
lng: 'de',
fallbackLng: false,
load: 'current',
resources: resBundle
}, function(err, t){
});
'change .language-selector': function(e){
e.preventDefault();
i18next.setLng($(e.target).val(), (err, t) => {
console.log(arguments);
this.render();
});
}