javascript - current language angularjs and i18next - Stack Overflow

I'm using this:I'm only able to get the language in options (if set):console.log("langua

I'm using this:

I'm only able to get the language in options (if set):

console.log("language: " + $i18next.options.lng);

How do you get the current language? documentation says: i18n.lng() returns current lng.

but within the context of angular $i18next.lng() doesn't exist.

I also tried:

console.log("language: " + $i18next.lang);
console.log("language: " + $i18next.language );
console.log("language: " + $i18next.lng);

I'm using this: https://github./archer96/ng-i18next

I'm only able to get the language in options (if set):

console.log("language: " + $i18next.options.lng);

How do you get the current language? documentation says: i18n.lng() returns current lng.

but within the context of angular $i18next.lng() doesn't exist.

I also tried:

console.log("language: " + $i18next.lang);
console.log("language: " + $i18next.language );
console.log("language: " + $i18next.lng);
Share Improve this question edited Jul 2, 2014 at 15:48 AndreM96 1,3751 gold badge23 silver badges35 bronze badges asked Oct 1, 2013 at 6:03 virtual82virtual82 8851 gold badge10 silver badges20 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

I'm the developer of ng-i18next.

ng-i18next uses angular's $watch function to look for any changes on $i18next.options.

This means you should change the language by setting $i18next.options.lng to any language you want.

Because of this, $i18next.options.lng always contains the current language. There is no need for $i18next.lng().

Of course this will work, too: window.i18n.lng()

This is how i18next provider does it: window.i18n.lng();

Check the code here.

[Edit] I know it's an old question but I was also looking for an answer and I thought it's a good idea to share my findings.

This is working for me:

    var language;
    /* init i18next */ 
    i18n.init(options, function(t) {
        $("body").i18n();
    /* set global language var for usage in other functions */
        var language = i18n.detectLanguage();
    });

To set the language add the parameter to your URL (?setLng=de), while de is your language key in the example.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745510294a4630741.html

相关推荐

  • javascript - current language angularjs and i18next - Stack Overflow

    I'm using this:I'm only able to get the language in options (if set):console.log("langua

    5小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信