Пример #1
0
    def test_duplicated_text_is_not_confused(self):
        string1 = self._create_openstring(False)
        source = strip_leading_spaces(u"""
            msgctxt ""
            msgid "{s1_key}"
            msgstr "{s1_key}"

            msgctxt "t2"
            msgid "{s1_key}"
            msgstr "{s1_key}"
        """.format(**{
            "s1_key": string1.key,
        }))
        template, stringset = self.handler.parse(source)
        compiled = self.handler.compile(template, [string1])
        self.assertEqual(
            compiled,
            strip_leading_spaces(u"""# \nmsgid ""
                msgstr ""

                msgctxt ""
                msgid "{s1_key}"
                msgstr "{s1_str}"
            """.format(**{
                "s1_key": string1.key,
                "s1_str": string1.string
            }))
        )
Пример #2
0
    def test_missing_translated_plurals_removed(self):
        random_key = generate_random_string()
        random_singular = generate_random_string()
        random_plural = generate_random_string()
        source = strip_leading_spaces(u'''
            <resources>
                <plurals name="{key}">
                    <item quantity="one">{singular}</item>
                    <item quantity="other">{plural}</item>
                </plurals>
            </resources>
        '''.format(key=random_key,
                   singular=random_singular,
                   plural=random_plural))

        template, stringset = self.handler.parse(source)
        compiled = self.handler.compile(template, [])
        self.assertEqual(
            compiled,
            strip_leading_spaces(u'''
            <resources>

            </resources>
        '''.format(key=random_key,
                   singular=random_singular,
                   plural=random_plural)))
Пример #3
0
    def test_plurals(self):
        random_key = generate_random_string()
        random_singular = generate_random_string()
        random_plural = generate_random_string()
        random_openstring = OpenString(random_key,
                                       {1: random_singular, 5: random_plural},
                                       order=0)
        random_hash = random_openstring.template_replacement

        source = strip_leading_spaces(u"""
            <resources>
                <plurals name="{key}">
                    <item quantity="one">{singular}</item>
                    <item quantity="other">{plural}</item>
                </plurals>
            </resources>
        """.format(key=random_key, singular=random_singular,
                   plural=random_plural))

        template, stringset = self.handler.parse(source)
        compiled = self.handler.compile(template, [random_openstring])

        self.assertEqual(
            template,
            strip_leading_spaces(u'''
                <resources>
                    <plurals name="{key}">
                        {hash_}
                    </plurals>
                </resources>
            '''.format(key=random_key, hash_=random_hash))
        )
        self.assertEqual(len(stringset), 1)
        self.assertEqual(stringset[0].__dict__, random_openstring.__dict__)
        self.assertEqual(compiled, source)
Пример #4
0
    def test_missing_translated_string_array_items_removed(self):
        random_key = generate_random_string()
        random_string1 = generate_random_string()
        random_string2 = generate_random_string()
        source = strip_leading_spaces(u'''
            <resources>
                <string-array name="{key}">
                    <item>{string1}</item>
                    <item>{string2}</item>
                </string-array>
            </resources>
        '''.format(key=random_key,
                   string1=random_string1,
                   string2=random_string2))

        template, stringset = self.handler.parse(source)
        compiled = self.handler.compile(template, [stringset[0]])
        self.assertEqual(
            compiled,
            strip_leading_spaces(u'''
            <resources>
                <string-array name="{key}">
                    <item>{string1}</item>

                </string-array>
            </resources>
        '''.format(key=random_key, string1=random_string1)))
Пример #5
0
    def test_not_source_removes_untranslated_on_upload(self):
        string1 = self._create_openstring(False)
        source = strip_leading_spaces(
            u"""
            #

            msgid ""
            msgstr ""

            msgid "{s1_key}"
            msgstr "{s1_str}"

            msgid "a_random_key"
            msgstr " "
        """.format(**{
                's1_key': string1.key,
                's1_str': string1.string
            }))
        template, stringset = self.handler.parse(source)
        compiled = self.handler.compile(template, [string1])
        self.assertEqual(
            compiled,
            strip_leading_spaces(
                u"""# \nmsgid ""
                msgstr ""

                msgid "{s1_key}"
                msgstr "{s1_str}"
                """.format(**{
                    's1_key': string1.key,
                    's1_str': string1.string
                })))
Пример #6
0
    def test_duplicated_text_is_not_confused(self):
        string1 = self._create_openstring(False)
        source = strip_leading_spaces(u"""
            msgctxt ""
            msgid "{s1_key}"
            msgstr "{s1_key}"

            msgctxt "t2"
            msgid "{s1_key}"
            msgstr "{s1_key}"
        """.format(**{
            "s1_key": string1.key,
        }))
        template, stringset = self.handler.parse(source)
        compiled = self.handler.compile(template, [string1])
        self.assertEqual(
            compiled,
            strip_leading_spaces(
                u"""# \nmsgid ""
                msgstr ""

                msgctxt ""
                msgid "{s1_key}"
                msgstr "{s1_str}"
            """.format(**{
                    "s1_key": string1.key,
                    "s1_str": string1.string
                })))
Пример #7
0
    def test_not_source_removes_untranslated_on_upload(self):
        string1 = self._create_openstring(False)
        source = strip_leading_spaces(u"""
            #

            msgid ""
            msgstr ""

            msgid "{s1_key}"
            msgstr "{s1_str}"

            msgid "a_random_key"
            msgstr " "
        """.format(**{
            's1_key': string1.key,
            's1_str': string1.string
        }))
        template, stringset = self.handler.parse(source)
        compiled = self.handler.compile(template, [string1])
        self.assertEqual(
            compiled,
            strip_leading_spaces(
                u"""# \nmsgid ""
                msgstr ""

                msgid "{s1_key}"
                msgstr "{s1_str}"
                """.format(**{
                    's1_key': string1.key,
                    's1_str': string1.string
                }))
        )
Пример #8
0
 def test_compile_doesnt_remove_already_empty_plurals(self):
     source = strip_leading_spaces('''
         <resources>
             <plurals name="a">
                 <item quantity="one">hello</item>
                 <item quantity="other">world</item>
             </plurals>
             <plurals name="b">
                 <item quantity="one"></item>
                 <item quantity="other"></item>
             </plurals>
         </resources>
     ''')
     template, stringset = self.handler.parse(source)
     compiled = self.handler.compile(template, [])
     self.assertEqual(
         compiled,
         strip_leading_spaces('''
             <resources>
                 <plurals name="b">
                     <item quantity="one"></item>
                     <item quantity="other"></item>
                 </plurals>
             </resources>
         ''')
     )
Пример #9
0
    def test_plurals(self):
        random_key = generate_random_string()
        random_singular = generate_random_string()
        random_plural = generate_random_string()
        random_openstring = OpenString(random_key,
                                       {1: random_singular, 5: random_plural},
                                       order=0)
        random_hash = random_openstring.template_replacement

        source = strip_leading_spaces(u"""
            <resources>
                <plurals name="{key}">
                    <item quantity="one">{singular}</item>
                    <item quantity="other">{plural}</item>
                </plurals>
            </resources>
        """.format(key=random_key, singular=random_singular,
                   plural=random_plural))

        template, stringset = self.handler.parse(source)
        compiled = self.handler.compile(template, [random_openstring])

        self.assertEqual(
            template,
            strip_leading_spaces(u'''
                <resources>
                    <plurals name="{key}">
                        {hash_}
                    </plurals>
                </resources>
            '''.format(key=random_key, hash_=random_hash))
        )
        self.assertEqual(len(stringset), 1)
        self.assertEqual(stringset[0].__dict__, random_openstring.__dict__)
        self.assertEqual(compiled, source)
Пример #10
0
    def test_compiled_includes_all_with_obsoleted_strings(self):
        """
        Test that the existence of obsoleted strings in the po file
        marked with #~ does not cause strings after the obsoleted ones
        to be missing from the compiled file.
        """
        string1 = self._create_openstring(False)
        string2 = self._create_openstring(False)
        string3 = self._create_openstring(False)
        source = strip_leading_spaces(u"""
            msgid ""
            msgstr ""
            
            msgid "{s1_key}"
            msgstr "{s1_str}"
            
            #~ msgid "{s2_key}"
            #~ msgstr "{s2_str}"
            
            msgid "{s3_key}"
            msgstr "{s3_str}"
        """.format(
            **{
                's1_key': string1.key,
                's1_str': string1.string,
                's2_key': string2.key,
                's2_str': string2.string,
                's3_key': string3.key,
                's3_str': string3.string
            }))
        template, stringset = self.handler.parse(source)
        compiled = self.handler.compile(template, [string1, string2, string3])

        self.assertEqual(
            compiled,
            strip_leading_spaces(u"""# \nmsgid ""
                msgstr ""
                
                msgid "{s1_key}"
                msgstr "{s1_str}"
                
                #~ msgid "{s2_key}"
                #~ msgstr "{s2_str}"
                
                msgid "{s3_key}"
                msgstr "{s3_str}"
                """.format(
                **{
                    's1_key': string1.key,
                    's1_str': string1.string,
                    's2_key': string2.key,
                    's2_str': string2.string,
                    's3_key': string3.key,
                    's3_str': string3.string
                })))
Пример #11
0
 def test_string(self):
     context_dict, openstring = self._create_pluralized_string()
     source = strip_leading_spaces(u"""
         <plist>
         <dict>
             <key>{main_key}</key>
             <dict>
                 <key>NSStringLocalizedFormatKey</key>
                 <string>%1$#@a_var@</string>
                 <key>{secondary_key}</key>
                 <dict>
                     <key>NSStringFormatSpecTypeKey</key>
                     <string>NSStringPluralRuleType</string>
                     <key>NSStringFormatValueTypeKey</key>
                     <string>d</string>
                     <key>one</key>
                     <string>{singular}</string>
                     <key>other</key>
                     <string>{plural}</string>
                 </dict>
             </dict>
         </dict>
         </plist>
     """.format(**context_dict))
     template, stringset = self.handler.parse(source)
     compiled = self.handler.compile(template, [openstring])
     self.assertEqual(
         template,
         strip_leading_spaces(u'''
             <plist>
             <dict>
                 <key>{main_key}</key>
                 <dict>
                     <key>NSStringLocalizedFormatKey</key>
                     <string>%1$#@a_var@</string>
                     <key>{secondary_key}</key>
                     <dict>
                         <key>NSStringFormatSpecTypeKey</key>
                         <string>NSStringPluralRuleType</string>
                         <key>NSStringFormatValueTypeKey</key>
                         <string>d</string>
                         <tx_awesome_key_tag></tx_awesome_key_tag>
                         <tx_awesome_string_tag>{hash}</tx_awesome_string_tag>
                     </dict>
                 </dict>
             </dict>
             </plist>
         '''.format(**context_dict)
         )
     )
     self.assertEqual(len(stringset), 1)
     self.assertEqual(stringset[0].__dict__, openstring.__dict__)
     self.assertEqual(compiled, source)
Пример #12
0
 def test_string(self):
     context_dict, openstring = self._create_pluralized_string()
     source = strip_leading_spaces(u"""
         <plist>
         <dict>
             <key>{main_key}</key>
             <dict>
                 <key>NSStringLocalizedFormatKey</key>
                 <string>%1$#@a_var@</string>
                 <key>{secondary_key}</key>
                 <dict>
                     <key>NSStringFormatSpecTypeKey</key>
                     <string>NSStringPluralRuleType</string>
                     <key>NSStringFormatValueTypeKey</key>
                     <string>d</string>
                     <key>one</key>
                     <string>{singular}</string>
                     <key>other</key>
                     <string>{plural}</string>
                 </dict>
             </dict>
         </dict>
         </plist>
     """.format(**context_dict))
     template, stringset = self.handler.parse(source)
     compiled = self.handler.compile(template, [openstring])
     self.assertEqual(
         template,
         strip_leading_spaces(u'''
             <plist>
             <dict>
                 <key>{main_key}</key>
                 <dict>
                     <key>NSStringLocalizedFormatKey</key>
                     <string>%1$#@a_var@</string>
                     <key>{secondary_key}</key>
                     <dict>
                         <key>NSStringFormatSpecTypeKey</key>
                         <string>NSStringPluralRuleType</string>
                         <key>NSStringFormatValueTypeKey</key>
                         <string>d</string>
                         <tx_awesome_key_tag></tx_awesome_key_tag>
                         <tx_awesome_string_tag>{hash}</tx_awesome_string_tag>
                     </dict>
                 </dict>
             </dict>
             </plist>
         '''.format(**context_dict)))
     self.assertEqual(len(stringset), 1)
     self.assertEqual(stringset[0].__dict__, openstring.__dict__)
     self.assertEqual(compiled, source)
Пример #13
0
    def test_missing_translated_strings_removed(self):
        random_key = generate_random_string()
        random_string = generate_random_string()
        source = strip_leading_spaces(u'''
            <resources>
                <string name="{key}">{string}</string>
            </resources>
        '''.format(key=random_key, string=random_string))

        template, stringset = self.handler.parse(source)
        compiled = self.handler.compile(template, [])
        self.assertEqual(compiled, strip_leading_spaces(u'''
            <resources>
                </resources>
        '''))
Пример #14
0
    def test_string_array(self):
        random_name = generate_random_string()
        random_key = '{}[0]'.format(random_name)
        random_string = generate_random_string()
        random_openstring = OpenString(random_key, random_string, order=0)
        random_hash = random_openstring.template_replacement
        source_python_template = strip_leading_spaces(u'''
            <resources>
                <string-array name="{key}">
                    <item>{string}</item>
                </string-array>
            </resources>
        ''')
        source = source_python_template.format(key=random_name,
                                               string=random_string)

        template, stringset = self.handler.parse(source)
        compiled = self.handler.compile(template, [random_openstring])

        self.assertEqual(
            template,
            source_python_template.format(key=random_name, string=random_hash)
        )
        self.assertEqual(len(stringset), 1)
        self.assertEqual(stringset[0].__dict__,
                          random_openstring.__dict__)
        self.assertEqual(compiled, source)
Пример #15
0
 def test_ignores_closed_string_placeholders(self):
     source = strip_leading_spaces(u"""
         <plist>
         <dict>
             <key>a_main_key</key>
             <dict>
                 <key>NSStringLocalizedFormatKey</key>
                 <string>%1$#@a_var@</string>
                 <key>a_secondary_key</key>
                 <dict>
                     <key>NSStringFormatSpecTypeKey</key>
                     <string>NSStringPluralRuleType</string>
                     <key>NSStringFormatValueTypeKey</key>
                     <string>d</string>
                     <key>one</key>
                     <string/>
                     <key>other</key>
                     <string/>
                 </dict>
             </dict>
         </dict>
         </plist>
     """)
     template, stringset = self.handler.parse(source)
     self.assertEqual(template, source)
     compiled = self.handler.compile(template, [])
     self.assertEqual(compiled, source)
Пример #16
0
    def test_string_array(self):
        random_name = generate_random_string()
        random_key = '{}[0]'.format(random_name)
        random_string = generate_random_string()
        random_openstring = OpenString(random_key, random_string, order=0)
        random_hash = random_openstring.template_replacement
        source_python_template = strip_leading_spaces(u'''
            <resources>
                <string-array name="{key}">
                    <item>{string}</item>
                </string-array>
            </resources>
        ''')
        source = source_python_template.format(key=random_name,
                                               string=random_string)

        template, stringset = self.handler.parse(source)
        compiled = self.handler.compile(template, [random_openstring])

        self.assertEqual(
            template,
            source_python_template.format(key=random_name, string=random_hash))
        self.assertEqual(len(stringset), 1)
        self.assertEqual(stringset[0].__dict__, random_openstring.__dict__)
        self.assertEqual(compiled, source)
Пример #17
0
 def test_ignores_closed_string_placeholders(self):
     source = strip_leading_spaces(u"""
         <plist>
         <dict>
             <key>a_main_key</key>
             <dict>
                 <key>NSStringLocalizedFormatKey</key>
                 <string>%1$#@a_var@</string>
                 <key>a_secondary_key</key>
                 <dict>
                     <key>NSStringFormatSpecTypeKey</key>
                     <string>NSStringPluralRuleType</string>
                     <key>NSStringFormatValueTypeKey</key>
                     <string>d</string>
                     <key>one</key>
                     <string/>
                     <key>other</key>
                     <string/>
                 </dict>
             </dict>
         </dict>
         </plist>
     """)
     template, stringset = self.handler.parse(source)
     self.assertEqual(template, source)
     compiled = self.handler.compile(template, [])
     self.assertEqual(compiled, source)
Пример #18
0
    def test_openstring_has_all_fields(self):
        source = strip_leading_spaces(u"""
            msgid ""
            msgstr ""
            "Content-Type: text/plain; charset=UTF-8\n"
            "Content-Transfer-Encoding: 8bit\n"
            "Language: en\n"
            "Plural-Forms: nplurals=2; plural=(n != 1);\n"

            #  translator-comments1
            #  translator-comments2
            #. extracted-comments1
            #. extracted-comments2
            #: validators.py:9
            #: validators.py:11
            #, python-format
            #, another-flag
            msgid "metest"
            msgstr "msgstr1"
        """)
        template, stringset = self.handler.parse(source)
        expected_comment = ('extracted-comments1\nextracted-comments2\n'
                            u' translator-comments1\n translator-comments2')
        self.assertEqual(len(stringset), 1)
        self.assertEqual(stringset[0].developer_comment, expected_comment)
        self.assertEqual(stringset[0].occurrences,
                         u'validators.py:9, validators.py:11')
        self.assertEqual(stringset[0].flags, u'python-format, another-flag')
Пример #19
0
    def test_removes_untranslated_non_pluralized(self):
        string1 = self._create_openstring(False)
        string2 = self._create_openstring(False)
        string3 = self._create_openstring(False)
        source = strip_leading_spaces(u"""
            #

            msgid ""
            msgstr ""

            msgid "{s1_key}"
            msgstr "{s1_str}"

            msgid "{s2_key}"
            msgstr "{s2_str}"

            msgid "{s3_key}"
            msgstr "{s3_str}"
        """.format(**{
            's1_key': string1.key,
            's1_str': string1.string,
            's2_key': string2.key,
            's2_str': string2.string,
            's3_key': string3.key,
            's3_str': string3.string
        }))
        template, stringset = self.handler.parse(source)
        compiled = self.handler.compile(template, [string1, string3])
        self.assertEqual(
            compiled,
            strip_leading_spaces(
                u"""# \nmsgid ""
                msgstr ""

                msgid "{s1_key}"
                msgstr "{s1_str}"

                msgid "{s3_key}"
                msgstr "{s3_str}"
                """.format(**{
                    's1_key': string1.key,
                    's1_str': string1.string,
                    's3_key': string3.key,
                    's3_str': string3.string
                }))
        )
Пример #20
0
    def test_removes_untranslated_non_pluralized(self):
        string1 = self._create_openstring(False)
        string2 = self._create_openstring(False)
        string3 = self._create_openstring(False)
        source = strip_leading_spaces(u"""
            #

            msgid ""
            msgstr ""

            msgid "{s1_key}"
            msgstr "{s1_str}"

            msgid "{s2_key}"
            msgstr "{s2_str}"

            msgid "{s3_key}"
            msgstr "{s3_str}"
        """.format(
            **{
                's1_key': string1.key,
                's1_str': string1.string,
                's2_key': string2.key,
                's2_str': string2.string,
                's3_key': string3.key,
                's3_str': string3.string
            }))
        template, stringset = self.handler.parse(source)
        compiled = self.handler.compile(template, [string1, string3])
        self.assertEqual(
            compiled,
            strip_leading_spaces(u"""# \nmsgid ""
                msgstr ""

                msgid "{s1_key}"
                msgstr "{s1_str}"

                msgid "{s3_key}"
                msgstr "{s3_str}"
                """.format(
                **{
                    's1_key': string1.key,
                    's1_str': string1.string,
                    's3_key': string3.key,
                    's3_str': string3.string
                })))
Пример #21
0
 def test_compile_removes_missing_strings(self):
     source = strip_leading_spaces('''
         <resources>
             <string name="a">hello</string>
             <string name="b">goodbye</string>
         </resources>
     ''')
     template, stringset = self.handler.parse(source)
     compiled = self.handler.compile(template, stringset[:1])
     self.assertEqual(
         compiled,
         strip_leading_spaces('''
             <resources>
                 <string name="a">hello</string>
             </resources>
         ''')
     )
Пример #22
0
 def test_compile_removes_missing_string_arrays(self):
     source = strip_leading_spaces('''
         <resources>
             <string-array name="a">
                 <item>hello</item>
                 <item>world</item>
             </string-array>
         </resources>
     ''')
     template, stringset = self.handler.parse(source)
     compiled = self.handler.compile(template, [])
     self.assertEqual(
         compiled,
         strip_leading_spaces('''
             <resources>
                 </resources>
         ''')
     )
Пример #23
0
    def test_empty_string_ignored(self):
        random_key = generate_random_string()
        source = strip_leading_spaces(u'''
            <resources>
                <string name="{key}"></string>
            </resources>
        '''.format(key=random_key))

        template, stringset = self.handler.parse(source)

        self.assertEqual(stringset, [])
        self.assertEqual(template, source)
Пример #24
0
    def test_missing_translated_plurals_removed(self):
        random_key = generate_random_string()
        random_singular = generate_random_string()
        random_plural = generate_random_string()
        source = strip_leading_spaces(u'''
            <resources>
                <plurals name="{key}">
                    <item quantity="one">{singular}</item>
                    <item quantity="other">{plural}</item>
                </plurals>
            </resources>
        '''.format(key=random_key, singular=random_singular,
                   plural=random_plural))

        template, stringset = self.handler.parse(source)
        compiled = self.handler.compile(template, [])
        self.assertEqual(compiled, strip_leading_spaces(u'''
            <resources>
                </resources>
        '''.format(key=random_key, singular=random_singular,
                   plural=random_plural)))
Пример #25
0
    def test_empty_string_ignored(self):
        random_key = generate_random_string()
        source = strip_leading_spaces(u'''
            <resources>
                <string name="{key}"></string>
            </resources>
        '''.format(key=random_key))

        template, stringset = self.handler.parse(source)

        self.assertEqual(stringset, [])
        self.assertEqual(template, source)
Пример #26
0
    def test_missing_translated_string_array_items_removed(self):
        random_key = generate_random_string()
        random_string1 = generate_random_string()
        random_string2 = generate_random_string()
        source = strip_leading_spaces(u'''
            <resources>
                <string-array name="{key}">
                    <item>{string1}</item>
                    <item>{string2}</item>
                </string-array>
            </resources>
        '''.format(key=random_key, string1=random_string1,
                   string2=random_string2))

        template, stringset = self.handler.parse(source)
        compiled = self.handler.compile(template, [stringset[0]])
        self.assertEqual(compiled, strip_leading_spaces(u'''
            <resources>
                <string-array name="{key}">
                    <item>{string1}</item>
                </string-array>
            </resources>
        '''.format(key=random_key, string1=random_string1)))
Пример #27
0
    def test_fuzzy_flag_removes_entry_but_keeps_strings(self):
        string1 = self._create_openstring(False)
        string2 = self._create_openstring(False, extra_context={'fuzzy': True})
        source = strip_leading_spaces(u"""
            #

            msgid ""
            msgstr ""

            msgid "{s1_key}"
            msgstr "{s1_str}"

            #, fuzzy
            msgid "{s2_key}"
            msgstr "{s2_str}"
        """.format(**{
            's1_key': string1.key,
            's1_str': string1.string,
            's2_key': string2.key,
            's2_str': string2.string
        }))
        template, stringset = self.handler.parse(source)
        compiled = self.handler.compile(template, [string1])
        self.assertEqual(
            compiled,
            strip_leading_spaces(
                u"""# \nmsgid ""
                msgstr ""

                msgid "{s1_key}"
                msgstr "{s1_str}"
                """.format(**{
                    's1_key': string1.key,
                    's1_str': string1.string
                }))
        )
Пример #28
0
    def test_empty_plural_ignored(self):
        random_key = generate_random_string()
        source = strip_leading_spaces(u'''
            <resources>
                <plurals name="{key}">
                    <item quantity="one"></item>
                    <item quantity="other"></item>
                </plurals>
            </resources>
        '''.format(key=random_key))

        template, stringset = self.handler.parse(source)

        self.assertEqual(stringset, [])
        self.assertEqual(template, source)
Пример #29
0
    def test_fuzzy_flag_removes_entry_but_keeps_strings(self):
        string1 = self._create_openstring(False)
        string2 = self._create_openstring(False, extra_context={'fuzzy': True})
        source = strip_leading_spaces(u"""
            #

            msgid ""
            msgstr ""

            msgid "{s1_key}"
            msgstr "{s1_str}"

            #, fuzzy
            msgid "{s2_key}"
            msgstr "{s2_str}"
        """.format(
            **{
                's1_key': string1.key,
                's1_str': string1.string,
                's2_key': string2.key,
                's2_str': string2.string
            }))
        template, stringset = self.handler.parse(source)
        compiled = self.handler.compile(template, [string1])
        self.assertEqual(
            compiled,
            strip_leading_spaces(
                u"""# \nmsgid ""
                msgstr ""

                msgid "{s1_key}"
                msgstr "{s1_str}"
                """.format(**{
                    's1_key': string1.key,
                    's1_str': string1.string
                })))
Пример #30
0
    def test_empty_plural_ignored(self):
        random_key = generate_random_string()
        source = strip_leading_spaces(u'''
            <resources>
                <plurals name="{key}">
                    <item quantity="one"></item>
                    <item quantity="other"></item>
                </plurals>
            </resources>
        '''.format(key=random_key))

        template, stringset = self.handler.parse(source)

        self.assertEqual(stringset, [])
        self.assertEqual(template, source)
Пример #31
0
    def test_openstring_has_all_fields(self):
        source = strip_leading_spaces(u"""
            msgid ""
            msgstr ""
            "Content-Type: text/plain; charset=UTF-8\n"
            "Content-Transfer-Encoding: 8bit\n"
            "Language: en\n"
            "Plural-Forms: nplurals=2; plural=(n != 1);\n"

            #  translator-comments1
            #  translator-comments2
            #. extracted-comments1
            #. extracted-comments2
            #: validators.py:9
            #: validators.py:11
            #, python-format
            #, another-flag
            msgid "metest"
            msgstr "msgstr1"
        """)
        template, stringset = self.handler.parse(source)
        expected_comment = (
            'extracted-comments1\nextracted-comments2\n'
            u' translator-comments1\n translator-comments2'
        )
        self.assertEqual(len(stringset), 1)
        self.assertEqual(
            stringset[0].developer_comment,
            expected_comment
        )
        self.assertEqual(
            stringset[0].occurrences,
            u'validators.py:9, validators.py:11'
        )
        self.assertEqual(
            stringset[0].flags,
            u'python-format, another-flag'
        )
Пример #32
0
    def test_removes_untranslated_pluralized(self):
        string1 = self._create_openstring(True)
        keys1 = string1.key.split(':')
        string2 = self._create_openstring(True)
        keys2 = string2.key.split(':')
        string3 = self._create_openstring(True)
        keys3 = string3.key.split(':')
        source = strip_leading_spaces(u"""
            #

            msgid ""
            msgstr ""

            msgid "{s1_key}"
            msgid_plural "{s1_key_plural}"
            msgstr[0] "{s1_str_singular}"
            msgstr[1] "{s1_str_plural}"

            msgid "{s2_key}"
            msgid_plural "{s2_key_plural}"
            msgstr[0] "{s2_str_singular}"
            msgstr[1] "{s2_str_plural}"

            msgid "{s3_key}"
            msgid_plural "{s3_key_plural}"
            msgstr[0] "{s3_str_singular}"
            msgstr[1] "{s3_str_plural}"
        """.format(**{
            's1_key': keys1[0],
            's1_key_plural': keys1[1],
            's1_str_singular': string1.string[0],
            's1_str_plural': string1.string[1],
            's2_key': keys2[0],
            's2_key_plural': keys2[1],
            's2_str_singular': string2.string[0],
            's2_str_plural': string2.string[1],
            's3_key': keys3[0],
            's3_key_plural': keys3[1],
            's3_str_singular': string3.string[0],
            's3_str_plural': string3.string[1]
        }))
        template, stringset = self.handler.parse(source)
        compiled = self.handler.compile(template, [string1, string3])
        self.assertEqual(
            compiled,
            strip_leading_spaces(
                u"""# \nmsgid ""
                msgstr ""

                msgid "{s1_key}"
                msgid_plural "{s1_key_plural}"
                msgstr[0] "{s1_str_singular}"
                msgstr[1] "{s1_str_plural}"

                msgid "{s3_key}"
                msgid_plural "{s3_key_plural}"
                msgstr[0] "{s3_str_singular}"
                msgstr[1] "{s3_str_plural}"
                """.format(**{
                    's1_key': keys1[0],
                    's1_key_plural': keys1[1],
                    's1_str_singular': string1.string[0],
                    's1_str_plural': string1.string[1],
                    's3_key': keys3[0],
                    's3_key_plural': keys3[1],
                    's3_str_singular': string3.string[0],
                    's3_str_plural': string3.string[1]
                }))
        )
Пример #33
0
    def test_removes_untranslated_pluralized(self):
        string1 = self._create_openstring(True)
        keys1 = string1.key.split(':')
        string2 = self._create_openstring(True)
        keys2 = string2.key.split(':')
        string3 = self._create_openstring(True)
        keys3 = string3.key.split(':')
        source = strip_leading_spaces(u"""
            #

            msgid ""
            msgstr ""

            msgid "{s1_key}"
            msgid_plural "{s1_key_plural}"
            msgstr[0] "{s1_str_singular}"
            msgstr[1] "{s1_str_plural}"

            msgid "{s2_key}"
            msgid_plural "{s2_key_plural}"
            msgstr[0] "{s2_str_singular}"
            msgstr[1] "{s2_str_plural}"

            msgid "{s3_key}"
            msgid_plural "{s3_key_plural}"
            msgstr[0] "{s3_str_singular}"
            msgstr[1] "{s3_str_plural}"
        """.format(
            **{
                's1_key': keys1[0],
                's1_key_plural': keys1[1],
                's1_str_singular': string1.string[0],
                's1_str_plural': string1.string[1],
                's2_key': keys2[0],
                's2_key_plural': keys2[1],
                's2_str_singular': string2.string[0],
                's2_str_plural': string2.string[1],
                's3_key': keys3[0],
                's3_key_plural': keys3[1],
                's3_str_singular': string3.string[0],
                's3_str_plural': string3.string[1]
            }))
        template, stringset = self.handler.parse(source)
        compiled = self.handler.compile(template, [string1, string3])
        self.assertEqual(
            compiled,
            strip_leading_spaces(u"""# \nmsgid ""
                msgstr ""

                msgid "{s1_key}"
                msgid_plural "{s1_key_plural}"
                msgstr[0] "{s1_str_singular}"
                msgstr[1] "{s1_str_plural}"

                msgid "{s3_key}"
                msgid_plural "{s3_key_plural}"
                msgstr[0] "{s3_str_singular}"
                msgstr[1] "{s3_str_plural}"
                """.format(
                **{
                    's1_key': keys1[0],
                    's1_key_plural': keys1[1],
                    's1_str_singular': string1.string[0],
                    's1_str_plural': string1.string[1],
                    's3_key': keys3[0],
                    's3_key_plural': keys3[1],
                    's3_str_singular': string3.string[0],
                    's3_str_plural': string3.string[1]
                })))
Пример #34
0
 def test_removes_untranslated(self):
     context_dict, openstring = self._create_pluralized_string()
     source = strip_leading_spaces(u"""
         <plist>
         <dict>
             <key>main_key</key>
             <dict>
                 <key>NSStringLocalizedFormatKey</key>
                 <string>%1$#@a_var@</string>
                 <key>secondary_key_1</key>
                 <dict>
                     <key>NSStringFormatSpecTypeKey</key>
                     <string>NSStringPluralRuleType</string>
                     <key>NSStringFormatValueTypeKey</key>
                     <string>d</string>
                     <key>one</key>
                     <string>removed_one_1</string>
                     <key>other</key>
                     <string>removed_other_1</string>
                 </dict>
                 <key>secondary_key_2</key>
                 <dict>
                     <key>NSStringFormatSpecTypeKey</key>
                     <string>NSStringPluralRuleType</string>
                     <key>NSStringFormatValueTypeKey</key>
                     <string>d</string>
                     <key>one</key>
                     <string>removed_one_2</string>
                     <key>other</key>
                     <string>removed_other_2</string>
                 </dict>
             </dict>
             <key>{main_key}</key>
             <dict>
                 <key>NSStringLocalizedFormatKey</key>
                 <string>%1$#@a_var@</string>
                 <key>{secondary_key}</key>
                 <dict>
                     <key>NSStringFormatSpecTypeKey</key>
                     <string>NSStringPluralRuleType</string>
                     <key>NSStringFormatValueTypeKey</key>
                     <string>d</string>
                     <key>one</key>
                     <string>{singular}</string>
                     <key>other</key>
                     <string>{plural}</string>
                 </dict>
             </dict>
         </dict>
         </plist>
     """.format(**context_dict))
     template, stringset = self.handler.parse(source)
     compiled = self.handler.compile(template, [openstring])
     self.assertEqual(
         compiled,
         strip_leading_spaces(u"""
             <plist>
             <dict>
                 <key>main_key</key>
                 <dict>
                     <key>NSStringLocalizedFormatKey</key>
                     <string>%1$#@a_var@</string>
                 </dict>
                 <key>{main_key}</key>
                 <dict>
                     <key>NSStringLocalizedFormatKey</key>
                     <string>%1$#@a_var@</string>
                     <key>{secondary_key}</key>
                     <dict>
                         <key>NSStringFormatSpecTypeKey</key>
                         <string>NSStringPluralRuleType</string>
                         <key>NSStringFormatValueTypeKey</key>
                         <string>d</string>
                         <key>one</key>
                         <string>{singular}</string>
                         <key>other</key>
                         <string>{plural}</string>
                     </dict>
                 </dict>
             </dict>
             </plist>
         """.format(**context_dict))
     )
Пример #35
0
 def test_removes_untranslated(self):
     context_dict, openstring = self._create_pluralized_string()
     source = strip_leading_spaces(u"""
         <plist>
         <dict>
             <key>main_key</key>
             <dict>
                 <key>NSStringLocalizedFormatKey</key>
                 <string>%1$#@a_var@</string>
                 <key>secondary_key_1</key>
                 <dict>
                     <key>NSStringFormatSpecTypeKey</key>
                     <string>NSStringPluralRuleType</string>
                     <key>NSStringFormatValueTypeKey</key>
                     <string>d</string>
                     <key>one</key>
                     <string>removed_one_1</string>
                     <key>other</key>
                     <string>removed_other_1</string>
                 </dict>
                 <key>secondary_key_2</key>
                 <dict>
                     <key>NSStringFormatSpecTypeKey</key>
                     <string>NSStringPluralRuleType</string>
                     <key>NSStringFormatValueTypeKey</key>
                     <string>d</string>
                     <key>one</key>
                     <string>removed_one_2</string>
                     <key>other</key>
                     <string>removed_other_2</string>
                 </dict>
             </dict>
             <key>{main_key}</key>
             <dict>
                 <key>NSStringLocalizedFormatKey</key>
                 <string>%1$#@a_var@</string>
                 <key>{secondary_key}</key>
                 <dict>
                     <key>NSStringFormatSpecTypeKey</key>
                     <string>NSStringPluralRuleType</string>
                     <key>NSStringFormatValueTypeKey</key>
                     <string>d</string>
                     <key>one</key>
                     <string>{singular}</string>
                     <key>other</key>
                     <string>{plural}</string>
                 </dict>
             </dict>
         </dict>
         </plist>
     """.format(**context_dict))
     template, stringset = self.handler.parse(source)
     compiled = self.handler.compile(template, [openstring])
     self.assertEqual(
         compiled,
         strip_leading_spaces(u"""
             <plist>
             <dict>
                 <key>main_key</key>
                 <dict>
                     <key>NSStringLocalizedFormatKey</key>
                     <string>%1$#@a_var@</string>
                 </dict>
                 <key>{main_key}</key>
                 <dict>
                     <key>NSStringLocalizedFormatKey</key>
                     <string>%1$#@a_var@</string>
                     <key>{secondary_key}</key>
                     <dict>
                         <key>NSStringFormatSpecTypeKey</key>
                         <string>NSStringPluralRuleType</string>
                         <key>NSStringFormatValueTypeKey</key>
                         <string>d</string>
                         <key>one</key>
                         <string>{singular}</string>
                         <key>other</key>
                         <string>{plural}</string>
                     </dict>
                 </dict>
             </dict>
             </plist>
         """.format(**context_dict)))