示例#1
0
    def test_findMissingKeys(self):
        """
        look for missing keys in the translated values.xml files
        """
        keys = localizr.getKeysFromTree(self.tree)
        missing = localizr.findMissingKeys(keys, self.LANGS, self.res_path)

        # verify that German is not missing any tags
        self.assertEqual(missing['de'], [])

        # verify that Spanish is missing all tags
        self.assertEqual(missing['es'], [('string', 'test_1'),
                                         ('string', 'test_2'),
                                         ('string', 'test_3'),
                                         ('string', 'test_4'),
                                         ('string', 'test_5'),
                                         ('plurals', 'plurals_test')])

        # verify that French is missing all tags (despite its extra tag)
        self.assertEqual(missing['fr'], [('string', 'test_1'),
                                         ('string', 'test_2'),
                                         ('string', 'test_3'),
                                         ('string', 'test_4'),
                                         ('string', 'test_5'),
                                         ('plurals', 'plurals_test')])

        # verify that traditional Chinese is only missing one tag
        self.assertEqual(missing['zh-rTW'], [('string', 'test_5'),
                                             ('plurals', 'plurals_test')])
    def test_cleanTranslationFiles(self):
        """
        Extra strings will be removed and re-arranged to match the order of the
        strings in the default language
        """
        # get the keys from the default language
        keys = localizr.getKeysFromTree(self.tree)

        # clean the fiels
        localizr.createOutputDir('./to_translate')
        localizr.cleanTranslationFiles(self.LANGS, keys, self.res_path)

        # verify that German strings are correctly sorted
        os.chdir(self.cwd)
        self.assertTrue(filecmp.cmp('./test/res/values-de/strings.xml',
                        './test/test_cleaned/res/values-de/strings.xml'))

        # verify that empty spanish strings stays empty
        os.chdir(self.cwd)
        self.assertTrue(filecmp.cmp('./test/res/values-es/strings.xml',
                        './test/test_cleaned/res/values-es/strings.xml'))

        # verify that extra french string is removed
        os.chdir(self.cwd)
        self.assertTrue(filecmp.cmp('./test/res/values-fr/strings.xml',
                        './test/test_cleaned/res/values-fr/strings.xml'))

        # verify that extra chinese string is removed and everything else is
        # the same
        os.chdir(self.cwd)
        self.assertTrue(filecmp.cmp('./test/res/values-zh-rTW/strings.xml',
                        './test/test_cleaned/res/values-zh-rTW/strings.xml'))
 def test_getKeysFromTrees(self):
     keys = localizr.getKeysFromTree(self.tree)
     self.assertEqual(
         keys,
         [('string', 'test_1'), ('string', 'test_2'), ('string', 'test_3'),
          ('string', 'test_4'), ('string', 'test_5'),
          ('plurals', 'plurals_test')])
    def test_findMissingKeys(self):
        """
        look for missing keys in the translated values.xml files
        """
        keys = localizr.getKeysFromTree(self.tree)
        missing = localizr.findMissingKeys(keys, self.LANGS, self.res_path)

        # verify that German is not missing any tags
        self.assertEqual(missing['de'], [])

        # verify that Spanish is missing all tags
        self.assertEqual(
            missing['es'],
            [('string', 'test_1'), ('string', 'test_2'), ('string', 'test_3'),
             ('string', 'test_4'), ('string', 'test_5'),
             ('plurals', 'plurals_test')])

        # verify that French is missing all tags (despite its extra tag)
        self.assertEqual(
            missing['fr'],
            [('string', 'test_1'), ('string', 'test_2'), ('string', 'test_3'),
             ('string', 'test_4'), ('string', 'test_5'),
             ('plurals', 'plurals_test')])

        # verify that traditional Chinese is only missing one tag
        self.assertEqual(
            missing['zh-rTW'],
            [('string', 'test_5'), ('plurals', 'plurals_test')])
示例#5
0
    def test_writeOutMissingStrings(self):
        # get tags from default tree so we know what to write out
        tags = localizr.getTagsFromTree(self.tree)

        # get the missing keys for each lang
        keys = localizr.getKeysFromTree(self.tree)
        missing = localizr.findMissingKeys(keys, self.LANGS, self.res_path)

        # write out the files
        localizr.createOutputDir('./test/to_translate')
        localizr.writeMissingKeysToFiles(self.LANGS, tags, missing,
                                         './test/to_translate')

        # verify that no German strings exist
        os.chdir(self.cwd)
        self.assertFalse(
            os.path.exists('./test/to_translate/strings_to_trans-de.xml'))

        # verify that spanish strings seem correct
        os.chdir(self.cwd)
        self.assertTrue(
            os.path.exists('./test/to_translate/strings_to_trans-es.xml'))
        self.assertTrue(
            filecmp.cmp('./test/test_to_translate/strings_to_trans-es.xml',
                        './test/to_translate/strings_to_trans-es.xml'))

        # verify that french strings seem correct
        os.chdir(self.cwd)
        self.assertTrue(
            os.path.exists('./test/to_translate/strings_to_trans-fr.xml'))
        self.assertTrue(
            filecmp.cmp('./test/test_to_translate/strings_to_trans-fr.xml',
                        './test/to_translate/strings_to_trans-fr.xml'))

        # verify that traditional chinese strings seem correct
        os.chdir(self.cwd)
        self.assertTrue(
            os.path.exists('./test/to_translate/strings_to_trans-zh-rTW.xml'))
        self.assertTrue(
            filecmp.cmp('./test/test_to_translate/strings_to_trans-zh-rTW.xml',
                        './test/to_translate/strings_to_trans-zh-rTW.xml'))
    def test_writeOutMissingStrings(self):
        # get tags from default tree so we know what to write out
        tags = localizr.getTagsFromTree(self.tree)

        # get the missing keys for each lang
        keys = localizr.getKeysFromTree(self.tree)
        missing = localizr.findMissingKeys(keys, self.LANGS, self.res_path)

        # write out the files
        localizr.createOutputDir('./test/to_translate')
        localizr.writeMissingKeysToFiles(self.LANGS, tags, missing,
                                         './test/to_translate')

        # verify that no German strings exist
        os.chdir(self.cwd)
        self.assertFalse(os.path.exists(
            './test/to_translate/strings_to_trans-de.xml'))

        # verify that spanish strings seem correct
        os.chdir(self.cwd)
        self.assertTrue(os.path.exists(
            './test/to_translate/strings_to_trans-es.xml'))
        self.assertTrue(filecmp.cmp(
            './test/test_to_translate/strings_to_trans-es.xml',
            './test/to_translate/strings_to_trans-es.xml'))

        # verify that french strings seem correct
        os.chdir(self.cwd)
        self.assertTrue(os.path.exists(
            './test/to_translate/strings_to_trans-fr.xml'))
        self.assertTrue(filecmp.cmp(
            './test/test_to_translate/strings_to_trans-fr.xml',
            './test/to_translate/strings_to_trans-fr.xml'))

        # verify that traditional chinese strings seem correct
        os.chdir(self.cwd)
        self.assertTrue(os.path.exists(
            './test/to_translate/strings_to_trans-zh-rTW.xml'))
        self.assertTrue(filecmp.cmp(
            './test/test_to_translate/strings_to_trans-zh-rTW.xml',
            './test/to_translate/strings_to_trans-zh-rTW.xml'))
示例#7
0
    def test_cleanTranslationFiles(self):
        """
        Extra strings will be removed and re-arranged to match the order of the
        strings in the default language
        """
        # get the keys from the default language
        keys = localizr.getKeysFromTree(self.tree)

        # clean the fiels
        localizr.createOutputDir('./to_translate')
        localizr.cleanTranslationFiles(self.LANGS, keys, self.res_path)

        # verify that German strings are correctly sorted
        os.chdir(self.cwd)
        self.assertTrue(
            filecmp.cmp('./test/res/values-de/strings.xml',
                        './test/test_cleaned/res/values-de/strings.xml'))

        # verify that empty spanish strings stays empty
        os.chdir(self.cwd)
        self.assertTrue(
            filecmp.cmp('./test/res/values-es/strings.xml',
                        './test/test_cleaned/res/values-es/strings.xml'))

        # verify that extra french string is removed
        os.chdir(self.cwd)
        self.assertTrue(
            filecmp.cmp('./test/res/values-fr/strings.xml',
                        './test/test_cleaned/res/values-fr/strings.xml'))

        # verify that extra chinese string is removed and everything else is
        # the same
        os.chdir(self.cwd)
        self.assertTrue(
            filecmp.cmp('./test/res/values-zh-rTW/strings.xml',
                        './test/test_cleaned/res/values-zh-rTW/strings.xml'))
示例#8
0
 def test_getKeysFromTrees(self):
     keys = localizr.getKeysFromTree(self.tree)
     self.assertEqual(keys, [('string', 'test_1'), ('string', 'test_2'),
                             ('string', 'test_3'), ('string', 'test_4'),
                             ('string', 'test_5'),
                             ('plurals', 'plurals_test')])