0

Before today in my app i had:

app.config(['$translateProvider', function ($translateProvider) {
  $translateProvider.translations('en', {});

  $translateProvider.translations('ru', {});

  $translateProvider.preferredLanguage('en');

  $translateProvider.useLocalStorage();
}]);

but now i have:

app.config(['$translateProvider', function ($translateProvider) {
  $translateProvider.translations('English', {});

  $translateProvider.translations('Russian', {});

  $translateProvider.preferredLanguage('English');

  $translateProvider.useLocalStorage();
}]);

so my language key is changed.

but!

when i open window tab with old localStorage (en) value - my new string are not translated, only in private browser mode, when cache is clean.

so i need somehow to check: if key is en, that replace it with English.

main trouble is that this service do not use $localStorage, but it's own solution for local storage.

how to solve it?

i have only such idea:

  if ($translate.storage().get() === 'en'){
    $translate.storage().set('NG_TRANSLATE_LANG_KEY', 'English');
  }
  if ($translate.storage().get() === 'ru'){
    $translate.storage().set('NG_TRANSLATE_LANG_KEY', 'Russian');
  }
brabertaser19
  • 5,678
  • 16
  • 78
  • 184
  • you need to change the key by yourself ;) http://stackoverflow.com/a/20862098/595152 – Betty St Jul 22 '15 at 21:23
  • Why not use `$localStorage` or the pure javascript API http://www.w3schools.com/html/html5_webstorage.asp ? – Thom-x Jul 22 '15 at 21:23
  • @Thom-x becouse! https://github.com/angular-translate/angular-translate/wiki/Multi-Language read doc. – brabertaser19 Jul 22 '15 at 21:25
  • "it's own solution for local storage" Ok, I thought it use an alternative to $localStorage to write/read localstorage... – Thom-x Jul 22 '15 at 21:29
  • I just looked at the code from ``angular-translate-storage-local.js`` and I think your code is right, did you tried it? – Betty St Jul 22 '15 at 21:38
  • @BettySt yes... just that i think it is not the best solution, also it is ugly( – brabertaser19 Jul 22 '15 at 22:13
  • 1
    Actually there is no senseful reason to change the language code, specially if you think about other modules which also use the ISO standard shortterms. – Simon Fakir Jul 22 '15 at 22:28

0 Answers0