I am investigating what is possible with i18next localization library.
Right now I have the following code (full Fiddle is here):
HTML
<div data-i18n="title"></div>
<input placeholder="Hello" value="name">
<div class="holder"></div>
<button class="lang" data-lang="en">Eng</button>
<button class="lang" data-lang="ch">Chi</button>
JS
$(document).ready(function () {
i18n.init({
"lng": 'en',
"resStore": resources,
"fallbackLng" : 'en'
}, function (t) {
$(document).i18n();
});
$('.lang').click(function () {
var lang = $(this).attr('data-lang');
i18n.init({
lng: lang
}, function (t) {
$(document).i18n();
});
});
});
It translates all text
elements, but the problem is that I can not translate custom attributes
. For example text inside the div is translated, but I can not understand how can I translate custom attributes like placeholder
and value
.
Another problem is with my way of translation. Whenever a button Chi
, Eng
is clicked, I am initializing the translation (but I am not sure this is a correct way). Edit I think I found how to solve this problem (I need to use setLng): i18n.setLng(lang, function(t) { ... })
<div id="dropdown" class="user_reg"> <select id="country_list" class="selectpicker" data-width="100%" data-size="5" data-live-search="true" required="required"> <option value="" disabled class="country_list">Country</option> </select> </div>
, then how do we translateCountry
? – Uigur