Closed vituchon closed 2 years ago
Sounds like a "problem" of ng-i18next you might ask @anwalkers in the ng-i18next repo... In general the language change seems to work, like in this example (but probably with a different angular lib): https://locize.com/blog/unleash-the-full-power-of-angular-i18next/
Hi @adrai how are you?
Thanks for your reply. Yeah, I'm afraid that in my ongoing project I wasn't having any problem until i added http-backend support. That is the reason that the ticket is here.
So.. i know this issue has at least 3 main characters: i18next (as the main character), ng-i18next and i18next-http-backend... It is indeed a complex system and the boundaries between these characters aren't clear at all as they are part of an integral solution. It sounds that you have already summon Anwalkers, so let's hope he has something to say about it.
I made some debug following the debbuger into the sources and indeed it could be a problem of ng-i18next as I saw that the translations files are correctly loaded (http-backend responsability), but inside the angular service (ng-i18next responsability) the this.translations["auto"]
remains with the same values once setup I mean, it doesn't change when you change the language. But things are, quite complex to really understand what is actually happening... i need, more knowledge and more debugging time.
Well you know guys, i fix this problem by adding a very specific line on the sources of ng-i18next, so now i can actually put all the focus on that proyect, leaving this proyect in peace... just for informing i do this
on ng-i18next/src/translateService.ts if you go to method changeLanguage and the MAGIC LINE (see comment below), this problem is solved
I18nTranslateService.prototype.changeLanguage = function (lng) {
var _this = this;
if (this.options.lng !== lng && this.i18n.language !== lng) {
this.options.lng = lng;
this.translations = {}; // THIS IS THE MAGIC LINE
this.i18n.changeLanguage(lng, function (err, t) {
_this.$rootScope.$broadcast('i18nextLanguageChange', _this.i18n.language);
});
}
};
Perhaps you could notify the buddies at the silbing proyect ng-i18next for this, i have already started a ticket on their proyect that references this ticket.
Cheers
Víctor
ok, so this issue here can be closed, right?
Sure adrai, but leave the content as it can be valuable for the your silbing proyect ng-i18next
Greetings
Vituchon
🐛 Bug Report :lady_beetle:
To Reproduce
Just run the examples below
index.html
script.js
Observed behavior
Expected behavior
Your Environment