-
Notifications
You must be signed in to change notification settings - Fork 600
/
Copy pathformatter-runtime-bind.js
46 lines (35 loc) · 1.11 KB
/
formatter-runtime-bind.js
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
define(function() {
return function( cldr, messageformatter ) {
var locale = cldr.locale,
origToString = messageformatter.toString;
messageformatter.toString = function() {
var argNames, argValues, output,
args = {};
// Properly adjust SlexAxton/messageformat.js compiled variables with Globalize variables:
output = origToString.call( messageformatter );
if ( /number\(/.test( output ) ) {
args.number = "messageFormat.number";
}
if ( /plural\(/.test( output ) ) {
args.plural = "messageFormat.plural";
}
if ( /select\(/.test( output ) ) {
args.select = "messageFormat.select";
}
output.replace( /pluralFuncs(\[([^\]]+)\]|\.([a-zA-Z]+))/, function( match ) {
args.pluralFuncs = "{" +
"\"" + locale + "\": Globalize(\"" + locale + "\").pluralGenerator()" +
"}";
return match;
});
argNames = Object.keys( args ).join( ", " );
argValues = Object.keys( args ).map(function( key ) {
return args[ key ];
}).join( ", " );
return "(function( " + argNames + " ) {\n" +
" return " + output + "\n" +
"})(" + argValues + ")";
};
return messageformatter;
};
});