How can I use translations in i18next in javascript

 ̄綄美尐妖づ 提交于 2019-12-20 05:11:06

问题


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) ?


回答1:


It should be alert(t(someKey)) (see http://i18next.com/ at end of page).




回答2:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!