コード例 #1
0
    def read(self, google_doc_name):
        worksheet = self._get_worksheet(google_doc_name)
        worksheet_cells = worksheet.get_all_values(returnas='cell',
                                                   include_empty=False)

        log_step(str(worksheet_cells))

        languages_row = worksheet_cells[0]
        values_rows = worksheet_cells[1:]

        languages = self._load_languages(languages_row)
        entries = self._read_strings(values_rows)
        dictionary = Dictionary()

        for i, lang in enumerate(languages):
            for row in entries:
                value_idx = i + 1
                key = row[0]
                value = row[value_idx] if value_idx < len(row) else None

                if len(key) == 0:
                    continue
                else:
                    if value is None and self.keys_as_values_if_empty:
                        value = key
                    dictionary.add_translation(key, lang, value)
        return dictionary
コード例 #2
0
ファイル: test_formatters.py プロジェクト: pblondin/stringify
 def test_simple(self):
     dictionary = Dictionary()
     formatter = AndroidToDictionary(dictionary)
     formatter.format(self.xml, 'en')
     self.assertEqual(dictionary.get_translation('hi', 'en'), 'Hi')
     self.assertEqual(dictionary.get_translation('welcome', 'en'),
                      'Welcome')
     self.assertEqual(len(dictionary.languages), 1)
コード例 #3
0
ファイル: test_formatters.py プロジェクト: pblondin/stringify
    def test_simple(self):
        dictionary = Dictionary()
        formatter = SwiftToDictionary(dictionary)
        formatter.format(self.localizable_content, 'en')

        self.assertEqual(dictionary.get_translation('hi', 'en'), 'Hi')
        self.assertEqual(dictionary.get_translation('welcome', 'en'),
                         'Welcome')
        self.assertEqual(len(dictionary.languages), 1)
コード例 #4
0
    def test_dictionary_keys(self):
        dictionary = Dictionary()
        dictionary.add_translation(self.key_welcome, self.lang_pl, self.pl_hello)
        dictionary.add_translation(self.key_bye, self.lang_pl, self.pl_bye)

        self.assertEqual(2, len(dictionary.keys()))
        self.assertEqual(1, len(dictionary.languages))

        dictionary.add_translation(self.key_bye, self.lang_en, self.en_bye)
        self.assertEqual(2, len(dictionary.keys()))
        self.assertEqual(2, len(dictionary.languages))
コード例 #5
0
    def test_values_insertion(self):
        dictionary = Dictionary()
        dictionary.add_translation(self.key_welcome, self.lang_pl, self.pl_hello)
        self.assertEqual(self.pl_hello, dictionary.get_translation(self.key_welcome, self.lang_pl))

        dictionary.add_translation(self.key_welcome, self.lang_pl, self.pl_hello_2)
        self.assertEqual(self.pl_hello_2, dictionary.get_translation(self.key_welcome, self.lang_pl))
コード例 #6
0
    def execute(self):
        files_finder = LocalizableFinder(self.directory, self.files_regex,
                                         self.default_lang)
        files = files_finder.find(
            language_decoders=[self.langage_path_decoder])
        dictionary = Dictionary()
        for file_path, language in files:
            atd = SwiftImport(dictionary)
            atd.format(open(file_path), language)

        if dictionary.is_empty():
            raise Exception("Empty dictionary!")
        else:
            google_doc_handler = GoogleDocsHandler(
                self.google_credentials_path)
            google_doc_handler.write(self.google_sheet_name, dictionary)
コード例 #7
0
    def test_add(self):
        dict1 = Dictionary()
        dict2 = Dictionary()

        dict1.add_translation('hello', 'en', 'Hello')
        dict2.add_translation('hello', 'pl', 'Czesc')

        new_dict = dict1 + dict2
        self.assertEqual(len(new_dict.languages), 2)
        self.assertEqual(len(new_dict.keys()), 1)
        self.assertEqual('Hello', new_dict.get_translation('hello', 'en'))
        self.assertEqual('Czesc', new_dict.get_translation('hello', 'pl'))
コード例 #8
0
ファイル: android2docs.py プロジェクト: pblondin/stringify
    def execute(self):
        files_finder = LocalizableFinder(self.directory, self.files_regex,
                                         self.default_lang)
        files = files_finder.find(
            language_decoders=[self.langage_path_decoder])
        dictionary = Dictionary()
        for file_path, language in files:
            atd = AndroidStringsImport(dictionary)
            atd.format(open(file_path), language)

        google_doc_handler = GoogleDocsHandler(self.google_credentials_path)
        google_doc_handler.write(self.google_sheet_name, dictionary)
コード例 #9
0
ファイル: test_formatters.py プロジェクト: pblondin/stringify
class TestAndroidFormatter(unittest.TestCase):
    def setUp(self):
        self.dictionary = Dictionary()
        self.dictionary.add_translation('hello', 'en', 'Hi')
        self.dictionary.add_translation('welcome', 'en', 'Welcome')

    def _generate_result(self, elements=()):
        result = "<resources>"
        for element in elements:
            result += '<string name="%s">%s</string>' % element
        result += "</resources>"
        return result

    def test_template(self):
        formatter = DictionaryToAndroid(dictionary=self.dictionary,
                                        use_pretty_xml=False)
        formatted_string = formatter.format('en')
        dictionary_result = self._generate_result(
            (('hello', 'Hi'), ('welcome', 'Welcome')))
        self.assertEqual(formatted_string, dictionary_result)

    def test_empty(self):
        self.dictionary.clear()
        formatter = DictionaryToAndroid(dictionary=self.dictionary,
                                        use_pretty_xml=False)
        result = formatter.format('en')
        expected_result = self._generate_result()
        self.assertEqual(result, expected_result)
コード例 #10
0
ファイル: test_formatters.py プロジェクト: pblondin/stringify
class TestSwiftFormatter(unittest.TestCase):
    def setUp(self):
        self.dictionary = Dictionary()
        self.dictionary.add_translation('hello', 'en', 'Hi')
        self.dictionary.add_translation('welcome', 'en', 'Welcome')
        self.dictionary_result = '''"hello" = "Hi";\n"welcome" = "Welcome";\n'''

    def test_template(self):
        formatter = DictionaryToSwift(self.dictionary)
        formatted_string = formatter.format('en')
        self.assertEqual(formatted_string, self.dictionary_result)

    def test_empty(self):
        self.dictionary.clear()
        formatter = DictionaryToSwift(self.dictionary)
        formatted_string = formatter.format('en')
        self.assertTrue(len(formatted_string) == 0)
コード例 #11
0
ファイル: docs2android.py プロジェクト: pblondin/stringify
 def __init__(self, dictionary=Dictionary(), use_pretty_xml=True):
     self.dictionary = dictionary
     self.use_pretty_xml = use_pretty_xml
コード例 #12
0
ファイル: test_formatters.py プロジェクト: pblondin/stringify
 def setUp(self):
     self.dictionary = Dictionary()
     self.dictionary.add_translation('hello', 'en', 'Hi')
     self.dictionary.add_translation('welcome', 'en', 'Welcome')
コード例 #13
0
ファイル: test_formatters.py プロジェクト: pblondin/stringify
 def setUp(self):
     self.dictionary = Dictionary()
     self.dictionary.add_translation('hello', 'en', 'Hi')
     self.dictionary.add_translation('welcome', 'en', 'Welcome')
     self.dictionary_result = '''"hello" = "Hi";\n"welcome" = "Welcome";\n'''
コード例 #14
0
ファイル: android2docs.py プロジェクト: pblondin/stringify
 def __init__(self, dictionary=Dictionary()):
     self.dictionary = dictionary