-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathfilter.js
More file actions
56 lines (48 loc) · 1.92 KB
/
filter.js
File metadata and controls
56 lines (48 loc) · 1.92 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
(function () {
var translate = function (gettextCatalog, $gettext) {
var message = gettextCatalog.getPlural($gettext.n, $gettext.msgid, $gettext.plural, null, $gettext.context);
if ($gettext.n || $gettext.n === 0) {
// replace $count with n, preserving leading whitespace
return message.replace(/(^|\s)\$count\b/g, '$1' + $gettext.n);
} else {
return message;
}
};
angular.module('gettext').filter('translate', function (gettextCatalog) {
function filter(msgid) {
var $gettext = msgid.$gettext || { msgid: msgid };
// translate is the only filter that returns a string primitive
return translate(gettextCatalog, $gettext);
}
filter.$stateful = true;
return filter;
});
angular.module('gettext').filter('translatePlural', function (gettextCatalog) {
function filter(msgid, n, plural) {
var $gettext = msgid.$gettext || { msgid: msgid };
$gettext.n = n;
$gettext.plural = plural;
/*jshint -W053 */
// might as well return the correct String, even if it is a wrapper type
var message = new String(translate(gettextCatalog, $gettext));
/*jshint +W053 */
message.$gettext = $gettext;
return message;
}
filter.$stateful = true;
return filter;
});
angular.module('gettext').filter('translateContext', function (gettextCatalog) {
function filter(msgid, context) {
var $gettext = msgid.$gettext || { msgid: msgid };
$gettext.context = context;
/*jshint -W053 */
var message = new String(translate(gettextCatalog, $gettext));
/*jshint +W053 */
message.$gettext = $gettext;
return message;
}
filter.$stateful = true;
return filter;
});
})();