i18next / ng-i18next

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

noConflict mode? - i18next: conflict with Google`s libphonenumber #81

Closed clicman closed 9 years ago

clicman commented 9 years ago

I`ve tried to add it to my project and got:

TypeError: undefined is not a function
    at init (public_html/deps/ng-i18next/dist/ng-i18next.js:35:17)
    at optionsChange (public_html/deps/ng-i18next/dist/ng-i18next.js:72:4)
    at self.$get (public_html/deps/ng-i18next/dist/ng-i18next.js:131:4)
    at Object.invoke (public_html/deps/angular/angular.js:4182:17)
    at http://localhost:8383/site/deps/angular/angular.js:4000:37
    at getService (public_html/deps/angular/angular.js:4141:39)
    at Object.invoke (public_html/deps/angular/angular.js:4173:13)
    at http://localhost:8383/site/deps/angular/angular.js:6482:43
    at forEach (public_html/deps/angular/angular.js:323:20)
    at Object.<anonymous> (public_html/deps/angular/angular.js:6480:13) (23:10:12:875 | error)

My code is:

 .config(function ($routeProvider, $i18nextProvider) {
            $i18nextProvider.options = {
                lng: 'ru',
                useCookie: false,
                useLocalStorage: false,
                fallbackLng: 'en',
                resGetPath: '../../resources/i18n/__lng__/__ns__.json'
            };

Called it like:

  <p ng-i18next="mainTitle"></p>

json

{
    "mainTitle": "Fix Your Ride!"
}

What I`ve missed?

clicman commented 9 years ago

Found the problem. i18 object conflicts with google`s libphonenumber at global js scope. Any ideas how to fix it?

bugwelle commented 9 years ago

I'm sorry for not answering until now... So, window.i18n is used by libphonenumber as well as i18next.

I'll look into it. Maybe you could rename libphonenumber's window.i18n before i18next is initialized. You can't rename i18next's window.i18n because ng-i18next uses it.

Or we have to introduce something similar to https://api.jquery.com/jQuery.noConflict/

Regards,

Andre

clicman commented 9 years ago

As workaround I`ve renamed it in i18next and ng-i18next libraries because it was much easer to perform. So I think it would be great to have possibility to wrap i18n object into some another context.

bugwelle commented 9 years ago

Since i18next version 1.8.1 there is a .noConflict() mode. And since version 0.4.1 of 'ng-i18nextyou can now simply addnoConflict: trueto yourng-i18next` settings and everything should work well.

Please load Google's libphonenumber before i18next.

Regards, Andre

clicman commented 9 years ago

@archer96 great news! Thank you!