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

Commit

Permalink
fix(service): translations for forceLanguage will be loaded on demand
Browse files Browse the repository at this point in the history
All service, directive and filter supports `forceLanguage` supporting an override language selector for the specified translation id. Until now, the translation has not been resolved correctly if the language's translations has not been used yet.

Fixes #1389
  • Loading branch information
knalli committed Mar 20, 2016
1 parent bde935e commit 14bc956
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/service/translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,11 @@ function $translate($STORAGE_KEY, $windowProvider, $translateSanitizationProvide
var uses = (forceLanguage && forceLanguage !== $uses) ? // we don't want to re-negotiate $uses
(negotiateLocale(forceLanguage) || forceLanguage) : $uses;

// Check forceLanguage is present
if (forceLanguage) {
loadTranslationsIfMissing(forceLanguage);
}

// Duck detection: If the first argument is an array, a bunch of translations was requested.
// The result is an object.
if (angular.isArray(translationId)) {
Expand Down Expand Up @@ -1623,6 +1628,14 @@ function $translate($STORAGE_KEY, $windowProvider, $translateSanitizationProvide
return resolvedTranslation;
};

var loadTranslationsIfMissing = function (key) {
if (!$translationTable[key] && $loaderFactory && !langPromises[key]) {
langPromises[key] = loadAsync(key).then(function (translation) {
translations(translation.key, translation.table);
});
}
};

/**
* @ngdoc function
* @name pascalprecht.translate.$translate#preferredLanguage
Expand Down Expand Up @@ -2040,6 +2053,11 @@ function $translate($STORAGE_KEY, $windowProvider, $translateSanitizationProvide
return translationId;
}

// Check forceLanguage is present
if (forceLanguage) {
loadTranslationsIfMissing(forceLanguage);
}

// Duck detection: If the first argument is an array, a bunch of translations was requested.
// The result is an object.
if (angular.isArray(translationId)) {
Expand Down

0 comments on commit 14bc956

Please sign in to comment.