def test_not_upload_all_properties_with_parital_ui_translations(self): headers = (('translations', ('property', 'en', 'fra')),) data = (('translation.always.upload', 'Miley', 'Cyrus'),) f = self._build_translation_download_file(headers, data) translations, error_properties, warnings = process_ui_translation_upload(self.app, f) update_app_translations_from_trans_dict(self.app, translations) self.assertDictEqual(self.app.translations, EXPECTED_TRANSLATIONS)
def test_partial_property_and_language(self): headers = (('translations', ('property', 'en')),) data = (('translation.always.upload', 'Miley'),) f = self._build_translation_download_file(headers, data) translations, error_properties, warnings = process_ui_translation_upload(self.app, f) update_app_translations_from_trans_dict(self.app, translations) self.assertDictEqual(self.app.translations['en'], {'translation.always.upload': 'Miley'}) self.assertDictEqual(self.app.translations['fra'], INITIAL_TRANSLATIONS['fra'])
def test_not_upload_all_properties_with_parital_ui_translations(self): headers = (('translations', ('property', 'en', 'fra')), ) data = (('translation.always.upload', 'Miley', 'Cyrus'), ) f = self._build_translation_download_file(headers, data) translations, error_properties, warnings = process_ui_translation_upload( self.app, f) update_app_translations_from_trans_dict(self.app, translations) self.assertDictEqual(self.app.translations, EXPECTED_TRANSLATIONS)
def test_not_upload_all_languages(self): headers = (('translations', ('property', 'en')),) data = ( ('translation.always.upload', 'Miley'), ('translation.sometimes.upload', 'Kanye'), ) f = self._build_translation_download_file(headers, data) translations, error_properties, warnings = process_ui_translation_upload(self.app, f) update_app_translations_from_trans_dict(self.app, translations) self.assertDictEqual(self.app.translations['en'], EXPECTED_TRANSLATIONS['en']) self.assertDictEqual(self.app.translations['fra'], INITIAL_TRANSLATIONS['fra'])
def test_partial_property_and_language_with_partial_ui_translations(self): headers = (('translations', ('property', 'en')), ) data = (('translation.always.upload', 'Miley'), ) f = self._build_translation_download_file(headers, data) translations, error_properties, warnings = process_ui_translation_upload( self.app, f) update_app_translations_from_trans_dict(self.app, translations) self.assertDictEqual(self.app.translations['en'], EXPECTED_TRANSLATIONS['en']) self.assertDictEqual(self.app.translations['fra'], INITIAL_TRANSLATIONS['fra'])
def upload_bulk_ui_translations(request, domain, app_id): def _html_message(header_text, messages): message = header_text + "<br>" for prop in messages: message += "<li>%s</li>" % prop return message success = False try: app = get_app(domain, app_id) trans_dict, error_properties, warnings = process_ui_translation_upload( app, request.file) if error_properties: message = _html_message( _("Upload failed. We found problems with the following translations:" ), error_properties) messages.error(request, message, extra_tags='html') else: # update translations only if there were no errors update_app_translations_from_trans_dict(app, trans_dict) app.save() success = True if warnings: message = _html_message( _("Upload succeeded, but we found following issues for some properties" ), warnings) messages.warning(request, message, extra_tags='html') except InvalidExcelFileException as e: messages.error(request, _(APP_TRANSLATION_UPLOAD_FAIL_MESSAGE).format(e)) except Exception: notify_exception(request, 'Bulk Upload Translations Error') messages.error( request, _("Something went wrong! Update failed. We're looking into it")) if success: messages.success(request, _("UI Translations Updated!")) # In v2, languages is the default tab on the settings page view_name = 'app_settings' return HttpResponseRedirect(reverse(view_name, args=[domain, app_id]))
def test_linked_app_not_upload_all_languages_with_partial_ui_translations( self): headers = (('translations', ('property', 'en')), ) data = ( ('translation.always.upload', 'Miley'), ('translation.sometimes.upload', 'Kanye'), ) f = self._build_translation_download_file(headers, data) translations, error_properties, warnings = process_ui_translation_upload( self.linked_app, f) update_app_translations_from_trans_dict(self.linked_app, translations) self.assertDictEqual(self.linked_app.translations['en'], EXPECTED_TRANSLATIONS['en']) self.assertDictEqual(self.linked_app.translations['fra'], INITIAL_TRANSLATIONS['fra']) self.assertDictEqual(self.linked_app.linked_app_translations['en'], EXPECTED_TRANSLATIONS['en']) with mock.patch.object(LinkedApplication, 'save'): self.linked_app.reapply_overrides() self.assertDictEqual(self.linked_app.translations['en'], EXPECTED_TRANSLATIONS['en'])
def upload_bulk_ui_translations(request, domain, app_id): def _html_message(header_text, messages): message = header_text + "<br>" for prop in messages: message += "<li>%s</li>" % prop return message success = False try: app = get_app(domain, app_id) trans_dict, error_properties, warnings = process_ui_translation_upload( app, request.file ) if error_properties: message = _html_message(_("Upload failed. We found problems with the following translations:"), error_properties) messages.error(request, message, extra_tags='html') else: # update translations only if there were no errors update_app_translations_from_trans_dict(app, trans_dict) app.save() success = True if warnings: message = _html_message(_("Upload succeeded, but we found following issues for some properties"), warnings) messages.warning(request, message, extra_tags='html') except Exception: notify_exception(request, 'Bulk Upload Translations Error') messages.error(request, _("Something went wrong! Update failed. We're looking into it")) if success: messages.success(request, _("UI Translations Updated!")) # In v2, languages is the default tab on the settings page view_name = 'app_settings' return HttpResponseRedirect(reverse(view_name, args=[domain, app_id]))