Ejemplo n.º 1
0
    def test_translations_in_generated_files(self):
        all_translations = {
            'sheet1': list(translations),
            'sheet2': list(translations),
        }
        file_paths = []
        with PoFileGenerator(all_translations, {}) as po_file_generator:
            generated_files = po_file_generator.generate_translation_files()
            for file_name, file_path in generated_files:
                file_paths.append(file_path)
                list_of_translations = polib.pofile(file_path)
                # assure translations
                self.assertEqual(list_of_translations[0].msgid, 'hello')
                self.assertEqual(list_of_translations[0].msgstr, 'नमस्ते')
                self.assertEqual(list_of_translations[0].msgctxt,
                                 '0:occurrence-hello')
                self.assertEqual(list_of_translations[0].occurrences,
                                 [('occurrence-hello', '')])
                self.assertEqual(list_of_translations[1].msgid, 'bye')
                self.assertEqual(list_of_translations[1].msgstr, 'अलविदा')
                self.assertEqual(list_of_translations[1].msgctxt,
                                 '0:occurrence-bye')
                self.assertEqual(list_of_translations[1].occurrences,
                                 [('occurrence-bye', '')])

        # assure files are cleaned
        for file_path in file_paths:
            self.assertFalse(os.path.exists(file_path))
Ejemplo n.º 2
0
    def _generate_po_content(self, worksheet):
        """
        extract translations from worksheet and converts to a po file

        :return: content of file generated
        """
        translations = self._generate_translations_for_po(worksheet)
        with PoFileGenerator(translations, {}) as po_file_generator:
            generated_files = po_file_generator.generate_translation_files()
            with open(generated_files[0].path, 'rb') as f:
                return f.read()
Ejemplo n.º 3
0
 def send_translation_files(self):
     """
     submit translation files to transifex
     """
     app_trans_generator = AppTranslationsGenerator(
         self.domain, self.app_id_to_build, self.version,
         self.key_lang, self.source_lang, self.lang_prefix,
         self.exclude_if_default, self.use_version_postfix)
     with PoFileGenerator(app_trans_generator.translations,
                          app_trans_generator.metadata) as po_file_generator:
         generated_files = po_file_generator.generate_translation_files()
         return self._send_files_to_transifex(generated_files, app_trans_generator)
Ejemplo n.º 4
0
 def test_metadata(self):
     all_translations = {'sheet1': list(translations)}
     metadata = {
         'MIME-Version': '1.0',
         'Content-Type': 'text/plain; charset=utf-8',
         'Language': 'hin',
     }
     with PoFileGenerator(all_translations, metadata) as po_file_generator:
         generated_files = po_file_generator.generate_translation_files()
         for file_name, file_path in generated_files:
             # ensure meta data
             with open(file_path, encoding='utf-8') as f:
                 file_content = f.read()
                 self.assertIn("Language: hin", file_content)
                 self.assertIn("MIME-Version: 1.0", file_content)
                 self.assertIn("Content-Type: text/plain; charset=utf-8",
                               file_content)