def email_project_from_hq(domain, data, email): """Emails the requester with an excel file translations to be sent to Transifex. Used to verify translations before sending to Transifex """ lang = data.get('source_lang') project_slug = data.get('transifex_project_slug') quacks_like_a_transifex = AppTranslationsGenerator(domain, data.get('app_id'), data.get('version'), key_lang=lang, source_lang=lang, lang_prefix='default_') parser = TranslationsParser(quacks_like_a_transifex) try: translation_file, __ = parser.generate_excel_file() with open(translation_file.name, 'rb') as file_obj: email = EmailMessage( subject='[{}] - HQ translation download'.format( settings.SERVER_ENVIRONMENT), body="Translations from HQ", to=[email], from_email=settings.DEFAULT_FROM_EMAIL) filename = "{project}-{lang}-translations.xls".format( project=project_slug, lang=lang) email.attach(filename=filename, content=file_obj.read()) email.send() finally: try: os.remove(translation_file.name) except (NameError, OSError): pass
def __init__(self, app, uploaded_workbook, lang_prefix='default_'): self.app = app self.uploaded_workbook = uploaded_workbook self.headers = None self.expected_rows = None self.lang_prefix = lang_prefix self.default_language_column = self.lang_prefix + self.app.default_language self.app_translation_generator = AppTranslationsGenerator( self.app.domain, self.app.get_id, None, self.app.default_language, self.app.default_language, self.lang_prefix)
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)
def _setup(self): self._validate_sheet() self.single_sheet = is_single_sheet_workbook(self.uploaded_workbook) self.lang_cols_to_compare = [self.lang_prefix + self.lang_to_compare] if self.lang_to_compare != self.app.default_language: default_lang_col = self.lang_prefix + self.app.default_language if default_lang_col in self.uploaded_workbook.worksheets[ 0].fieldnames: self.lang_cols_to_compare.append(default_lang_col) self.app_translation_generator = AppTranslationsGenerator( self.app.domain, self.app.get_id, None, self.app.default_language, self.lang_to_compare, self.lang_prefix) self.current_sheet_name_to_module_or_form_type_and_id = dict() self.uploaded_sheet_name_to_module_or_form_type_and_id = dict()
def __init__(self, app, uploaded_workbook, lang_to_compare, lang_prefix='default_'): self.app = app self.uploaded_workbook = uploaded_workbook self.headers = None self.expected_rows = None self.lang_prefix = lang_prefix self.lang_cols_to_compare = [self.lang_prefix + self.app.default_language] self.default_language_column = self.lang_prefix + self.app.default_language if lang_to_compare in app.langs and lang_to_compare != self.app.default_language: self.lang_cols_to_compare.append(self.lang_prefix + lang_to_compare) target_lang = lang_to_compare else: target_lang = self.app.default_language self.app_translation_generator = AppTranslationsGenerator( self.app.domain, self.app.get_id, None, self.app.default_language, target_lang, self.lang_prefix)
def _setup(self): self.single_sheet = self._is_single_sheet() if self.single_sheet: self.lang_cols_to_compare = [ self.lang_prefix + self.lang_to_compare ] else: self.lang_cols_to_compare = [ self.lang_prefix + self.app.default_language ] # compare lang to compare along with default language, if not same if self.lang_to_compare != self.app.default_language: self.lang_cols_to_compare.append(self.lang_prefix + self.lang_to_compare) self.app_translation_generator = AppTranslationsGenerator( self.app.domain, self.app.get_id, None, self.app.default_language, self.lang_to_compare, self.lang_prefix) self.current_sheet_name_to_module_or_form_type_and_id = dict() self.uploaded_sheet_name_to_module_or_form_type_and_id = dict()
def setUpClass(cls): super(TestTransifexBlacklist, cls).setUpClass() factory = AppFactory() app = factory.app app.langs = ['en', 'hin'] module, form = factory.new_basic_module('register', 'case') form.source = cls.get_xml('transifex_blacklist').decode('utf-8') with patch( 'corehq.apps.translations.generators.get_current_app') as mock: mock.return_value = app trans_gen = AppTranslationsGenerator('domain', 'app_id', 1, 'en', 'en', 'default_') translations = trans_gen.translations first_form_translations = translations['form_register_form_0_v1'] cls.labels_sent_to_transifex = [ trans.msgctxt for trans in first_form_translations ]