mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
GUAC-1345: Do not attempt to retrieve translation files for languages which are not explicitly listed as available by the REST API.
This commit is contained in:
@@ -29,9 +29,10 @@
|
|||||||
angular.module('locale').factory('translationLoader', ['$injector', function translationLoader($injector) {
|
angular.module('locale').factory('translationLoader', ['$injector', function translationLoader($injector) {
|
||||||
|
|
||||||
// Required services
|
// Required services
|
||||||
var $http = $injector.get('$http');
|
var $http = $injector.get('$http');
|
||||||
var $q = $injector.get('$q');
|
var $q = $injector.get('$q');
|
||||||
var cacheService = $injector.get('cacheService');
|
var cacheService = $injector.get('cacheService');
|
||||||
|
var languageService = $injector.get('languageService');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Satisfies a translation request for the given key by searching for the
|
* Satisfies a translation request for the given key by searching for the
|
||||||
@@ -62,22 +63,48 @@ angular.module('locale').factory('translationLoader', ['$injector', function tra
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attempt to retrieve language
|
/**
|
||||||
$http({
|
* Continues trying possible translation files until no possibilities
|
||||||
cache : cacheService.languages,
|
* exist.
|
||||||
method : 'GET',
|
*
|
||||||
url : 'translations/' + encodeURIComponent(currentKey) + '.json'
|
* @private
|
||||||
})
|
*/
|
||||||
|
var tryNextTranslation = function tryNextTranslation() {
|
||||||
// Resolve promise if translation retrieved successfully
|
|
||||||
.success(function translationFileRetrieved(translation) {
|
|
||||||
deferred.resolve(translation);
|
|
||||||
})
|
|
||||||
|
|
||||||
// Retry with remaining languages if translation file could not be retrieved
|
|
||||||
.error(function translationFileUnretrievable() {
|
|
||||||
satisfyTranslation(deferred, requestedKey, remainingKeys);
|
satisfyTranslation(deferred, requestedKey, remainingKeys);
|
||||||
});
|
};
|
||||||
|
|
||||||
|
// Retrieve list of supported languages
|
||||||
|
languageService.getLanguages()
|
||||||
|
|
||||||
|
// Attempt to retrieve translation if language is supported
|
||||||
|
.success(function retrievedLanguages(languages) {
|
||||||
|
|
||||||
|
// Skip retrieval if language is not supported
|
||||||
|
if (!(currentKey in languages)) {
|
||||||
|
tryNextTranslation();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Attempt to retrieve language
|
||||||
|
$http({
|
||||||
|
cache : cacheService.languages,
|
||||||
|
method : 'GET',
|
||||||
|
url : 'translations/' + encodeURIComponent(currentKey) + '.json'
|
||||||
|
})
|
||||||
|
|
||||||
|
// Resolve promise if translation retrieved successfully
|
||||||
|
.success(function translationFileRetrieved(translation) {
|
||||||
|
deferred.resolve(translation);
|
||||||
|
})
|
||||||
|
|
||||||
|
// Retry with remaining languages if translation file could not be
|
||||||
|
// retrieved
|
||||||
|
.error(tryNextTranslation);
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
// Retry with remaining languages if translation does not exist
|
||||||
|
.error(tryNextTranslation);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user