Esempio n. 1
0
 def test_compile_with_custom_delimiter(self):
     """Make sure that serialization with a custom delimiter
     works as expected."""
     openstring = OpenString('key', {1: u'χαλί', 5: u'χαλιά'}, pluralized=True)
     string = ICUCompiler().serialize_strings(openstring.string, '\n')
     self.assertEqual(
         u'one {χαλί}\nother {χαλιά}',
         string,
     )
Esempio n. 2
0
 def test_with_different_target_plurals(self):
     icu_string = ICUParser().parse(
         'doesntmatter',
         u'{count, plural, one {ac76ac7a27_pl_0} other {ac76ac7a27_pl_2}}'
     )
     serialized = ICUCompiler().serialize_placeholder_string(
         icu_string,
         [2, 5]
     )
     self.assertEqual(
         u'two {s}_0} other {s}_1}'.replace(
             u'{s}', u'{ac76ac7a27_pl',
         ),
         serialized,
     )
Esempio n. 3
0
 def test_with_more_target_plurals(self):
     icu_string = ICUParser().parse(
         'doesntmatter',
         u'{count, plural, one {ac76ac7a27_pl_0} other {ac76ac7a27_pl_1}}'
     )
     serialized = ICUCompiler().serialize_placeholder_string(
         icu_string,
         [1, 2, 3, 4, 5]
     )
     self.assertEqual(
         u'one {s}_0} two {s}_1} few {s}_2} many {s}_3} other {s}_4}'.replace(
             u'{s}', u'{ac76ac7a27_pl',
         ),
         serialized,
     )
Esempio n. 4
0
 def test_with_less_target_languages(self):
     icu_string = ICUParser().parse(
         'doesntmatter',
         u'{count, plural, one {ac76ac7a27_pl_0} other {ac76ac7a27_pl_1}}'
     )
     placeholders = ICUCompiler._create_placeholders_by_rule(
         icu_string,
         [5]
     )
     self.assertDictEqual(
         {
             5: u'ac76ac7a27_pl_0',
         },
         placeholders,
     )
Esempio n. 5
0
 def test_with_more_target_languages(self):
     icu_string = ICUParser().parse(
         'doesntmatter',
         u'{count, plural, one {ac76ac7a27_pl_0} other {ac76ac7a27_pl_1}}'
     )
     placeholders = ICUCompiler._create_placeholders_by_rule(
         icu_string,
         [1, 2, 3, 4, 5]
     )
     self.assertDictEqual(
         {
             1: u'ac76ac7a27_pl_0',
             2: u'ac76ac7a27_pl_1',
             3: u'ac76ac7a27_pl_2',
             4: u'ac76ac7a27_pl_3',
             5: u'ac76ac7a27_pl_4',
         },
         placeholders,
     )
Esempio n. 6
0
 def test_compile_with_custom_syntax_per_rule(self):
     """Make sure that serialization with a custom syntax
     works as expected."""
     openstring = OpenString(
         'key', {1: u'χαλί', 2: u'δύο χαλιά', 3: u'λίγα χαλιά', 5: u'χαλιά'},
         pluralized=True,
     )
     string = ICUCompiler().serialize_strings(
         openstring.string,
         syntax_by_rule={
             1: PLURAL_FORMAT_NUMERIC,
             2: PLURAL_FORMAT_NUMERIC,
             3: PLURAL_FORMAT_STRING,
             # omit the last one on purpose, should be rendered as string
         },
     )
     self.assertEqual(
         u'=1 {χαλί} =2 {δύο χαλιά} few {λίγα χαλιά} other {χαλιά}',
         string,
     )