예제 #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,
     )
예제 #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,
     )
예제 #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,
     )
예제 #4
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,
     )