i18next / ng-i18next

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

Add documentation on dynamic locale change #41

Closed ValMilkevich closed 10 years ago

ValMilkevich commented 10 years ago

Hi, first of this is awesome project! thank you so much!

I'm currently trying to implement the dynamic language change, please may you let me know if that is possible at all?

My main.js.coffee looks like the following:

locale = "en"

angular.module("jm.i18next").config [
  "$i18nextProvider"
  ($i18nextProvider) ->
    $i18nextProvider.options =
      interpolationPrefix: '%{'
      interpolationSuffix: '}'      
      lng: locale
      # useCookie: false
      # useLocalStorage: false
      # fallbackLng: "en"
      resGetPath: '/locales/%{lng}.json'
      # useLocalStorage: true      
      # localStorageExpirationTime: 60
]

@app = angular.module('homekit', ['templates', 'ngRoute', 'ngResource', "jm.i18next"])

the question is - if it is possible to change the locale of the application from within the angular controller ?

bugwelle commented 10 years ago

Hello and thanks for asking this question (no joking; question like this make this project better) :)

I never use CoffeeScript but the JavaScript code of your examples looks like this (using http://js2coffee.org/ ):

var locale;

locale = "en";

angular.module("jm.i18next").config([
  "$i18nextProvider", function($i18nextProvider) {
    return $i18nextProvider.options = {
      interpolationPrefix: '%{',
      interpolationSuffix: '}',
      lng: locale,
      resGetPath: '/locales/%{lng}.json'
    };
  }
]);

this.app = angular.module('homekit', ['templates', 'ngRoute', 'ngResource', "jm.i18next"]);

So you want to change the language? It's possible and not hard to implement. Just have a look on this: https://github.com/archer96/ng-i18next/blob/master/examples/directive/directive.js#L62 (line 62). You simply change $i18next.options.lng to whatever language you want ;) ng-i18next watches for changes on $i18next.options.

For examples see https://github.com/archer96/ng-i18next#examples .

Regards, Andre

ValMilkevich commented 10 years ago

Andre, thanks for such a quick reply! https://github.com/archer96/ng-i18next/blob/master/examples/directive/directive.js#L62 - helps a lot!

bugwelle commented 10 years ago

:)

I think this issue can now be closed.