forked from angular/angular.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessageFormatService.js
More file actions
68 lines (59 loc) · 2.47 KB
/
Copy pathmessageFormatService.js
File metadata and controls
68 lines (59 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
'use strict';
// NOTE: ADVANCED_OPTIMIZATIONS mode.
//
// This file is compiled with Closure compiler's ADVANCED_OPTIMIZATIONS flag! Be wary of using
// constructs incompatible with that mode.
/* global $interpolateMinErr: false */
/* global MessageFormatParser: false */
/* global stringify: false */
/**
* @ngdoc service
* @name $$messageFormat
*
* @description
* Angular internal service to recognize MessageFormat extensions in interpolation expressions.
* For more information, see:
* https://docs.google.com/a/google.com/document/d/1pbtW2yvtmFBikfRrJd8VAsabiFkKezmYZ_PbgdjQOVU/edit
*/
var $$MessageFormatFactory = ['$parse', '$locale', '$sce', '$exceptionHandler', function $$messageFormat(
$parse, $locale, $sce, $exceptionHandler) {
function getStringifier(trustedContext, allOrNothing, text) {
return function stringifier(value) {
try {
value = trustedContext ? $sce['getTrusted'](trustedContext, value) : $sce['valueOf'](value);
return allOrNothing && (value === void 0) ? value : stringify(value);
} catch (err) {
$exceptionHandler($interpolateMinErr['interr'](text, err));
}
};
}
function interpolate(text, mustHaveExpression, trustedContext, allOrNothing) {
var stringifier = getStringifier(trustedContext, allOrNothing, text);
var parser = new MessageFormatParser(text, 0, $parse, $locale['pluralCat'], stringifier,
mustHaveExpression, trustedContext, allOrNothing);
parser.run(parser.ruleInterpolate);
return parser.parsedFn;
}
return {
'interpolate': interpolate
};
}];
var $$interpolateDecorator = ['$$messageFormat', '$delegate', function $$interpolateDecorator($$messageFormat, $interpolate) {
if ($interpolate['startSymbol']() != "{{" || $interpolate['endSymbol']() != "}}") {
throw $interpolateMinErr('nochgmustache', 'angular-messageformat.js currently does not allow you to use custom start and end symbols for interpolation.');
}
var interpolate = $$messageFormat['interpolate'];
interpolate['startSymbol'] = $interpolate['startSymbol'];
interpolate['endSymbol'] = $interpolate['endSymbol'];
return interpolate;
}];
/**
* @ngdoc module
* @name ngMessageFormat
* @description
*/
var module = angular['module']('ngMessageFormat', ['ng']);
module['factory']('$$messageFormat', $$MessageFormatFactory);
module['config'](['$provide', function($provide) {
$provide['decorator']('$interpolate', $$interpolateDecorator);
}]);