|
15 | 15 |
|
16 | 16 |
|
17 | 17 | class MockContext(unittest.TestCase):
|
18 |
| - # Static categories corresponding to en-US. |
| 18 | + maxDiff = None |
| 19 | + # Plural categories corresponding to English (en-US). |
19 | 20 | plural_categories = ('one', 'other')
|
20 | 21 |
|
21 | 22 | def get_source(self, path, key):
|
@@ -142,5 +143,81 @@ def test_plural_replace(self):
|
142 | 143 | )
|
143 | 144 |
|
144 | 145 |
|
| 146 | +@unittest.skipUnless(PropertiesParser, 'compare-locales required') |
| 147 | +class TestOneCategory(MockContext): |
| 148 | + # Plural categories corresponding to Turkish (tr). |
| 149 | + plural_categories = ('other',) |
| 150 | + |
| 151 | + def setUp(self): |
| 152 | + self.strings = parse(PropertiesParser, ''' |
| 153 | + deleteAll=#1 indirme silinsin mi? |
| 154 | + ''') |
| 155 | + |
| 156 | + self.message = FTL.Message( |
| 157 | + FTL.Identifier('delete-all'), |
| 158 | + value=PLURALS( |
| 159 | + 'test.properties', |
| 160 | + 'deleteAll', |
| 161 | + EXTERNAL_ARGUMENT('num'), |
| 162 | + lambda text: REPLACE_IN_TEXT( |
| 163 | + text, |
| 164 | + { |
| 165 | + '#1': EXTERNAL_ARGUMENT('num') |
| 166 | + } |
| 167 | + ) |
| 168 | + ) |
| 169 | + ) |
| 170 | + |
| 171 | + def test_no_select_expression(self): |
| 172 | + self.assertEqual( |
| 173 | + evaluate(self, self.message).to_json(), |
| 174 | + ftl_message_to_json(''' |
| 175 | + delete-all = { $num } indirme silinsin mi? |
| 176 | + ''') |
| 177 | + ) |
| 178 | + |
| 179 | + |
| 180 | +@unittest.skipUnless(PropertiesParser, 'compare-locales required') |
| 181 | +class TestManyCategories(MockContext): |
| 182 | + # Plural categories corresponding to Polish (pl). |
| 183 | + plural_categories = ('one', 'few', 'many', 'other') |
| 184 | + |
| 185 | + def setUp(self): |
| 186 | + self.strings = parse(PropertiesParser, ''' |
| 187 | + deleteAll=Usunąć plik?;Usunąć #1 pliki?;Usunąć #1 plików? |
| 188 | + ''') |
| 189 | + |
| 190 | + self.message = FTL.Message( |
| 191 | + FTL.Identifier('delete-all'), |
| 192 | + value=PLURALS( |
| 193 | + 'test.properties', |
| 194 | + 'deleteAll', |
| 195 | + EXTERNAL_ARGUMENT('num'), |
| 196 | + lambda text: REPLACE_IN_TEXT( |
| 197 | + text, |
| 198 | + { |
| 199 | + '#1': EXTERNAL_ARGUMENT('num') |
| 200 | + } |
| 201 | + ) |
| 202 | + ) |
| 203 | + ) |
| 204 | + |
| 205 | + def test_too_few_variants(self): |
| 206 | + # StringBundle's plural rule #9 used for Polish has three categories |
| 207 | + # which is one fewer than the CLDR's. The migrated string will not have |
| 208 | + # the [other] variant and [many] will be marked as the default. |
| 209 | + self.assertEqual( |
| 210 | + evaluate(self, self.message).to_json(), |
| 211 | + ftl_message_to_json(''' |
| 212 | + delete-all = |
| 213 | + { $num -> |
| 214 | + [one] Usunąć plik? |
| 215 | + [few] Usunąć { $num } pliki? |
| 216 | + *[many] Usunąć { $num } plików? |
| 217 | + } |
| 218 | + ''') |
| 219 | + ) |
| 220 | + |
| 221 | + |
145 | 222 | if __name__ == '__main__':
|
146 | 223 | unittest.main()
|
0 commit comments