Exemple #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
 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)
    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)
    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))
    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))
Exemple #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)
    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'))
Exemple #8
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 = 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)
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)
Exemple #10
0
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)
Exemple #11
0
 def __init__(self, dictionary=Dictionary(), use_pretty_xml=True):
     self.dictionary = dictionary
     self.use_pretty_xml = use_pretty_xml
Exemple #12
0
 def setUp(self):
     self.dictionary = Dictionary()
     self.dictionary.add_translation('hello', 'en', 'Hi')
     self.dictionary.add_translation('welcome', 'en', 'Welcome')
Exemple #13
0
 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'''
Exemple #14
0
 def __init__(self, dictionary=Dictionary()):
     self.dictionary = dictionary