Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

Commit

Permalink
fix(service): update storage before triggering $translateChangeSuccess
Browse files Browse the repository at this point in the history
Triggering $translateChangeSuccess before updating the stored language key causes fallback translation to fail the first time $translate.use() is called. The second time it is called with the same language code, it works. This is because promiseToWaitFor() reads what it thinks is the current language from storage, and then proceeds to ignore that as a fallback language. This is not correct behaviour unless the stored language has been updated first.

This bug occurs if you have languages AA and BB with storage enabled, and AA set up to as the fallback language. Changing to BB from AA causes AA to be ignored in the fallback chain, and all translations fail.
  • Loading branch information
runemoennike authored and knalli committed Sep 13, 2015
1 parent beea1fa commit 77dd5a2
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/service/translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -1113,11 +1113,14 @@ function $translate($STORAGE_KEY, $windowProvider, $translateSanitizationProvide
*/
var useLanguage = function (key) {
$uses = key;
$rootScope.$emit('$translateChangeSuccess', {language: key});

// make sure to store new language key before triggering success event
if ($storageFactory) {
Storage.put($translate.storageKey(), $uses);
}

$rootScope.$emit('$translateChangeSuccess', {language: key});

// inform default interpolator
defaultInterpolator.setLocale($uses);

Expand Down

0 comments on commit 77dd5a2

Please sign in to comment.