You could also bind it to your to vm or to knockout itself.
ko.i18n = i18n
If you want to use it in the html, you can also create a binding handler like so:
ko.bindingHandlers.textT = {
update: function(element, valueAccessor, allBindings, viewModel, bindingContext) {
var l = bindingContext.$root.language()
var valueUnwrapped = ko.unwrap(valueAccessor())
var translatedValue = i18n.t(valueUnwrapped)
if (translatedValue == valueUnwrapped && translatedValue.indexOf(':') > 0 && translatedValue.indexOf(':') < translatedValue.length) translatedValue = translatedValue.split(':')[1]
var tValueAccessor = function() {
return translatedValue
}
ko.bindingHandlers.text.update(element, tValueAccessor, allBindings, viewModel, bindingContext)
}
}
in this we called our vm $root.
we also have a language observable attached to our main VM. If the language change all of the i18n bindings rerun thru dependency tracking.
The if with the colon is for cases where we pass a string including another translation page, you don't need it if you only use one.