Here's a simple example, but you'd maybe want to use something like i18next as your app gets more complex.
Fiddle: http://jsfiddle.net/jiggle/dZ9Em/
function AppViewModel() {
var self = this;
self.Username = ko.observable("Username");
self.Password = ko.observable("Password");
self.Rememberpassword = ko.observable("Remember Password");
self.Language =ko.observable("english");
self.Language.subscribe(function(lang){
if (lang=="norwegian"){
self.Username("Brukernavn");
self.Password("Passord");
self.Rememberpassword("Husk passord");
};
if (lang=="english"){
self.Username("Username");
self.Password("Password");
self.Rememberpassword("Remember Password");
};
});
self.Languagelist=['english','norwegian'];
return self;
}
var vm = new AppViewModel();
ko.applyBindings(vm);
The code sets your language text as knockout observables, and also the current language, then we subscribe to the language observable, such that when it is updated (the user selects a different language), we check what the new value is (lang) and then set the observables to the correct words.
For more information on subcribing to observables and observables in general have a look a the knockout documentation, that has good examples:
http://knockoutjs.com/documentation/observables.html
I've captured 'this" using var self=this; at the start of the viewmodel to ensure we have a reference to the language text observables when the subcription code is called (it wouldn't work otherwise as 'this' would not be the viewmodel).
For the purposes of the demo, I've created an array of languages (just the two) and we bind this to the select dropdown to allow the language selection; the value is bound to the viewmodel's Language observable, which then triggers the code in the subscribe function to switch the language.
HTML:
<select data-bind="options: Languagelist,value:Language"></select>
<div>
<div data-bind="text:Username"></div>
<div data-bind="text:Password"></div>
<div data-bind="text:Rememberpassword"></div>
</div>
Fiddle: http://jsfiddle.net/jiggle/dZ9Em/