示例#1
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')
示例#2
0
    def test_write_16(self):
        self.maxDiff = 1024
        strings_table = StringsTable(os.path.join(source_root, 'example16.strings'))

        with tempfile.TemporaryDirectory() as tmp_dir:
            strings_table['String with ;'].localized = '有分號的字'
            strings_table['String with ='].comment = 'String with "equal" sign'
            strings_table.insert('String not translated 2', comment='Another not translated')

            output_file_path = os.path.join(tmp_dir, 'example16.strings')
            strings_table.write_file(output_file_path)
            with open(output_file_path, 'r', encoding='utf-16') 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 "equal" sign */
"String with =" = "String with =";

/* String with semicolon */
"String with ;" = "有分號的字";

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

/* Not translated */
"String not translated" = "";

/* Another not translated */
"String not translated 2" = "";
''')