angular-translate-rails-tf 2.6.3 → 2.7.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 48f0076777fbcf6d9711fd95687b7665653e1835
4
- data.tar.gz: e7b576ef00e88fbf21bc09a0832e76e5973718e7
3
+ metadata.gz: 929573be32a74bd2cfa7fadf2d62f16c567d6b4a
4
+ data.tar.gz: 20a8c41c0be0ba48985362db226cb2ee6c45eac2
5
5
  SHA512:
6
- metadata.gz: b34fb0e7b879c19743f5ca9ede714049c1ee971a70af6879c15b6f9050dccc24eac18834b622fc853437ae5c2b215b2c6d712fc72da275d553b65a68676692af
7
- data.tar.gz: 6bef5dbae974734992ade06be419e8d7c24b8e551685165e8c01ce1d1d35e521a86f545f3d3af927947bce50ed20c79facb3fa351846adeee54c02d6a025ccd2
6
+ metadata.gz: 0e3170d3f54cdca476c86e5dd91a3e6982458a93ce4087a00487f07f9247c455886304f0dd9215122459b3ef1dcfa2d947efd1558103f6d2a4126ac0625586b8
7
+ data.tar.gz: ca1b828a283907b022dedcf6857b537e3ea1ca2b21fe351410e9c60b295afb217660aaac28c7ae8c30820835ed0fcf7b479dfb543c132422ca4e2309dfc6456f
@@ -1,8 +1,24 @@
1
1
  /*!
2
- * angular-translate - v2.6.1 - 2015-03-01
2
+ * angular-translate - v2.7.2 - 2015-06-01
3
3
  * http://github.com/angular-translate/angular-translate
4
4
  * Copyright (c) 2015 ; Licensed MIT
5
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([], function () {
10
+ return (factory());
11
+ });
12
+ } else if (typeof exports === 'object') {
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();
17
+ } else {
18
+ factory();
19
+ }
20
+ }(this, function () {
21
+
6
22
  /**
7
23
  * @ngdoc overview
8
24
  * @name pascalprecht.translate
@@ -11,13 +27,16 @@
11
27
  * The main module which holds everything together.
12
28
  */
13
29
  angular.module('pascalprecht.translate', ['ng'])
30
+ .run(runTranslate);
31
+
32
+ function runTranslate($translate) {
14
33
 
15
- .run(['$translate', function ($translate) {
34
+ 'use strict';
16
35
 
17
36
  var key = $translate.storageKey(),
18
- storage = $translate.storage();
37
+ storage = $translate.storage();
19
38
 
20
- var fallbackFromIncorrectStorageValue = function() {
39
+ var fallbackFromIncorrectStorageValue = function () {
21
40
  var preferred = $translate.preferredLanguage();
22
41
  if (angular.isString(preferred)) {
23
42
  $translate.use(preferred);
@@ -28,6 +47,8 @@ angular.module('pascalprecht.translate', ['ng'])
28
47
  }
29
48
  };
30
49
 
50
+ fallbackFromIncorrectStorageValue.displayName = 'fallbackFromIncorrectStorageValue';
51
+
31
52
  if (storage) {
32
53
  if (!storage.get(key)) {
33
54
  fallbackFromIncorrectStorageValue();
@@ -37,7 +58,256 @@ angular.module('pascalprecht.translate', ['ng'])
37
58
  } else if (angular.isString($translate.preferredLanguage())) {
38
59
  $translate.use($translate.preferredLanguage());
39
60
  }
40
- }]);
61
+ }
62
+ runTranslate.$inject = ['$translate'];
63
+
64
+ runTranslate.displayName = 'runTranslate';
65
+
66
+ /**
67
+ * @ngdoc object
68
+ * @name pascalprecht.translate.$translateSanitizationProvider
69
+ *
70
+ * @description
71
+ *
72
+ * Configurations for $translateSanitization
73
+ */
74
+ angular.module('pascalprecht.translate').provider('$translateSanitization', $translateSanitizationProvider);
75
+
76
+ function $translateSanitizationProvider () {
77
+
78
+ 'use strict';
79
+
80
+ var $sanitize,
81
+ currentStrategy = null, // TODO change to either 'sanitize', 'escape' or ['sanitize', 'escapeParameters'] in 3.0.
82
+ hasConfiguredStrategy = false,
83
+ hasShownNoStrategyConfiguredWarning = false,
84
+ strategies;
85
+
86
+ /**
87
+ * Definition of a sanitization strategy function
88
+ * @callback StrategyFunction
89
+ * @param {string|object} value - value to be sanitized (either a string or an interpolated value map)
90
+ * @param {string} mode - either 'text' for a string (translation) or 'params' for the interpolated params
91
+ * @return {string|object}
92
+ */
93
+
94
+ /**
95
+ * @ngdoc property
96
+ * @name strategies
97
+ * @propertyOf pascalprecht.translate.$translateSanitizationProvider
98
+ *
99
+ * @description
100
+ * Following strategies are built-in:
101
+ * <dl>
102
+ * <dt>sanitize</dt>
103
+ * <dd>Sanitizes HTML in the translation text using $sanitize</dd>
104
+ * <dt>escape</dt>
105
+ * <dd>Escapes HTML in the translation</dd>
106
+ * <dt>sanitizeParameters</dt>
107
+ * <dd>Sanitizes HTML in the values of the interpolation parameters using $sanitize</dd>
108
+ * <dt>escapeParameters</dt>
109
+ * <dd>Escapes HTML in the values of the interpolation parameters</dd>
110
+ * <dt>escaped</dt>
111
+ * <dd>Support legacy strategy name 'escaped' for backwards compatibility (will be removed in 3.0)</dd>
112
+ * </dl>
113
+ *
114
+ */
115
+
116
+ strategies = {
117
+ sanitize: function (value, mode) {
118
+ if (mode === 'text') {
119
+ value = htmlSanitizeValue(value);
120
+ }
121
+ return value;
122
+ },
123
+ escape: function (value, mode) {
124
+ if (mode === 'text') {
125
+ value = htmlEscapeValue(value);
126
+ }
127
+ return value;
128
+ },
129
+ sanitizeParameters: function (value, mode) {
130
+ if (mode === 'params') {
131
+ value = mapInterpolationParameters(value, htmlSanitizeValue);
132
+ }
133
+ return value;
134
+ },
135
+ escapeParameters: function (value, mode) {
136
+ if (mode === 'params') {
137
+ value = mapInterpolationParameters(value, htmlEscapeValue);
138
+ }
139
+ return value;
140
+ }
141
+ };
142
+ // Support legacy strategy name 'escaped' for backwards compatibility.
143
+ // TODO should be removed in 3.0
144
+ strategies.escaped = strategies.escapeParameters;
145
+
146
+ /**
147
+ * @ngdoc function
148
+ * @name pascalprecht.translate.$translateSanitizationProvider#addStrategy
149
+ * @methodOf pascalprecht.translate.$translateSanitizationProvider
150
+ *
151
+ * @description
152
+ * Adds a sanitization strategy to the list of known strategies.
153
+ *
154
+ * @param {string} strategyName - unique key for a strategy
155
+ * @param {StrategyFunction} strategyFunction - strategy function
156
+ * @returns {object} this
157
+ */
158
+ this.addStrategy = function (strategyName, strategyFunction) {
159
+ strategies[strategyName] = strategyFunction;
160
+ return this;
161
+ };
162
+
163
+ /**
164
+ * @ngdoc function
165
+ * @name pascalprecht.translate.$translateSanitizationProvider#removeStrategy
166
+ * @methodOf pascalprecht.translate.$translateSanitizationProvider
167
+ *
168
+ * @description
169
+ * Removes a sanitization strategy from the list of known strategies.
170
+ *
171
+ * @param {string} strategyName - unique key for a strategy
172
+ * @returns {object} this
173
+ */
174
+ this.removeStrategy = function (strategyName) {
175
+ delete strategies[strategyName];
176
+ return this;
177
+ };
178
+
179
+ /**
180
+ * @ngdoc function
181
+ * @name pascalprecht.translate.$translateSanitizationProvider#useStrategy
182
+ * @methodOf pascalprecht.translate.$translateSanitizationProvider
183
+ *
184
+ * @description
185
+ * Selects a sanitization strategy. When an array is provided the strategies will be executed in order.
186
+ *
187
+ * @param {string|StrategyFunction|array} strategy The sanitization strategy / strategies which should be used. Either a name of an existing strategy, a custom strategy function, or an array consisting of multiple names and / or custom functions.
188
+ * @returns {object} this
189
+ */
190
+ this.useStrategy = function (strategy) {
191
+ hasConfiguredStrategy = true;
192
+ currentStrategy = strategy;
193
+ return this;
194
+ };
195
+
196
+ /**
197
+ * @ngdoc object
198
+ * @name pascalprecht.translate.$translateSanitization
199
+ * @requires $injector
200
+ * @requires $log
201
+ *
202
+ * @description
203
+ * Sanitizes interpolation parameters and translated texts.
204
+ *
205
+ */
206
+ this.$get = ['$injector', '$log', function ($injector, $log) {
207
+
208
+ var applyStrategies = function (value, mode, selectedStrategies) {
209
+ angular.forEach(selectedStrategies, function (selectedStrategy) {
210
+ if (angular.isFunction(selectedStrategy)) {
211
+ value = selectedStrategy(value, mode);
212
+ } else if (angular.isFunction(strategies[selectedStrategy])) {
213
+ value = strategies[selectedStrategy](value, mode);
214
+ } else {
215
+ throw new Error('pascalprecht.translate.$translateSanitization: Unknown sanitization strategy: \'' + selectedStrategy + '\'');
216
+ }
217
+ });
218
+ return value;
219
+ };
220
+
221
+ // TODO: should be removed in 3.0
222
+ var showNoStrategyConfiguredWarning = function () {
223
+ if (!hasConfiguredStrategy && !hasShownNoStrategyConfiguredWarning) {
224
+ $log.warn('pascalprecht.translate.$translateSanitization: No sanitization strategy has been configured. This can have serious security implications. See http://angular-translate.github.io/docs/#/guide/19_security for details.');
225
+ hasShownNoStrategyConfiguredWarning = true;
226
+ }
227
+ };
228
+
229
+ if ($injector.has('$sanitize')) {
230
+ $sanitize = $injector.get('$sanitize');
231
+ }
232
+
233
+ return {
234
+ /**
235
+ * @ngdoc function
236
+ * @name pascalprecht.translate.$translateSanitization#useStrategy
237
+ * @methodOf pascalprecht.translate.$translateSanitization
238
+ *
239
+ * @description
240
+ * Selects a sanitization strategy. When an array is provided the strategies will be executed in order.
241
+ *
242
+ * @param {string|StrategyFunction|array} strategy The sanitization strategy / strategies which should be used. Either a name of an existing strategy, a custom strategy function, or an array consisting of multiple names and / or custom functions.
243
+ */
244
+ useStrategy: (function (self) {
245
+ return function (strategy) {
246
+ self.useStrategy(strategy);
247
+ };
248
+ })(this),
249
+
250
+ /**
251
+ * @ngdoc function
252
+ * @name pascalprecht.translate.$translateSanitization#sanitize
253
+ * @methodOf pascalprecht.translate.$translateSanitization
254
+ *
255
+ * @description
256
+ * Sanitizes a value.
257
+ *
258
+ * @param {string|object} value The value which should be sanitized.
259
+ * @param {string} mode The current sanitization mode, either 'params' or 'text'.
260
+ * @param {string|StrategyFunction|array} [strategy] Optional custom strategy which should be used instead of the currently selected strategy.
261
+ * @returns {string|object} sanitized value
262
+ */
263
+ sanitize: function (value, mode, strategy) {
264
+ if (!currentStrategy) {
265
+ showNoStrategyConfiguredWarning();
266
+ }
267
+
268
+ if (arguments.length < 3) {
269
+ strategy = currentStrategy;
270
+ }
271
+
272
+ if (!strategy) {
273
+ return value;
274
+ }
275
+
276
+ var selectedStrategies = angular.isArray(strategy) ? strategy : [strategy];
277
+ return applyStrategies(value, mode, selectedStrategies);
278
+ }
279
+ };
280
+ }];
281
+
282
+ var htmlEscapeValue = function (value) {
283
+ var element = angular.element('<div></div>');
284
+ element.text(value); // not chainable, see #1044
285
+ return element.html();
286
+ };
287
+
288
+ var htmlSanitizeValue = function (value) {
289
+ if (!$sanitize) {
290
+ throw new Error('pascalprecht.translate.$translateSanitization: Error cannot find $sanitize service. Either include the ngSanitize module (https://docs.angularjs.org/api/ngSanitize) or use a sanitization strategy which does not depend on $sanitize, such as \'escape\'.');
291
+ }
292
+ return $sanitize(value);
293
+ };
294
+
295
+ var mapInterpolationParameters = function (value, iteratee) {
296
+ if (angular.isObject(value)) {
297
+ var result = angular.isArray(value) ? [] : {};
298
+
299
+ angular.forEach(value, function (propertyValue, propertyKey) {
300
+ result[propertyKey] = mapInterpolationParameters(propertyValue, iteratee);
301
+ });
302
+
303
+ return result;
304
+ } else if (angular.isNumber(value)) {
305
+ return value;
306
+ } else {
307
+ return iteratee(value);
308
+ }
309
+ };
310
+ }
41
311
 
42
312
  /**
43
313
  * @ngdoc object
@@ -48,7 +318,13 @@ angular.module('pascalprecht.translate', ['ng'])
48
318
  * and similar to configure translation behavior directly inside of a module.
49
319
  *
50
320
  */
51
- angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY', '$windowProvider', function ($STORAGE_KEY, $windowProvider) {
321
+ angular.module('pascalprecht.translate')
322
+ .constant('pascalprechtTranslateOverrider', {})
323
+ .provider('$translate', $translate);
324
+
325
+ function $translate($STORAGE_KEY, $windowProvider, $translateSanitizationProvider, pascalprechtTranslateOverrider) {
326
+
327
+ 'use strict';
52
328
 
53
329
  var $translationTable = {},
54
330
  $preferredLanguage,
@@ -64,21 +340,44 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY',
64
340
  $missingTranslationHandlerFactory,
65
341
  $interpolationFactory,
66
342
  $interpolatorFactories = [],
67
- $interpolationSanitizationStrategy = false,
68
343
  $loaderFactory,
69
344
  $cloakClassName = 'translate-cloak',
70
345
  $loaderOptions,
71
346
  $notFoundIndicatorLeft,
72
347
  $notFoundIndicatorRight,
73
348
  $postCompilingEnabled = false,
349
+ $forceAsyncReloadEnabled = false,
74
350
  NESTED_OBJECT_DELIMITER = '.',
75
351
  loaderCache,
76
- directivePriority = 0;
352
+ directivePriority = 0,
353
+ statefulFilter = true,
354
+ uniformLanguageTagResolver = 'default',
355
+ languageTagResolver = {
356
+ 'default': function (tag) {
357
+ return (tag || '').split('-').join('_');
358
+ },
359
+ java: function (tag) {
360
+ var temp = (tag || '').split('-').join('_');
361
+ var parts = temp.split('_');
362
+ return parts.length > 1 ? (parts[0].toLowerCase() + '_' + parts[1].toUpperCase()) : temp;
363
+ },
364
+ bcp47: function (tag) {
365
+ var temp = (tag || '').split('_').join('-');
366
+ var parts = temp.split('-');
367
+ return parts.length > 1 ? (parts[0].toLowerCase() + '-' + parts[1].toUpperCase()) : temp;
368
+ }
369
+ };
77
370
 
78
- var version = '2.6.1';
371
+ var version = '2.7.2';
79
372
 
80
373
  // tries to determine the browsers language
81
374
  var getFirstBrowserLanguage = function () {
375
+
376
+ // internal purpose only
377
+ if (angular.isFunction(pascalprechtTranslateOverrider.getLocale)) {
378
+ return pascalprechtTranslateOverrider.getLocale();
379
+ }
380
+
82
381
  var nav = $windowProvider.$get().navigator,
83
382
  browserLanguagePropertyKeys = ['language', 'browserLanguage', 'systemLanguage', 'userLanguage'],
84
383
  i,
@@ -108,7 +407,11 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY',
108
407
 
109
408
  // tries to determine the browsers locale
110
409
  var getLocale = function () {
111
- return (getFirstBrowserLanguage() || '').split('-').join('_');
410
+ var locale = getFirstBrowserLanguage() || '';
411
+ if (languageTagResolver[uniformLanguageTagResolver]) {
412
+ locale = languageTagResolver[uniformLanguageTagResolver](locale);
413
+ }
414
+ return locale;
112
415
  };
113
416
  getLocale.displayName = 'angular-translate/service: getLocale';
114
417
 
@@ -180,10 +483,12 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY',
180
483
  }
181
484
  }
182
485
 
183
- var parts = preferred.split('_');
486
+ if (preferred) {
487
+ var parts = preferred.split('_');
184
488
 
185
- if (parts.length > 1 && indexOf(avail, angular.lowercase(parts[0])) > -1) {
186
- return parts[0];
489
+ if (parts.length > 1 && indexOf(avail, angular.lowercase(parts[0])) > -1) {
490
+ return parts[0];
491
+ }
187
492
  }
188
493
 
189
494
  // If everything fails, just return the preferred, unchanged.
@@ -304,6 +609,7 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY',
304
609
  }
305
610
  return result;
306
611
  };
612
+ flatObject.displayName = 'flatObject';
307
613
 
308
614
  /**
309
615
  * @ngdoc function
@@ -361,7 +667,7 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY',
361
667
  * @param {string} value Strategy type.
362
668
  */
363
669
  this.useSanitizeValueStrategy = function (value) {
364
- $interpolationSanitizationStrategy = value;
670
+ $translateSanitizationProvider.useStrategy(value);
365
671
  return this;
366
672
  };
367
673
 
@@ -511,7 +817,7 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY',
511
817
  if (langKey) {
512
818
  if (!$translationTable[langKey] && (!$loaderFactory)) {
513
819
  // only throw an error, when not loading translation data asynchronously
514
- throw new Error("$translateProvider couldn't find translationTable for langKey: '" + langKey + "'");
820
+ throw new Error('$translateProvider couldn\'t find translationTable for langKey: \'' + langKey + '\'');
515
821
  }
516
822
  $uses = langKey;
517
823
  return this;
@@ -537,6 +843,7 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY',
537
843
  return $storageKey;
538
844
  }
539
845
  $storageKey = key;
846
+ return this;
540
847
  };
541
848
 
542
849
  this.storageKey = storageKey;
@@ -713,6 +1020,86 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY',
713
1020
  return this;
714
1021
  };
715
1022
 
1023
+ /**
1024
+ * @ngdoc function
1025
+ * @name pascalprecht.translate.$translateProvider#forceAsyncReload
1026
+ * @methodOf pascalprecht.translate.$translateProvider
1027
+ *
1028
+ * @description
1029
+ * If force async reload is enabled, async loader will always be called
1030
+ * even if $translationTable already contains the language key, adding
1031
+ * possible new entries to the $translationTable.
1032
+ *
1033
+ * Example:
1034
+ * <pre>
1035
+ * app.config(function ($translateProvider) {
1036
+ * $translateProvider.forceAsyncReload(true);
1037
+ * });
1038
+ * </pre>
1039
+ *
1040
+ * @param {boolean} value - valid values are true or false
1041
+ */
1042
+ this.forceAsyncReload = function (value) {
1043
+ $forceAsyncReloadEnabled = !(!value);
1044
+ return this;
1045
+ };
1046
+
1047
+ /**
1048
+ * @ngdoc function
1049
+ * @name pascalprecht.translate.$translateProvider#uniformLanguageTag
1050
+ * @methodOf pascalprecht.translate.$translateProvider
1051
+ *
1052
+ * @description
1053
+ * Tells angular-translate which language tag should be used as a result when determining
1054
+ * the current browser language.
1055
+ *
1056
+ * This setting must be set before invoking {@link pascalprecht.translate.$translateProvider#methods_determinePreferredLanguage determinePreferredLanguage()}.
1057
+ *
1058
+ * <pre>
1059
+ * $translateProvider
1060
+ * .uniformLanguageTag('bcp47')
1061
+ * .determinePreferredLanguage()
1062
+ * </pre>
1063
+ *
1064
+ * The resolver currently supports:
1065
+ * * default
1066
+ * (traditionally: hyphens will be converted into underscores, i.e. en-US => en_US)
1067
+ * en-US => en_US
1068
+ * en_US => en_US
1069
+ * en-us => en_us
1070
+ * * java
1071
+ * like default, but the second part will be always in uppercase
1072
+ * en-US => en_US
1073
+ * en_US => en_US
1074
+ * en-us => en_US
1075
+ * * BCP 47 (RFC 4646 & 4647)
1076
+ * en-US => en-US
1077
+ * en_US => en-US
1078
+ * en-us => en-US
1079
+ *
1080
+ * See also:
1081
+ * * http://en.wikipedia.org/wiki/IETF_language_tag
1082
+ * * http://www.w3.org/International/core/langtags/
1083
+ * * http://tools.ietf.org/html/bcp47
1084
+ *
1085
+ * @param {string|object} options - options (or standard)
1086
+ * @param {string} options.standard - valid values are 'default', 'bcp47', 'java'
1087
+ */
1088
+ this.uniformLanguageTag = function (options) {
1089
+
1090
+ if (!options) {
1091
+ options = {};
1092
+ } else if (angular.isString(options)) {
1093
+ options = {
1094
+ standard: options
1095
+ };
1096
+ }
1097
+
1098
+ uniformLanguageTagResolver = options.standard;
1099
+
1100
+ return this;
1101
+ };
1102
+
716
1103
  /**
717
1104
  * @ngdoc function
718
1105
  * @name pascalprecht.translate.$translateProvider#determinePreferredLanguage
@@ -728,9 +1115,9 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY',
728
1115
  * `[lang]` depending on what the browser provides.
729
1116
  *
730
1117
  * Use this method at your own risk, since not all browsers return a valid
731
- * locale.
1118
+ * locale (see {@link pascalprecht.translate.$translateProvider#methods_uniformLanguageTag uniformLanguageTag()}).
732
1119
  *
733
- * @param {object=} fn Function to determine a browser's locale
1120
+ * @param {Function=} fn Function to determine a browser's locale
734
1121
  */
735
1122
  this.determinePreferredLanguage = function (fn) {
736
1123
 
@@ -825,6 +1212,31 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY',
825
1212
  }
826
1213
  };
827
1214
 
1215
+ /**
1216
+ * @ngdoc function
1217
+ * @name pascalprecht.translate.$translateProvider#statefulFilter
1218
+ * @methodOf pascalprecht.translate.$translateProvider
1219
+ *
1220
+ * @description
1221
+ * Since AngularJS 1.3, filters which are not stateless (depending at the scope)
1222
+ * have to explicit define this behavior.
1223
+ * Sets whether the translate filter should be stateful or stateless. The standard value is `true`
1224
+ * meaning being stateful.
1225
+ * Calling this function without an argument will return the current value.
1226
+ *
1227
+ * @param {boolean} state - defines the state of the filter
1228
+ */
1229
+ this.statefulFilter = function (state) {
1230
+ if (state === undefined) {
1231
+ // getter
1232
+ return statefulFilter;
1233
+ } else {
1234
+ // setter with chaining
1235
+ statefulFilter = state;
1236
+ return this;
1237
+ }
1238
+ };
1239
+
828
1240
  /**
829
1241
  * @ngdoc object
830
1242
  * @name pascalprecht.translate.$translate
@@ -944,9 +1356,12 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY',
944
1356
  // We can just translate.
945
1357
  determineTranslation(translationId, interpolateParams, interpolationId, defaultTranslationText).then(deferred.resolve, deferred.reject);
946
1358
  } else {
947
- promiseToWaitFor.then(function () {
1359
+ var promiseResolved = function () {
948
1360
  determineTranslation(translationId, interpolateParams, interpolationId, defaultTranslationText).then(deferred.resolve, deferred.reject);
949
- }, deferred.reject);
1361
+ };
1362
+ promiseResolved.displayName = 'promiseResolved';
1363
+
1364
+ promiseToWaitFor['finally'](promiseResolved, deferred.reject);
950
1365
  }
951
1366
  return deferred.promise;
952
1367
  };
@@ -995,10 +1410,14 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY',
995
1410
  }
996
1411
  // inform default interpolator
997
1412
  defaultInterpolator.setLocale($uses);
998
- // inform all others too!
999
- angular.forEach(interpolatorHashMap, function (interpolator, id) {
1413
+
1414
+ var eachInterpolator = function (interpolator, id) {
1000
1415
  interpolatorHashMap[id].setLocale($uses);
1001
- });
1416
+ };
1417
+ eachInterpolator.displayName = 'eachInterpolatorLocaleSetter';
1418
+
1419
+ // inform all others too!
1420
+ angular.forEach(interpolatorHashMap, eachInterpolator);
1002
1421
  $rootScope.$emit('$translateChangeEnd', {language: key});
1003
1422
  };
1004
1423
 
@@ -1037,7 +1456,7 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY',
1037
1456
  }, $loaderOptions.$http)
1038
1457
  });
1039
1458
 
1040
- $injector.get($loaderFactory)(loaderOptions).then(function (data) {
1459
+ var onLoaderSuccess = function (data) {
1041
1460
  var translationTable = {};
1042
1461
  $rootScope.$emit('$translateLoadingSuccess', {language: key});
1043
1462
 
@@ -1054,11 +1473,19 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY',
1054
1473
  table: translationTable
1055
1474
  });
1056
1475
  $rootScope.$emit('$translateLoadingEnd', {language: key});
1057
- }, function (key) {
1476
+ };
1477
+ onLoaderSuccess.displayName = 'onLoaderSuccess';
1478
+
1479
+ var onLoaderError = function (key) {
1058
1480
  $rootScope.$emit('$translateLoadingError', {language: key});
1059
1481
  deferred.reject(key);
1060
1482
  $rootScope.$emit('$translateLoadingEnd', {language: key});
1061
- });
1483
+ };
1484
+ onLoaderError.displayName = 'onLoaderError';
1485
+
1486
+ $injector.get($loaderFactory)(loaderOptions)
1487
+ .then(onLoaderSuccess, onLoaderError);
1488
+
1062
1489
  return deferred.promise;
1063
1490
  };
1064
1491
 
@@ -1070,25 +1497,19 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY',
1070
1497
  }
1071
1498
  }
1072
1499
 
1073
- // apply additional settings
1074
- if (angular.isFunction(defaultInterpolator.useSanitizeValueStrategy)) {
1075
- defaultInterpolator.useSanitizeValueStrategy($interpolationSanitizationStrategy);
1076
- }
1077
-
1078
1500
  // if we have additional interpolations that were added via
1079
1501
  // $translateProvider.addInterpolation(), we have to map'em
1080
1502
  if ($interpolatorFactories.length) {
1081
- angular.forEach($interpolatorFactories, function (interpolatorFactory) {
1503
+ var eachInterpolationFactory = function (interpolatorFactory) {
1082
1504
  var interpolator = $injector.get(interpolatorFactory);
1083
1505
  // setting initial locale for each interpolation service
1084
1506
  interpolator.setLocale($preferredLanguage || $uses);
1085
- // apply additional settings
1086
- if (angular.isFunction(interpolator.useSanitizeValueStrategy)) {
1087
- interpolator.useSanitizeValueStrategy($interpolationSanitizationStrategy);
1088
- }
1089
1507
  // make'em recognizable through id
1090
1508
  interpolatorHashMap[interpolator.getInterpolationIdentifier()] = interpolator;
1091
- });
1509
+ };
1510
+ eachInterpolationFactory.displayName = 'interpolationFactoryAdder';
1511
+
1512
+ angular.forEach($interpolatorFactories, eachInterpolationFactory);
1092
1513
  }
1093
1514
 
1094
1515
  /**
@@ -1107,10 +1528,12 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY',
1107
1528
  if (Object.prototype.hasOwnProperty.call($translationTable, langKey)) {
1108
1529
  deferred.resolve($translationTable[langKey]);
1109
1530
  } else if (langPromises[langKey]) {
1110
- langPromises[langKey].then(function (data) {
1531
+ var onResolve = function (data) {
1111
1532
  translations(data.key, data.table);
1112
1533
  deferred.resolve(data.table);
1113
- }, deferred.reject);
1534
+ };
1535
+ onResolve.displayName = 'translationTableResolver';
1536
+ langPromises[langKey].then(onResolve, deferred.reject);
1114
1537
  } else {
1115
1538
  deferred.reject();
1116
1539
  }
@@ -1135,7 +1558,7 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY',
1135
1558
  var getFallbackTranslation = function (langKey, translationId, interpolateParams, Interpolator) {
1136
1559
  var deferred = $q.defer();
1137
1560
 
1138
- getTranslationTable(langKey).then(function (translationTable) {
1561
+ var onResolve = function (translationTable) {
1139
1562
  if (Object.prototype.hasOwnProperty.call(translationTable, translationId)) {
1140
1563
  Interpolator.setLocale(langKey);
1141
1564
  var translation = translationTable[translationId];
@@ -1149,7 +1572,10 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY',
1149
1572
  } else {
1150
1573
  deferred.reject();
1151
1574
  }
1152
- }, deferred.reject);
1575
+ };
1576
+ onResolve.displayName = 'fallbackTranslationResolver';
1577
+
1578
+ getTranslationTable(langKey).then(onResolve, deferred.reject);
1153
1579
 
1154
1580
  return deferred.promise;
1155
1581
  };
@@ -1194,11 +1620,11 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY',
1194
1620
  * @returns translation created by $missingTranslationHandler or translationId is $missingTranslationHandler is
1195
1621
  * absent
1196
1622
  */
1197
- var translateByHandler = function (translationId) {
1623
+ var translateByHandler = function (translationId, interpolateParams) {
1198
1624
  // If we have a handler factory - we might also call it here to determine if it provides
1199
1625
  // a default text for a translationid that can't be found anywhere in our tables
1200
1626
  if ($missingTranslationHandlerFactory) {
1201
- var resultString = $injector.get($missingTranslationHandlerFactory)(translationId, $uses);
1627
+ var resultString = $injector.get($missingTranslationHandlerFactory)(translationId, $uses, interpolateParams);
1202
1628
  if (resultString !== undefined) {
1203
1629
  return resultString;
1204
1630
  } else {
@@ -1243,7 +1669,7 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY',
1243
1669
  } else {
1244
1670
  // if no default translation is set and an error handler is defined, send it to the handler
1245
1671
  // and then return the result
1246
- deferred.resolve(translateByHandler(translationId));
1672
+ deferred.resolve(translateByHandler(translationId, interpolateParams));
1247
1673
  }
1248
1674
  }
1249
1675
  return deferred.promise;
@@ -1324,7 +1750,7 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY',
1324
1750
  var missingTranslationHandlerTranslation;
1325
1751
  // for logging purposes only (as in $translateMissingTranslationHandlerLog), value is not returned to promise
1326
1752
  if ($missingTranslationHandlerFactory && !pendingLoader) {
1327
- missingTranslationHandlerTranslation = translateByHandler(translationId);
1753
+ missingTranslationHandlerTranslation = translateByHandler(translationId, interpolateParams);
1328
1754
  }
1329
1755
 
1330
1756
  // since we couldn't translate the inital requested translation id,
@@ -1381,7 +1807,7 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY',
1381
1807
  var missingTranslationHandlerTranslation;
1382
1808
  // for logging purposes only (as in $translateMissingTranslationHandlerLog), value is not returned to promise
1383
1809
  if ($missingTranslationHandlerFactory && !pendingLoader) {
1384
- missingTranslationHandlerTranslation = translateByHandler(translationId);
1810
+ missingTranslationHandlerTranslation = translateByHandler(translationId, interpolateParams);
1385
1811
  }
1386
1812
 
1387
1813
  // since we couldn't translate the inital requested translation id,
@@ -1403,6 +1829,13 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY',
1403
1829
  return result;
1404
1830
  };
1405
1831
 
1832
+ var clearNextLangAndPromise = function(key) {
1833
+ if ($nextLang === key) {
1834
+ $nextLang = undefined;
1835
+ }
1836
+ langPromises[key] = undefined;
1837
+ };
1838
+
1406
1839
  /**
1407
1840
  * @ngdoc function
1408
1841
  * @name pascalprecht.translate.$translate#preferredLanguage
@@ -1567,24 +2000,31 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY',
1567
2000
 
1568
2001
  // if there isn't a translation table for the language we've requested,
1569
2002
  // we load it asynchronously
1570
- if (!$translationTable[key] && $loaderFactory && !langPromises[key]) {
2003
+ if (($forceAsyncReloadEnabled || !$translationTable[key]) && $loaderFactory && !langPromises[key]) {
1571
2004
  $nextLang = key;
1572
2005
  langPromises[key] = loadAsync(key).then(function (translation) {
1573
2006
  translations(translation.key, translation.table);
1574
2007
  deferred.resolve(translation.key);
1575
-
1576
2008
  useLanguage(translation.key);
1577
- if ($nextLang === key) {
1578
- $nextLang = undefined;
1579
- }
1580
2009
  return translation;
1581
2010
  }, function (key) {
1582
- if ($nextLang === key) {
1583
- $nextLang = undefined;
1584
- }
1585
2011
  $rootScope.$emit('$translateChangeError', {language: key});
1586
2012
  deferred.reject(key);
1587
2013
  $rootScope.$emit('$translateChangeEnd', {language: key});
2014
+ return $q.reject(key);
2015
+ });
2016
+ langPromises[key]['finally'](function () {
2017
+ clearNextLangAndPromise(key);
2018
+ });
2019
+ } else if ($nextLang === key && langPromises[key]) {
2020
+ // we are already loading this asynchronously
2021
+ // resolve our new deferred when the old langPromise is resolved
2022
+ langPromises[key].then(function (translation) {
2023
+ deferred.resolve(translation.key);
2024
+ return translation;
2025
+ }, function (key) {
2026
+ deferred.reject(key);
2027
+ return $q.reject(key);
1588
2028
  });
1589
2029
  } else {
1590
2030
  deferred.resolve(key);
@@ -1622,6 +2062,20 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY',
1622
2062
  return $postCompilingEnabled;
1623
2063
  };
1624
2064
 
2065
+ /**
2066
+ * @ngdoc function
2067
+ * @name pascalprecht.translate.$translate#isForceAsyncReloadEnabled
2068
+ * @methodOf pascalprecht.translate.$translate
2069
+ *
2070
+ * @description
2071
+ * Returns whether force async reload is enabled or not
2072
+ *
2073
+ * @return {boolean} forceAsyncReload value
2074
+ */
2075
+ $translate.isForceAsyncReloadEnabled = function () {
2076
+ return $forceAsyncReloadEnabled;
2077
+ };
2078
+
1625
2079
  /**
1626
2080
  * @ngdoc function
1627
2081
  * @name pascalprecht.translate.$translate#refresh
@@ -1687,28 +2141,32 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY',
1687
2141
  tables.push(loadAsync($uses));
1688
2142
  }
1689
2143
 
1690
- $q.all(tables).then(function (tableData) {
2144
+ var allTranslationsLoaded = function (tableData) {
2145
+ $translationTable = {};
1691
2146
  angular.forEach(tableData, function (data) {
1692
- if ($translationTable[data.key]) {
1693
- delete $translationTable[data.key];
1694
- }
1695
2147
  translations(data.key, data.table);
1696
2148
  });
1697
2149
  if ($uses) {
1698
2150
  useLanguage($uses);
1699
2151
  }
1700
2152
  resolve();
1701
- });
2153
+ };
2154
+ allTranslationsLoaded.displayName = 'refreshPostProcessor';
2155
+
2156
+ $q.all(tables).then(allTranslationsLoaded, reject);
1702
2157
 
1703
2158
  } else if ($translationTable[langKey]) {
1704
2159
 
1705
- loadAsync(langKey).then(function (data) {
2160
+ var oneTranslationsLoaded = function (data) {
1706
2161
  translations(data.key, data.table);
1707
2162
  if (langKey === $uses) {
1708
2163
  useLanguage($uses);
1709
2164
  }
1710
2165
  resolve();
1711
- }, reject);
2166
+ };
2167
+ oneTranslationsLoaded.displayName = 'refreshPostProcessor';
2168
+
2169
+ loadAsync(langKey).then(oneTranslationsLoaded, reject);
1712
2170
 
1713
2171
  } else {
1714
2172
  reject();
@@ -1734,7 +2192,7 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY',
1734
2192
  * @param {object} interpolateParams Params
1735
2193
  * @param {string} interpolationId The id of the interpolation to use
1736
2194
  *
1737
- * @return {string} translation
2195
+ * @return {string|object} translation
1738
2196
  */
1739
2197
  $translate.instant = function (translationId, interpolateParams, interpolationId) {
1740
2198
 
@@ -1791,7 +2249,7 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY',
1791
2249
  // Return translation of default interpolator if not found anything.
1792
2250
  result = defaultInterpolator.interpolate(translationId, interpolateParams);
1793
2251
  if ($missingTranslationHandlerFactory && !pendingLoader) {
1794
- result = translateByHandler(translationId);
2252
+ result = translateByHandler(translationId, interpolateParams);
1795
2253
  }
1796
2254
  }
1797
2255
 
@@ -1831,6 +2289,11 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY',
1831
2289
  return directivePriority;
1832
2290
  };
1833
2291
 
2292
+ // internal purpose only
2293
+ $translate.statefulFilter = function () {
2294
+ return statefulFilter;
2295
+ };
2296
+
1834
2297
  if ($loaderFactory) {
1835
2298
 
1836
2299
  // If at least one async loader is defined and there are no
@@ -1848,7 +2311,10 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY',
1848
2311
  return translation;
1849
2312
  };
1850
2313
  for (var i = 0, len = $fallbackLanguage.length; i < len; i++) {
1851
- langPromises[$fallbackLanguage[i]] = loadAsync($fallbackLanguage[i]).then(processAsyncResult);
2314
+ var fallbackLanguageId = $fallbackLanguage[i];
2315
+ if ($forceAsyncReloadEnabled || !$translationTable[fallbackLanguageId]) {
2316
+ langPromises[fallbackLanguageId] = loadAsync(fallbackLanguageId).then(processAsyncResult);
2317
+ }
1852
2318
  }
1853
2319
  }
1854
2320
  }
@@ -1856,7 +2322,10 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY',
1856
2322
  return $translate;
1857
2323
  }
1858
2324
  ];
1859
- }]);
2325
+ }
2326
+ $translate.$inject = ['$STORAGE_KEY', '$windowProvider', '$translateSanitizationProvider', 'pascalprechtTranslateOverrider'];
2327
+
2328
+ $translate.displayName = 'displayName';
1860
2329
 
1861
2330
  /**
1862
2331
  * @ngdoc object
@@ -1866,40 +2335,22 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY',
1866
2335
  * @description
1867
2336
  * Uses angular's `$interpolate` services to interpolate strings against some values.
1868
2337
  *
1869
- * @return {object} $translateInterpolator Interpolator service
2338
+ * Be aware to configure a proper sanitization strategy.
2339
+ *
2340
+ * See also:
2341
+ * * {@link pascalprecht.translate.$translateSanitization}
2342
+ *
2343
+ * @return {object} $translateDefaultInterpolation Interpolator service
1870
2344
  */
1871
- angular.module('pascalprecht.translate').factory('$translateDefaultInterpolation', ['$interpolate', function ($interpolate) {
2345
+ angular.module('pascalprecht.translate').factory('$translateDefaultInterpolation', $translateDefaultInterpolation);
2346
+
2347
+ function $translateDefaultInterpolation ($interpolate, $translateSanitization) {
2348
+
2349
+ 'use strict';
1872
2350
 
1873
2351
  var $translateInterpolator = {},
1874
2352
  $locale,
1875
- $identifier = 'default',
1876
- $sanitizeValueStrategy = null,
1877
- // map of all sanitize strategies
1878
- sanitizeValueStrategies = {
1879
- escaped: function (params) {
1880
- var result = {};
1881
- for (var key in params) {
1882
- if (Object.prototype.hasOwnProperty.call(params, key)) {
1883
- if (angular.isNumber(params[key])) {
1884
- result[key] = params[key];
1885
- } else {
1886
- result[key] = angular.element('<div></div>').text(params[key]).html();
1887
- }
1888
- }
1889
- }
1890
- return result;
1891
- }
1892
- };
1893
-
1894
- var sanitizeParams = function (params) {
1895
- var result;
1896
- if (angular.isFunction(sanitizeValueStrategies[$sanitizeValueStrategy])) {
1897
- result = sanitizeValueStrategies[$sanitizeValueStrategy](params);
1898
- } else {
1899
- result = params;
1900
- }
1901
- return result;
1902
- };
2353
+ $identifier = 'default';
1903
2354
 
1904
2355
  /**
1905
2356
  * @ngdoc function
@@ -1929,8 +2380,12 @@ angular.module('pascalprecht.translate').factory('$translateDefaultInterpolation
1929
2380
  return $identifier;
1930
2381
  };
1931
2382
 
2383
+ /**
2384
+ * @deprecated will be removed in 3.0
2385
+ * @see {@link pascalprecht.translate.$translateSanitization}
2386
+ */
1932
2387
  $translateInterpolator.useSanitizeValueStrategy = function (value) {
1933
- $sanitizeValueStrategy = value;
2388
+ $translateSanitization.useStrategy(value);
1934
2389
  return this;
1935
2390
  };
1936
2391
 
@@ -1945,15 +2400,21 @@ angular.module('pascalprecht.translate').factory('$translateDefaultInterpolation
1945
2400
  *
1946
2401
  * @returns {string} interpolated string.
1947
2402
  */
1948
- $translateInterpolator.interpolate = function (string, interpolateParams) {
1949
- if ($sanitizeValueStrategy) {
1950
- interpolateParams = sanitizeParams(interpolateParams);
1951
- }
1952
- return $interpolate(string)(interpolateParams || {});
2403
+ $translateInterpolator.interpolate = function (string, interpolationParams) {
2404
+ interpolationParams = interpolationParams || {};
2405
+ interpolationParams = $translateSanitization.sanitize(interpolationParams, 'params');
2406
+
2407
+ var interpolatedText = $interpolate(string)(interpolationParams);
2408
+ interpolatedText = $translateSanitization.sanitize(interpolatedText, 'text');
2409
+
2410
+ return interpolatedText;
1953
2411
  };
1954
2412
 
1955
2413
  return $translateInterpolator;
1956
- }]);
2414
+ }
2415
+ $translateDefaultInterpolation.$inject = ['$interpolate', '$translateSanitization'];
2416
+
2417
+ $translateDefaultInterpolation.displayName = '$translateDefaultInterpolation';
1957
2418
 
1958
2419
  angular.module('pascalprecht.translate').constant('$STORAGE_KEY', 'NG_TRANSLATE_LANG_KEY');
1959
2420
 
@@ -1975,7 +2436,7 @@ angular.module('pascalprecht.translate')
1975
2436
  * @param {string=} translate-values Values to pass into translation id. Can be passed as object literal string or interpolated object.
1976
2437
  * @param {string=} translate-attr-ATTR translate Translation id and put it into ATTR attribute.
1977
2438
  * @param {string=} translate-default will be used unless translation was successful
1978
- * @param {boolean=} translate-compile (default true if present) defines locally activation of {@link pascalprecht.translate.$translate#usePostCompiling}
2439
+ * @param {boolean=} translate-compile (default true if present) defines locally activation of {@link pascalprecht.translate.$translateProvider#methods_usePostCompiling}
1979
2440
  *
1980
2441
  * @example
1981
2442
  <example module="ngView">
@@ -2044,7 +2505,10 @@ angular.module('pascalprecht.translate')
2044
2505
  </file>
2045
2506
  </example>
2046
2507
  */
2047
- .directive('translate', ['$translate', '$q', '$interpolate', '$compile', '$parse', '$rootScope', function ($translate, $q, $interpolate, $compile, $parse, $rootScope) {
2508
+ .directive('translate', translateDirective);
2509
+ function translateDirective($translate, $q, $interpolate, $compile, $parse, $rootScope) {
2510
+
2511
+ 'use strict';
2048
2512
 
2049
2513
  /**
2050
2514
  * @name trim
@@ -2083,6 +2547,22 @@ angular.module('pascalprecht.translate')
2083
2547
  scope.postText = '';
2084
2548
  var translationIds = {};
2085
2549
 
2550
+ var initInterpolationParams = function (interpolateParams, iAttr, tAttr) {
2551
+ // initial setup
2552
+ if (iAttr.translateValues) {
2553
+ angular.extend(interpolateParams, $parse(iAttr.translateValues)(scope.$parent));
2554
+ }
2555
+ // initially fetch all attributes if existing and fill the params
2556
+ if (translateValueExist) {
2557
+ for (var attr in tAttr) {
2558
+ if (Object.prototype.hasOwnProperty.call(iAttr, attr) && attr.substr(0, 14) === 'translateValue' && attr !== 'translateValues') {
2559
+ var attributeName = angular.lowercase(attr.substr(14, 1)) + attr.substr(15);
2560
+ interpolateParams[attributeName] = tAttr[attr];
2561
+ }
2562
+ }
2563
+ }
2564
+ };
2565
+
2086
2566
  // Ensures any change of the attribute "translate" containing the id will
2087
2567
  // be re-stored to the scope's "translationId".
2088
2568
  // If the attribute has no content, the element's text value (white spaces trimmed off) will be used.
@@ -2125,6 +2605,9 @@ angular.module('pascalprecht.translate')
2125
2605
  });
2126
2606
  };
2127
2607
 
2608
+ // initial setup with values
2609
+ initInterpolationParams(scope.interpolateParams, iAttr, tAttr);
2610
+
2128
2611
  var firstAttributeChangedEvent = true;
2129
2612
  iAttr.$observe('translate', function (translationId) {
2130
2613
  if (typeof translationId === 'undefined') {
@@ -2177,7 +2660,8 @@ angular.module('pascalprecht.translate')
2177
2660
  // Master update function
2178
2661
  var updateTranslations = function () {
2179
2662
  for (var key in translationIds) {
2180
- if (translationIds.hasOwnProperty(key)) {
2663
+
2664
+ if (translationIds.hasOwnProperty(key) && translationIds[key] !== undefined) {
2181
2665
  updateTranslation(key, translationIds[key], scope, scope.interpolateParams, scope.defaultText);
2182
2666
  }
2183
2667
  }
@@ -2216,12 +2700,19 @@ angular.module('pascalprecht.translate')
2216
2700
  if (!successful && typeof scope.defaultText !== 'undefined') {
2217
2701
  value = scope.defaultText;
2218
2702
  }
2219
- var attributeName = iAttr.$attr[translateAttr].substr(15);
2703
+ var attributeName = iAttr.$attr[translateAttr];
2704
+ if (attributeName.substr(0, 5) === 'data-') {
2705
+ // ensure html5 data prefix is stripped
2706
+ attributeName = attributeName.substr(5);
2707
+ }
2708
+ attributeName = attributeName.substr(15);
2220
2709
  iElement.attr(attributeName, value);
2221
2710
  }
2222
2711
  };
2223
2712
 
2224
- scope.$watch('interpolateParams', updateTranslations, true);
2713
+ if (translateValuesExist || translateValueExist || iAttr.translateDefault) {
2714
+ scope.$watch('interpolateParams', updateTranslations, true);
2715
+ }
2225
2716
 
2226
2717
  // Ensures the text will be refreshed after the current language was changed
2227
2718
  // w/ $translate.use(...)
@@ -2229,14 +2720,24 @@ angular.module('pascalprecht.translate')
2229
2720
 
2230
2721
  // ensure translation will be looked up at least one
2231
2722
  if (iElement.text().length) {
2232
- observeElementTranslation('');
2723
+ if (iAttr.translate) {
2724
+ observeElementTranslation(iAttr.translate);
2725
+ } else {
2726
+ observeElementTranslation('');
2727
+ }
2728
+ } else if (iAttr.translate) {
2729
+ // ensure attribute will be not skipped
2730
+ observeElementTranslation(iAttr.translate);
2233
2731
  }
2234
2732
  updateTranslations();
2235
2733
  scope.$on('$destroy', unbind);
2236
2734
  };
2237
2735
  }
2238
2736
  };
2239
- }]);
2737
+ }
2738
+ translateDirective.$inject = ['$translate', '$q', '$interpolate', '$compile', '$parse', '$rootScope'];
2739
+
2740
+ translateDirective.displayName = 'translateDirective';
2240
2741
 
2241
2742
  angular.module('pascalprecht.translate')
2242
2743
  /**
@@ -2260,7 +2761,11 @@ angular.module('pascalprecht.translate')
2260
2761
  * or hiding the cloak. Basically it relies on the translation
2261
2762
  * resolve.
2262
2763
  */
2263
- .directive('translateCloak', ['$rootScope', '$translate', function ($rootScope, $translate) {
2764
+ .directive('translateCloak', translateCloakDirective);
2765
+
2766
+ function translateCloakDirective($rootScope, $translate) {
2767
+
2768
+ 'use strict';
2264
2769
 
2265
2770
  return {
2266
2771
  compile: function (tElement) {
@@ -2287,7 +2792,10 @@ angular.module('pascalprecht.translate')
2287
2792
  };
2288
2793
  }
2289
2794
  };
2290
- }]);
2795
+ }
2796
+ translateCloakDirective.$inject = ['$rootScope', '$translate'];
2797
+
2798
+ translateCloakDirective.displayName = 'translateCloakDirective';
2291
2799
 
2292
2800
  angular.module('pascalprecht.translate')
2293
2801
  /**
@@ -2341,7 +2849,12 @@ angular.module('pascalprecht.translate')
2341
2849
  </file>
2342
2850
  </example>
2343
2851
  */
2344
- .filter('translate', ['$parse', '$translate', function ($parse, $translate) {
2852
+ .filter('translate', translateFilterFactory);
2853
+
2854
+ function translateFilterFactory($parse, $translate) {
2855
+
2856
+ 'use strict';
2857
+
2345
2858
  var translateFilter = function (translationId, interpolateParams, interpolation) {
2346
2859
 
2347
2860
  if (!angular.isObject(interpolateParams)) {
@@ -2351,9 +2864,41 @@ angular.module('pascalprecht.translate')
2351
2864
  return $translate.instant(translationId, interpolateParams, interpolation);
2352
2865
  };
2353
2866
 
2354
- // Since AngularJS 1.3, filters which are not stateless (depending at the scope)
2355
- // have to explicit define this behavior.
2356
- translateFilter.$stateful = true;
2867
+ if ($translate.statefulFilter()) {
2868
+ translateFilter.$stateful = true;
2869
+ }
2357
2870
 
2358
2871
  return translateFilter;
2359
- }]);
2872
+ }
2873
+ translateFilterFactory.$inject = ['$parse', '$translate'];
2874
+
2875
+ translateFilterFactory.displayName = 'translateFilterFactory';
2876
+
2877
+ angular.module('pascalprecht.translate')
2878
+
2879
+ /**
2880
+ * @ngdoc object
2881
+ * @name pascalprecht.translate.$translationCache
2882
+ * @requires $cacheFactory
2883
+ *
2884
+ * @description
2885
+ * The first time a translation table is used, it is loaded in the translation cache for quick retrieval. You
2886
+ * can load translation tables directly into the cache by consuming the
2887
+ * `$translationCache` service directly.
2888
+ *
2889
+ * @return {object} $cacheFactory object.
2890
+ */
2891
+ .factory('$translationCache', $translationCache);
2892
+
2893
+ function $translationCache($cacheFactory) {
2894
+
2895
+ 'use strict';
2896
+
2897
+ return $cacheFactory('translations');
2898
+ }
2899
+ $translationCache.$inject = ['$cacheFactory'];
2900
+
2901
+ $translationCache.displayName = '$translationCache';
2902
+ return 'pascalprecht.translate';
2903
+
2904
+ }));
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: angular-translate-rails-tf
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.3
4
+ version: 2.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kanwaldeep Singh Arneja
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-10-12 00:00:00.000000000 Z
12
+ date: 2017-10-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties