@@ -12,7 +12,7 @@ describe("Filter", function () {
12
12
catalog . setStrings ( "nl" , {
13
13
Hello : "Hallo" ,
14
14
"Hello {{name}}!" : "Hallo {{name}}!" ,
15
- "One boat" : [ "Een boot" , "{{ count}} boten" ] ,
15
+ "One boat" : [ "Een boot" , "$ count boten" ] ,
16
16
Archive : { verb : "Archiveren" , noun : "Archief" , $$noContext : "Archief (no context)" }
17
17
} ) ;
18
18
} ) ) ;
@@ -30,23 +30,84 @@ describe("Filter", function () {
30
30
assert . equal ( el . text ( ) , "Hallo" ) ;
31
31
} ) ;
32
32
33
- it ( "Should translate known strings according to translate context" , function ( ) {
34
- catalog . setCurrentLanguage ( "nl" ) ;
35
- var el = $compile ( "<span>{{\"Archive\"|translate:'verb'}}</span>" ) ( $rootScope ) ;
36
- $rootScope . $digest ( ) ;
37
- assert . equal ( el . text ( ) , "Archiveren" ) ;
38
- el = $compile ( "<span>{{\"Archive\"|translate:'noun'}}</span>" ) ( $rootScope ) ;
39
- $rootScope . $digest ( ) ;
40
- assert . equal ( el . text ( ) , "Archief" ) ;
41
- el = $compile ( "<span>{{\"Archive\"|translate}}</span>" ) ( $rootScope ) ;
42
- $rootScope . $digest ( ) ;
43
- assert . equal ( el . text ( ) , "Archief (no context)" ) ;
44
- } ) ;
45
-
46
33
it ( "Can use filter in attribute values" , function ( ) {
47
34
catalog . setCurrentLanguage ( "nl" ) ;
48
35
var el = $compile ( "<input type=\"text\" placeholder=\"{{'Hello'|translate}}\" />" ) ( $rootScope ) ;
49
36
$rootScope . $digest ( ) ;
50
37
assert . equal ( el . attr ( "placeholder" ) , "Hallo" ) ;
51
38
} ) ;
39
+
40
+ describe ( "translatePlural" , function ( ) {
41
+
42
+ // not sure why you'd want to do this, but it's a good test case
43
+ it ( "Should work if n is a number" , function ( ) {
44
+ catalog . setCurrentLanguage ( "nl" ) ;
45
+ var el = $compile ( "<span>{{'One boat' | translatePlural:2:'$count boten' | translate}}</span>" ) ( $rootScope ) ;
46
+ $rootScope . $digest ( ) ;
47
+ assert . equal ( el . text ( ) , "2 boten" ) ;
48
+ } ) ;
49
+
50
+ it ( "Should work if n is a reference" , function ( ) {
51
+ catalog . setCurrentLanguage ( "nl" ) ;
52
+ var scope = $rootScope . $new ( ) ;
53
+ scope . count = 2 ;
54
+ var el = $compile ( "<span>{{'One boat' | translatePlural:count:'$count boten' | translate}}</span>" ) ( scope ) ;
55
+ $rootScope . $digest ( ) ;
56
+ assert . equal ( el . text ( ) , "2 boten" ) ;
57
+
58
+ scope . count = 1 ;
59
+ el = $compile ( "<span>{{'One boat' | translatePlural:count:'$count boten' | translate}}</span>" ) ( scope ) ;
60
+ $rootScope . $digest ( ) ;
61
+ assert . equal ( el . text ( ) , "Een boot" ) ;
62
+ } ) ;
63
+
64
+ it ( "Should work if it precedes translateContext" , function ( ) {
65
+ catalog . setCurrentLanguage ( "nl" ) ;
66
+ catalog . setStrings ( "nl" , {
67
+ "One boat" : { c1 : [ "Een boot1" , "$count boten1" ] , c2 : [ "Een boot" , "$count boten" ] }
68
+ } ) ;
69
+
70
+ var scope = $rootScope . $new ( ) ;
71
+ scope . count = 2 ;
72
+ var el = $compile ( "<span>{{'One boat' | translatePlural:count:'$count boten' | translateContext:'c2' | translate}}</span>" ) ( scope ) ;
73
+ $rootScope . $digest ( ) ;
74
+ assert . equal ( el . text ( ) , "2 boten" ) ;
75
+ } ) ;
76
+ } ) ;
77
+
78
+ describe ( "translateContext" , function ( ) {
79
+ it ( "Should translate known strings according to translateContext" , function ( ) {
80
+ catalog . setCurrentLanguage ( "nl" ) ;
81
+ var el = $compile ( "<span>{{'Archive' | translateContext:'verb' | translate}}</span>" ) ( $rootScope ) ;
82
+ $rootScope . $digest ( ) ;
83
+ assert . equal ( el . text ( ) , "Archiveren" ) ;
84
+ el = $compile ( "<span>{{'Archive' | translateContext:'noun' | translate}}</span>" ) ( $rootScope ) ;
85
+ $rootScope . $digest ( ) ;
86
+ assert . equal ( el . text ( ) , "Archief" ) ;
87
+ } ) ;
88
+
89
+ it ( "Should work with no args" , function ( ) {
90
+ // translateContext with no args is the same as translate
91
+ catalog . setCurrentLanguage ( "nl" ) ;
92
+ var el = $compile ( "<span>{{'Archive' | translateContext | translate}}</span>" ) ( $rootScope ) ;
93
+ $rootScope . $digest ( ) ;
94
+ assert . equal ( el . text ( ) , "Archief (no context)" ) ;
95
+ el = $compile ( "<span>{{'Archive' | translate }}</span>" ) ( $rootScope ) ;
96
+ $rootScope . $digest ( ) ;
97
+ assert . equal ( el . text ( ) , "Archief (no context)" ) ;
98
+ } ) ;
99
+
100
+ it ( "Should work if it precedes translatePlural" , function ( ) {
101
+ catalog . setCurrentLanguage ( "nl" ) ;
102
+ catalog . setStrings ( "nl" , {
103
+ "One boat" : { c1 : [ "Een boot1" , "$count boten1" ] , c2 : [ "Een boot" , "$count boten" ] }
104
+ } ) ;
105
+
106
+ var scope = $rootScope . $new ( ) ;
107
+ scope . count = 2 ;
108
+ var el = $compile ( "<span>{{'One boat' | translateContext:'c2' | translatePlural:count:'$count boten' | translate}}</span>" ) ( scope ) ;
109
+ $rootScope . $digest ( ) ;
110
+ assert . equal ( el . text ( ) , "2 boten" ) ;
111
+ } ) ;
112
+ } ) ;
52
113
} ) ;
0 commit comments