1/*! 2 * angular-translate - v2.18.4 - 2021-01-14 3 * 4 * Copyright (c) 2021 The angular-translate team, Pascal Precht; Licensed MIT 5 */ 6(function (root, factory) { 7 if (typeof define === 'function' && define.amd) { 8 // AMD. Register as an anonymous module unless amdModuleId is set 9 define(["messageformat"], function (a0) { 10 return (factory(a0)); 11 }); 12 } else if (typeof module === 'object' && module.exports) { 13 // Node. Does not work with strict CommonJS, but 14 // only CommonJS-like environments that support module.exports, 15 // like Node. 16 module.exports = factory(require("messageformat")); 17 } else { 18 factory(root["MessageFormat"]); 19 } 20}(this, function (MessageFormat) { 21 22angular.module('pascalprecht.translate') 23 24/** 25 * @ngdoc property 26 * @name pascalprecht.translate.TRANSLATE_MF_INTERPOLATION_CACHE 27 * @requires TRANSLATE_MF_INTERPOLATION_CACHE 28 * 29 * @description 30 * Uses MessageFormat.js to interpolate strings against some values. 31 */ 32.constant('TRANSLATE_MF_INTERPOLATION_CACHE', '$translateMessageFormatInterpolation') 33 34/** 35 * @ngdoc object 36 * @name pascalprecht.translate.$translateMessageFormatInterpolationProvider 37 * 38 * @description 39 * Configurations for $translateMessageFormatInterpolation 40 */ 41.provider('$translateMessageFormatInterpolation', $translateMessageFormatInterpolationProvider); 42 43function $translateMessageFormatInterpolationProvider() { 44 45 'use strict'; 46 47 var configurer; 48 49 /** 50 * @ngdoc function 51 * @name pascalprecht.translate.$translateMessageFormatInterpolationProvider#messageFormatConfigurer 52 * @methodOf pascalprecht.translate.$translateMessageFormatInterpolationProvider 53 * 54 * @description 55 * Defines an optional configurer for the MessageFormat instance. 56 * 57 * Note: This hook will be called whenever a new instance of MessageFormat will be created. 58 * 59 * @param {function} fn callback with the instance as argument 60 */ 61 this.messageFormatConfigurer = function (fn) { 62 configurer = fn; 63 }; 64 65 /** 66 * @ngdoc object 67 * @name pascalprecht.translate.$translateMessageFormatInterpolation 68 * @requires pascalprecht.translate.TRANSLATE_MF_INTERPOLATION_CACHE 69 * 70 * @description 71 * Uses MessageFormat.js to interpolate strings against some values. 72 * 73 * Be aware to configure a proper sanitization strategy. 74 * 75 * See also: 76 * * {@link pascalprecht.translate.$translateSanitization} 77 * * {@link https://github.com/SlexAxton/messageformat.js} 78 * 79 * @return {object} $translateMessageFormatInterpolation Interpolator service 80 */ 81 this.$get = ['$translateSanitization', '$cacheFactory', 'TRANSLATE_MF_INTERPOLATION_CACHE', function ($translateSanitization, $cacheFactory, TRANSLATE_MF_INTERPOLATION_CACHE) { 82 return $translateMessageFormatInterpolation($translateSanitization, $cacheFactory, TRANSLATE_MF_INTERPOLATION_CACHE, configurer); 83 }]; 84 85} 86 87function $translateMessageFormatInterpolation($translateSanitization, $cacheFactory, TRANSLATE_MF_INTERPOLATION_CACHE, messageFormatConfigurer) { 88 89 'use strict'; 90 91 var $translateInterpolator = {}, 92 $cache = $cacheFactory.get(TRANSLATE_MF_INTERPOLATION_CACHE), 93 // instantiate with default locale (which is 'en') 94 $mf = new MessageFormat('en'), 95 $identifier = 'messageformat'; 96 97 if (angular.isFunction(messageFormatConfigurer)) { 98 messageFormatConfigurer($mf); 99 } 100 101 if (!$cache) { 102 // create cache if it doesn't exist already 103 $cache = $cacheFactory(TRANSLATE_MF_INTERPOLATION_CACHE); 104 } 105 106 $cache.put('en', $mf); 107 108 /** 109 * @ngdoc function 110 * @name pascalprecht.translate.$translateMessageFormatInterpolation#setLocale 111 * @methodOf pascalprecht.translate.$translateMessageFormatInterpolation 112 * 113 * @description 114 * Sets current locale (this is currently not use in this interpolation). 115 * 116 * @param {string} locale Language key or locale. 117 */ 118 $translateInterpolator.setLocale = function (locale) { 119 $mf = $cache.get(locale); 120 if (!$mf) { 121 $mf = new MessageFormat(locale); 122 if (angular.isFunction(messageFormatConfigurer)) { 123 messageFormatConfigurer($mf); 124 } 125 $cache.put(locale, $mf); 126 } 127 }; 128 129 /** 130 * @ngdoc function 131 * @name pascalprecht.translate.$translateMessageFormatInterpolation#getInterpolationIdentifier 132 * @methodOf pascalprecht.translate.$translateMessageFormatInterpolation 133 * 134 * @description
135 * Returns an identifier for this interpolation service. 136 * 137 * @returns {string} $identifier 138 */ 139 $translateInterpolator.getInterpolationIdentifier = function () { 140 return $identifier; 141 }; 142 143 /** 144 * @deprecated will be removed in 3.0 145 * @see {@link pascalprecht.translate.$translateSanitization} 146 */ 147 $translateInterpolator.useSanitizeValueStrategy = function (value) { 148 $translateSanitization.useStrategy(value); 149 return this; 150 }; 151 152 /** 153 * @ngdoc function 154 * @name pascalprecht.translate.$translateMessageFormatInterpolation#interpolate 155 * @methodOf pascalprecht.translate.$translateMessageFormatInterpolation 156 * 157 * @description 158 * Interpolates given string against given interpolate params using MessageFormat.js. 159 * 160 * @returns {string} interpolated string. 161 */ 162 $translateInterpolator.interpolate = function (string, interpolationParams, context, sanitizeStrategy) { 163 interpolationParams = interpolationParams || {}; 164 interpolationParams = $translateSanitization.sanitize(interpolationParams, 'params', sanitizeStrategy); 165 166 var compiledFunction = $cache.get('mf:' + string); 167 168 // if given string wasn't compiled yet, we do so now and never have to do it again 169 if (!compiledFunction) { 170 171 // Ensure explicit type if possible 172 // MessageFormat checks the actual type (i.e. for amount based conditions) 173 for (var key in interpolationParams) { 174 if (interpolationParams.hasOwnProperty(key)) { 175 // ensure number 176 var number = parseInt(interpolationParams[key], 10); 177 if (angular.isNumber(number) && ('' + number) === interpolationParams[key]) { 178 interpolationParams[key] = number; 179 } 180 } 181 } 182 183 compiledFunction = $mf.compile(string); 184 $cache.put('mf:' + string, compiledFunction); 185 } 186 187 var interpolatedText = compiledFunction(interpolationParams); 188 return $translateSanitization.sanitize(interpolatedText, 'text', sanitizeStrategy); 189 }; 190 191 return $translateInterpolator; 192} 193 194$translateMessageFormatInterpolation.displayName = '$translateMessageFormatInterpolation'; 195return 'pascalprecht.translate'; 196 197}));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.