Exemplo n.º 1
0
    def test_write_8(self):
        self.maxDiff = 1024
        strings_table = StringsTable(os.path.join(source_root, 'example.strings'), encoding='utf-8')

        with tempfile.TemporaryDirectory() as tmp_dir:
            output_file_path = os.path.join(tmp_dir, 'example.strings')
            strings_table.write_file(output_file_path, encoding='utf-8')

            with open(output_file_path, 'r') as f:
                result = f.read()

            self.assertEqual(result, r'''/* Some comemnt */
"%@ doesn't have a list named %@." = "%1$@ は %2$@ というリストをもっていません。";

/* Error message when Tickle tries to open a document but fails to fetch the version info,
   English source is "Cannot get the version of this Tickle document." */
"Cannot get the version of this Tickle document." = "Cannot get the version of this Tickle document.";

"No comment" = "沒有註解";

/* Comment with "quote" */
"String with \"quote\".\"" = "有引號的字\"";

/* String with = */
"String with =" = "String with =";

/* String with semicolon */
"String with ;" = "String with ;";

/* String with spaces */
"String\twith \n" = "String\twith \n";

/* Not translated */
"String not translated" = "";
''')
Exemplo n.º 2
0
    def test_insert(self):
        strings_table = StringsTable()

        localized_string = strings_table.insert('A string', '一個字串')
        self.assertEqual(len(strings_table), 1)
        self.assertEqual(strings_table['A string'], localized_string)
        self.assertEqual(strings_table['A string'].source, 'A string')
        self.assertEqual(strings_table['A string'].localized, '一個字串')
        self.assertIsNone(strings_table['A string'].comment)

        localized_string = strings_table.insert('A number', '수', 'a digits value')
        self.assertEqual(len(strings_table), 2)
        self.assertEqual(strings_table['A number'], localized_string)
        self.assertEqual(strings_table['A number'].source, 'A number')
        self.assertEqual(strings_table['A number'].localized, '수')
        self.assertEqual(strings_table['A number'].comment, 'a digits value')
Exemplo n.º 3
0
 def test_duplicate(self):
     duplicated_entries = StringsTable.duplicated_entries_in_file(os.path.join(source_root, 'duplicate16.strings'))
     self.assertEqual(len(duplicated_entries), 1)
     self.assertIn('String with "quote"."', duplicated_entries)
     self.assertEqual(len(duplicated_entries['String with "quote"."']), 2)
     self.assertEqual(duplicated_entries['String with "quote"."'][0].localized, '有引號的字"')
     self.assertEqual(duplicated_entries['String with "quote"."'][1].localized, '有引號的字2"')
Exemplo n.º 4
0
 def setUp(self):
     self.strings_table = StringsTable(os.path.join(source_root, 'example.strings'), encoding='utf-8')
     self.another_strings_table = StringsTable(os.path.join(source_root, 'example2.strings'), encoding='utf-8')
Exemplo n.º 5
0
class TestMergeStringsFile(unittest.TestCase, TestStringsTableContentMixin):

    def setUp(self):
        self.strings_table = StringsTable(os.path.join(source_root, 'example.strings'), encoding='utf-8')
        self.another_strings_table = StringsTable(os.path.join(source_root, 'example2.strings'), encoding='utf-8')

    def test_merge_default(self):
        self.strings_table.merge(self.another_strings_table)
        self.assertEqual(len(self.strings_table), 9)
        self._test_strings_table_content(self.strings_table, expected_results=self.default_expected_results + (
            ExpectedResult("a key", "一個鑰匙", "A key"),
        ))

    def test_merge_not_keep_comment(self):
        self.strings_table.merge(self.another_strings_table, keep_comment=False)
        self._test_strings_table_content(self.strings_table, expected_results=(
            ExpectedResult("%@ doesn't have a list named %@.", "%1$@ は %2$@ というリストをもっていません。", "Some comemnt"),
            ExpectedResult("Cannot get the version of this Tickle document.",
                           "Cannot get the version of this Tickle document.",
                           'Error message when Tickle tries to open a document but fails to fetch the version info,\n'
                           '   English source is "Cannot get the version of this Tickle document."'),
            ExpectedResult("No comment", "沒有註解", None),
            ExpectedResult("String with \"quote\".\"", "有引號的字\"", "Comment with \"QUOTE\""),
            ExpectedResult("String with =", "String with =", "String with ="),
            ExpectedResult("String with ;", "String with ;", "String with semicolon"),
            ExpectedResult(r"String\twith \n", r"String\twith \n", "String with spaces"),
            ExpectedResult("String not translated", "String not translated", "Not translated"),
            ExpectedResult("a key", "一個鑰匙", "A key"),
        ))

    def test_merge_not_keep_localized(self):
        self.strings_table.merge(self.another_strings_table, keep_localized=False)
        self._test_strings_table_content(self.strings_table, expected_results=(
            ExpectedResult("%@ doesn't have a list named %@.", "%1$@ は %2$@ というリストをもっていません。", "Some comemnt"),
            ExpectedResult("Cannot get the version of this Tickle document.",
                           "Cannot get the version of this Tickle document.",
                           'Error message when Tickle tries to open a document but fails to fetch the version info,\n'
                           '   English source is "Cannot get the version of this Tickle document."'),
            ExpectedResult("No comment", "kein Kommentar", None),
            ExpectedResult("String with \"quote\".\"", "有引號的字\"", "Comment with \"quote\""),
            ExpectedResult("String with =", "String with =", "String with ="),
            ExpectedResult("String with ;", "String with ;", "String with semicolon"),
            ExpectedResult(r"String\twith \n", r"String\twith \n", "String with spaces"),
            ExpectedResult("String not translated", "String not translated", "Not translated"),
            ExpectedResult("a key", "一個鑰匙", "A key"),
        ))

    def test_merge_exclude_extra(self):
        self.strings_table.merge(self.another_strings_table, exclude_extra=True)
        self._test_strings_table_content(self.strings_table, expected_results=(
            ExpectedResult("%@ doesn't have a list named %@.", "%1$@ は %2$@ というリストをもっていません。", "Some comemnt"),
            ExpectedResult("Cannot get the version of this Tickle document.",
                           "Cannot get the version of this Tickle document.",
                           'Error message when Tickle tries to open a document but fails to fetch the version info,\n'
                           '   English source is "Cannot get the version of this Tickle document."'),
            ExpectedResult("No comment", "沒有註解", None),
            ExpectedResult("String with \"quote\".\"", "有引號的字\"", "Comment with \"quote\""),
            ExpectedResult("String with =", "String with =", "String with ="),
            ExpectedResult(r"String\twith \n", r"String\twith \n", "String with spaces"),
            ExpectedResult("a key", "一個鑰匙", "A key"),
        ))