I know that I can use i18next to translate languages in html. For example:
<div data-i18n="someKey"></div>
But is there a way to somehow use it in JS. For example if I want to do something like
alert(someKey)
?
It should be alert(t(someKey))
(see http://i18next.com/ at end of page).
Having read the homepage of the project...
i18n.init(function(t) { // translate nav $(".nav").i18n(); // programatical access var appName = t("app.name"); });
That last part is what you're looking for. It's important to note that that t
is passed to the init
callback as a parameter - you can't just blindly call t()
anywhere ;)
来源:https://stackoverflow.com/questions/24077938/how-can-i-use-translations-in-i18next-in-javascript