mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-09 22:51:22 +00:00
GUAC-605: Use MessageFormat interpolation for angular-translate.
This commit is contained in:
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