mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 05:07:41 +00:00
GUAC-605: Use MessageFormat interpolation for angular-translate.
This commit is contained in:
@@ -135,9 +135,11 @@
|
||||
<jsSourceFile>lib/plugins/angular-route.js</jsSourceFile>
|
||||
<jsSourceFile>lib/plugins/angular-translate.js</jsSourceFile>
|
||||
<jsSourceFile>lib/plugins/angular-translate-loader-static-files.js</jsSourceFile>
|
||||
<jsSourceFile>lib/plugins/angular-translate-interpolation-messageformat.js</jsSourceFile>
|
||||
<jsSourceFile>lib/plugins/modal.min.js</jsSourceFile>
|
||||
<jsSourceFile>lib/blob/blob.js</jsSourceFile>
|
||||
<jsSourceFile>lib/filesaver/filesaver.js</jsSourceFile>
|
||||
<jsSourceFile>lib/messageformat/messageformat.js</jsSourceFile>
|
||||
<jsSourceFile>license.txt</jsSourceFile>
|
||||
<jsSourceFile>guacamole-common-js/all.js</jsSourceFile>
|
||||
<jsSourceFile>scripts/session.js</jsSourceFile>
|
||||
|
@@ -24,10 +24,17 @@
|
||||
* The configuration block for setting up everything having to do with i18n.
|
||||
*/
|
||||
angular.module('index').config(['$translateProvider', function($translateProvider) {
|
||||
|
||||
// Use US English by default
|
||||
$translateProvider.preferredLanguage('en_US');
|
||||
|
||||
// Load translations from static JSON files
|
||||
$translateProvider.useStaticFilesLoader({
|
||||
prefix: 'translations/',
|
||||
suffix: '.json'
|
||||
});
|
||||
|
||||
// Provide pluralization, etc. via messageformat.js
|
||||
$translateProvider.useMessageFormatInterpolation();
|
||||
|
||||
}]);
|
1593
guacamole/src/main/webapp/lib/messageformat/messageformat.js
Normal file
1593
guacamole/src/main/webapp/lib/messageformat/messageformat.js
Normal file
File diff suppressed because it is too large
Load Diff
62
guacamole/src/main/webapp/lib/plugins/angular-translate-interpolation-messageformat.js
vendored
Normal file
62
guacamole/src/main/webapp/lib/plugins/angular-translate-interpolation-messageformat.js
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
/*!
|
||||
* angular-translate - v2.2.0 - 2014-06-03
|
||||
* http://github.com/PascalPrecht/angular-translate
|
||||
* Copyright (c) 2014 ; Licensed MIT
|
||||
*/
|
||||
angular.module('pascalprecht.translate').constant('TRANSLATE_MF_INTERPOLATION_CACHE', '$translateMessageFormatInterpolation').factory('$translateMessageFormatInterpolation', [
|
||||
'$cacheFactory',
|
||||
'TRANSLATE_MF_INTERPOLATION_CACHE',
|
||||
function ($cacheFactory, TRANSLATE_MF_INTERPOLATION_CACHE) {
|
||||
var $translateInterpolator = {}, $cache = $cacheFactory.get(TRANSLATE_MF_INTERPOLATION_CACHE), $mf = new MessageFormat(), $identifier = 'messageformat', $sanitizeValueStrategy = null, sanitizeValueStrategies = {
|
||||
escaped: function (params) {
|
||||
var result = {};
|
||||
for (var key in params) {
|
||||
if (params.hasOwnProperty(key)) {
|
||||
result[key] = angular.element('<div></div>').text(params[key]).html();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
var sanitizeParams = function (params) {
|
||||
var result;
|
||||
if (angular.isFunction(sanitizeValueStrategies[$sanitizeValueStrategy])) {
|
||||
result = sanitizeValueStrategies[$sanitizeValueStrategy](params);
|
||||
} else {
|
||||
result = params;
|
||||
}
|
||||
return result;
|
||||
};
|
||||
if (!$cache) {
|
||||
$cache = $cacheFactory(TRANSLATE_MF_INTERPOLATION_CACHE);
|
||||
}
|
||||
$cache.put('en', $mf);
|
||||
$translateInterpolator.setLocale = function (locale) {
|
||||
$mf = $cache.get(locale);
|
||||
if (!$mf) {
|
||||
$mf = new MessageFormat(locale);
|
||||
$cache.put(locale, $mf);
|
||||
}
|
||||
};
|
||||
$translateInterpolator.getInterpolationIdentifier = function () {
|
||||
return $identifier;
|
||||
};
|
||||
$translateInterpolator.useSanitizeValueStrategy = function (value) {
|
||||
$sanitizeValueStrategy = value;
|
||||
return this;
|
||||
};
|
||||
$translateInterpolator.interpolate = function (string, interpolateParams) {
|
||||
interpolateParams = interpolateParams || {};
|
||||
if ($sanitizeValueStrategy) {
|
||||
interpolateParams = sanitizeParams(interpolateParams);
|
||||
}
|
||||
var interpolatedText = $cache.get(string + angular.toJson(interpolateParams));
|
||||
if (!interpolatedText) {
|
||||
interpolatedText = $mf.compile(string)(interpolateParams);
|
||||
$cache.put(string + angular.toJson(interpolateParams), interpolatedText);
|
||||
}
|
||||
return interpolatedText;
|
||||
};
|
||||
return $translateInterpolator;
|
||||
}
|
||||
]);
|
Reference in New Issue
Block a user