Exemple #1
0
    def test_translation(self):
        headers = (('translations', ('property', 'en', 'fra')), )
        # on an update to 2.31.0, the keys date.tomorrow, entity.sort.title,
        # activity.locationcapture.Longitude were no longer present in messages_en-2.txt
        # They were replaced by other randomly selected strings in that file.
        # Leaving this note here in case this issue comes up again. --B
        data = (('key.manage.title', 'wobble',
                 ''), ('bulk.send.dialog.progress', 'wabble ${0}',
                       ''), ('connection.test.access.settings', '', 'wibble'),
                ('bulk.send.dialog.progress', '',
                 'wubble ${0}'), ('home.start.demo', 'Ding',
                                  'Dong'), ('unknown_string', 'Ding', 'Dong'),
                ('updates.found', 'I am missing a parameter',
                 'I have ${0} an ${1} extra ${2} parameter'),
                ('sync.progress', 'It is fine to ${1} reorder ${0} params',
                 'But use ${x0} correct syntax $ {1}'))

        f = self._build_translation_download_file(headers, data)
        translations, error_properties, warnings = process_ui_translation_upload(
            self.app, f)

        self.assertEqual(
            dict(translations), {
                'en': {
                    'key.manage.title': 'wobble',
                    'bulk.send.dialog.progress': 'wabble ${0}',
                    'home.start.demo': 'Ding',
                    'unknown_string': 'Ding',
                    'updates.found': 'I am missing a parameter',
                    'sync.progress': 'It is fine to ${1} reorder ${0} params',
                },
                'fra': {
                    'connection.test.access.settings': 'wibble',
                    'bulk.send.dialog.progress': 'wubble ${0}',
                    'home.start.demo': 'Dong',
                    'unknown_string': 'Dong',
                    'updates.found':
                    'I have ${0} an ${1} extra ${2} parameter',
                    'sync.progress': 'But use ${x0} correct syntax $ {1}',
                }
            })
        self.assertEqual(len(error_properties), 2)
        self.assertEqual([e.strip() for e in error_properties], [
            "Could not understand '${x0}' in fra value of 'sync.progress'.",
            "Could not understand '$ {1}' in fra value of 'sync.progress'.",
        ])
        self.assertEqual(len(warnings), 3)
        self.assertEqual([e.strip() for e in warnings], [
            "Property 'unknown_string' is not a known CommCare UI string, but we added it anyway.",
            "Property 'updates.found' should contain ${0}, ${1} but en value contains no parameters.",
            "Property 'updates.found' should contain ${0}, ${1} but fra value contains ${0}, ${1}, ${2}.",
        ])

        # test existing translations get updated correctly
        data = (('home.start.demo', 'change_1', 'change_2'))
        f = self._build_translation_download_file(headers, data)
        translations, error_properties, warnings = process_ui_translation_upload(
            self.app, f)
        self.assertEqual(translations["fra"]["home.start.demo"], "change_2")
        self.assertEqual(translations["en"]["home.start.demo"], "change_1")
Exemple #2
0
    def test_no_change(self):
        headers = (('translations', ('property', 'en')),)
        f = self._build_translation_download_file(headers)

        translations, error_properties, warnings = process_ui_translation_upload(self.app, f)
        self.assertEqual(dict(translations), {})
        self.assertEqual(len(error_properties), 0)
    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_translation(self):
        headers = (('translations', ('property', 'en', 'fra')),)
        # on an update to 2.31.0, the keys date.tomorrow, entity.sort.title,
        # activity.locationcapture.Longitude were no longer present in messages_en-2.txt
        # They were replaced by other randomly selected strings in that file.
        # Leaving this note here in case this issue comes up again. --B
        data = (('key.manage.title', 'wobble', ''),
                ('bulk.send.dialog.progress', 'wabble', ''),
                ('connection.test.access.settings', '', 'wibble'),
                ('bulk.send.dialog.progress', '', 'wubble'),
                ('home.start.demo', 'Ding', 'Dong'),
                ('unknown_string', 'Ding', 'Dong'))

        f = self._build_translation_download_file(headers, data)
        translations, error_properties, warnings = process_ui_translation_upload(self.app, f)

        self.assertEqual(
            dict(translations),
            {
                u'en': {
                    u'key.manage.title': u'wobble',
                    u'bulk.send.dialog.progress': u'wabble',
                    u'home.start.demo': u'Ding',
                    u'unknown_string': u'Ding',
                },
                u'fra': {
                    u'connection.test.access.settings': u'wibble',
                    u'bulk.send.dialog.progress': u'wubble',
                    u'home.start.demo': u'Dong',
                    u'unknown_string': u'Dong',
                }
            }

        )
        self.assertEqual(len(error_properties), 0)
        # There should be a warning that 'unknown_string' is not a CommCare string
        self.assertEqual(len(warnings), 1, warnings)

        # test existing translations get updated correctly
        data = (('home.start.demo', 'change_1', 'change_2'))
        f = self._build_translation_download_file(headers, data)
        translations, error_properties, warnings = process_ui_translation_upload(self.app, f)
        self.assertEqual(translations[u"fra"][u"home.start.demo"], u"change_2")
        self.assertEqual(translations[u"en"][u"home.start.demo"], u"change_1")
    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'])
Exemple #9
0
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
            app.translations = dict(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' if toggles.APP_MANAGER_V2.enabled(
        request.user.username) else 'app_languages'
    return HttpResponseRedirect(reverse(view_name, args=[domain, app_id]))
Exemple #10
0
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
            if isinstance(app, LinkedApplication):
                app.linked_app_translations.update(dict(trans_dict))
            app.translations.update(dict(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 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
            app.translations = dict(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!"))

    return HttpResponseRedirect(reverse('app_languages', 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'])