-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathfilter.js
More file actions
91 lines (76 loc) · 2.96 KB
/
filter.js
File metadata and controls
91 lines (76 loc) · 2.96 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
describe("Filter", function () {
var catalog = null;
var $rootScope = null;
var $compile = null;
beforeEach(module("gettext"));
beforeEach(inject(function ($injector, gettextCatalog) {
$rootScope = $injector.get("$rootScope");
$compile = $injector.get("$compile");
catalog = gettextCatalog;
catalog.setStrings("nl", {
Hello: "Hallo",
"Hello {{name}}!": "Hallo {{name}}!",
"One boat": ["Een boot", "{{count}} boten"]
});
}));
it("Should have a translate filter", function () {
var el = $compile("<h1>{{\"Hello!\"|translate}}</h1>")($rootScope);
$rootScope.$digest();
assert.equal(el.text(), "Hello!");
});
it("Should translate known strings", function () {
catalog.currentLanguage = "nl";
var el = $compile("<span>{{\"Hello\"|translate}}</span>")($rootScope);
$rootScope.$digest();
assert.equal(el.text(), "Hallo");
});
it("Can use filter in attribute values", function () {
catalog.currentLanguage = "nl";
var el = $compile("<input type=\"text\" placeholder=\"{{'Hello'|translate}}\" />")($rootScope);
$rootScope.$digest();
assert.equal(el.attr("placeholder"), "Hallo");
});
});
describe("Filter: translatePlural", function () {
var catalog = null;
var $rootScope = null;
var $compile = null;
beforeEach(module("gettext"));
beforeEach(inject(function ($injector, gettextCatalog) {
$rootScope = $injector.get("$rootScope");
$compile = $injector.get("$compile");
catalog = gettextCatalog;
catalog.setStrings("nl", {
Hello: "Hallo",
"Hello {{name}}!": "Hallo {{name}}!",
"One boat": ["Een boot", "{} boten"]
});
$rootScope.n = 1;
}));
it("Should have a translatePlural filter", function () {
var el = $compile("<h1>{{\"One boat\"|translatePlural:n:\"{} boats\"}}</h1>")($rootScope);
$rootScope.$digest();
assert.equal(el.text(), "One boat");
$rootScope.n = 2;
$rootScope.$digest();
assert.equal(el.text(), "2 boats");
});
it("Should translate known strings", function () {
catalog.currentLanguage = "nl";
var el = $compile("<span>{{\"One boat\"|translatePlural:n:\"{} boten\"}}</span>")($rootScope);
$rootScope.$digest();
assert.equal(el.text(), "Een boot");
$rootScope.n = 2;
$rootScope.$digest();
assert.equal(el.text(), "2 boten");
});
it("Can use filter in attribute values", function () {
catalog.currentLanguage = "nl";
var el = $compile("<input type=\"text\" placeholder=\"{{'One boat'|translatePlural:n:'{} boten'}}\" />")($rootScope);
$rootScope.$digest();
assert.equal(el.attr("placeholder"), "Een boot");
$rootScope.n = 2;
$rootScope.$digest();
assert.equal(el.attr("placeholder"), "2 boten");
});
});