i18next / ng-i18next

translation for AngularJS using i18next
https://github.com/i18next/ng-i18next
MIT License
161 stars 54 forks source link

languages not available on time #131

Closed aubrey-fowler closed 6 years ago

aubrey-fowler commented 7 years ago

I am using Visual Studio 2017 to deploy my app to my android device. I am making an angular, ionic, cordova hybrid app. The languages are loaded after the user logs in because it's on a per-user basis.

I load the languages into i18next in my controller before routing to the home page but the translations are not available on the home page.

Here's the part from my login controller:

                    languageService.setDefault(data).then(function (response) {
                        console.log("Success!", response);
                        $state.go('main.home'); //route to home page
                    }, function (error) {
                        console.error("Failed!", error);
                    });

Here's the part from my language service:

                languageService.setDefault = function (langObj) {

                  // Return a new promise.
                    return new Promise(function (resolve, reject) {
                        try {
                    console.log('> > > > > languageService.save::: ', langObj);

                    for (var i = 0; i < langObj.languages.length; i++) {
                        $i18next.i18n.addResourceBundle(langObj.languages[i], 'translations', langObj[langObj.languages[i]], false, true);
                    }

                    if ($i18next.i18n.language !== langObj.actual) {
                        $i18next.i18n.changeLanguage(lng);
                    }

                    console.log('- - - - - made it this far: ', $i18next.i18n.options.resources); 
//prints out the resources perfectly

                            resolve(1);
                        }
                        catch (err) {
                            reject(err);
                        }
                    });

I have the languages loaded so I'm not sure why it is not available on my home page in time.

anwalkers commented 7 years ago

Any way to create a sample project?

anwalkers commented 6 years ago

Closing the issue.