I recently started working with knockout and I am still learning. I have a below drop down code in which if I select English
, it translates whole page into English and if I select French
it translates whole page into French and everything works fine without any issues. I am assuming it has to do something with this return i18n(item.label)
.
<div class="header dropdown">
<select data-bind=" value: locale.selected_locale,
options: [{ value: 'en-CA', label: 'english'}, { value: 'fr-CA',label: 'french'}],
optionsText: function (item) {return i18n(item.label);},
optionsValue: 'value' " class="auto">
</select>
</div>
Now I am changing the drop down layout to a button thing but still same translation thing should work. Here is my jsfiddle.
Now If I click on Setting
button, it gives either English
or French
green tab so if I click on English
it should do exactly same thing what is happening with if I select English
in the above drop down box and translates whole page into English and same thing French
as well? How can I fit above drop down code which does all the magic of translation in this button thing in my jsfiddle. I can do testing on my site to check it out whether it is working or not.
Idea is to do same thing what is being achieved in the above code (through dropdown) but with different layout. Clicking on english will translate everything to english, clicking on french will translate everything to french(as the above drop down code is already doing that).
Update:
<div class="header dropdown">
<button type="button" data-bind="text: i18n('french '), click: function(){locale.selected_locale('fr-CA')}"></button>
</div>