dhoko / angular-ngBabelfish

Internationalization module for angular.js, it's magic !
MIT License
11 stars 3 forks source link

Cannot read property '_common' of undefined #44

Closed SaidTayebi closed 9 years ago

SaidTayebi commented 9 years ago

In lazy mode I have this error when I switch the language. It doesn't break my app though. I have a file for each language: fr-FR.json, nl-NL.json, en-EN.json

TypeError: Cannot read property '_common' of undefined at Object.setTranslation as updateState at bundle.js:583 at Scope.$get.Scope.$broadcast (angular.js:14720) at x.transitionTo.x.transition.I.then.x.transition.x.transition (angular-ui-router.min.js:7) at processQueue (angular.js:13189) at angular.js:13205 at Scope.$get.Scope.$eval (angular.js:14401) at Scope.$get.Scope.$digest (angular.js:14217) at Scope.$get.Scope.$apply (angular.js:14506) at dependencyResolverFor.js:13

dhoko commented 9 years ago

What is your version of Angular ? How do you try to change the lang ?

I tried to remove _common from my demo for lazyMode, but there are no errors :/

SaidTayebi commented 9 years ago

1.3. The thing is, I have a "_common" in each file but stil got the error.

dhoko commented 9 years ago

Do you have a gist with how you try to change the lang, also a small exemple to have this error.

SaidTayebi commented 9 years ago

I change the lang with data-i18n-load

each lang in languages
   - var country = (lang == 'fr') ? 'France' : (lang == 'nl') ? 'Netherlands' : (lang == 'en') ? 'United-Kingdom' : 'Belgium'
   - var langCountry = (lang == 'fr') ? 'FR' : (lang == 'nl') ? 'NL' : (lang == 'en') ? 'EN' : 'EN'
      li(class=(currentLanguage == lang) ? 'active' : '')
        a(href="", id="site-#{lang}" data-i18n-load="#{lang}-#{langCountry}")
            img(src="#{MEDIA_URL}images/global/flags/#{country}.png").flag-icon

And my config is:

babelfishProvider.init({
    namespace: 'i18n',
    state: 'dashboard',
    lang: $cookies["sy-locales"] + "-" + $cookies["sy-locales"].toUpperCase(), 
});

babelfishProvider
   .lang({
              lang: "fr-FR",
              url: "/i18n/fr-FR.json"
          })
          .lang({
              lang: "en-EN",
              url: "/i18n/en-EN.json"
          })
          .lang({
              lang: "nl-NL",
              url: "/i18n/nl-NL.json"
          });
dhoko commented 9 years ago

Ok I've seen it once. It's a bug coming from this commit https://github.com/dhoko/angular-ngBabelfish/commit/0f486aae084fb555acc0134e4d04d23fd2f8cd77 (else if (config.lazy))

I don't know why we do not have this error everytime, and it should not be able to enter the condition. A patch is coming.

dhoko commented 9 years ago

It should be ok now. v1.7.2 is available with the patch.

SaidTayebi commented 9 years ago

Works fine ! Thanks. BTW: Great work, very helpful library