예제 #1
0
 def _generate_translations_for_po(self, worksheet):
     """
     :return: a list of Translation objects
     """
     rows, source, translation, occurrence, context = self._parse_excel_sheet(
         worksheet)
     translations = {worksheet.title: []}
     for row in rows[1:]:
         _occurrence = row[
             occurrence].value or '' if occurrence is not None else ''
         _context = row[context].value if context is not None else ''
         translations[worksheet.title].append(
             Translation(row[source].value, row[translation].value,
                         [(_occurrence, '')], _context))
     return translations
예제 #2
0
import os

from django.test.testcases import SimpleTestCase

import polib

from corehq.apps.translations.generators import PoFileGenerator, Translation

translations = [
    Translation('hello', 'नमस्ते', [('occurrence-hello', '')],
                '0:occurrence-hello'),
    Translation('bye', 'अलविदा', [('occurrence-bye', '')], '0:occurrence-bye'),
]


class TestPoFileGenerator(SimpleTestCase):
    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,