Reputation: 885
I'm using this: https://github.com/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);
Upvotes: 1
Views: 3901
Reputation: 359
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.
Upvotes: 0
Reputation: 1375
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()
Upvotes: 3
Reputation: 636
This is how i18next provider does it: window.i18n.lng();
[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.
Upvotes: 3