def test_post_plural_translation_form(set_translated_string, get_translated_string, authenticated_flask_client): get_translated_string.return_value = structures.TranslatedStringData( pk='34', base_string='%d option', plural='%d options', translation='%d alternatywa', comment='comment', translator_comment='translator_comment', context='context', resource_pk='1', plural_translations=structures.PluralTranslations( few='%d alternatywy', many='%d alternatyw', other='%d alternatyw', ), ) response = authenticated_flask_client.post('/lang/pl/edit/34/', data={ 'translation_one': '%d opcja', 'translation_few': '%d opcje', 'translation_many': '%d opcji', 'translation_other': '%d opcji', 'translator_comment': 'new-translator-comment', }) assert response.status_code == 302 assert response.location == 'http://localhost/lang/pl/res/1/' response = authenticated_flask_client.get(response.location) assert 'Translation changed' in response.data.decode() set_translated_string.assert_called_with('pl', '34', translation='%d opcja', translator_comment='new-translator-comment', plural_translations=structures.PluralTranslations( few='%d opcje', many='%d opcji', other='%d opcji', ))
def test_get_plural_translation_form(get_translated_string, authenticated_flask_client): get_translated_string.return_value = structures.TranslatedStringData( pk='34', base_string='%d option', plural='%d options', translation='%d opcja', comment='comment', translator_comment='translator_comment', context='context', resource_pk='1', plural_translations=structures.PluralTranslations( few='%d opcje', many='%d opcji', other='%d opcji', ), ) response = authenticated_flask_client.get('/lang/pl/edit/34/') assert re.search('<textarea class="[^"]*" cols="[^"]*" id="translation_one" name="translation_one" rows="[^"]*">' '%d opcja</textarea>', response.data.decode()) assert re.search('<textarea class="[^"]*" cols="[^"]*" id="translation_few" name="translation_few" rows="[^"]*">' '%d opcje</textarea>', response.data.decode()) assert re.search('<textarea class="[^"]*" cols="[^"]*" id="translation_many" name="translation_many" rows="[^"]*">' '%d opcji</textarea>', response.data.decode()) assert re.search('<textarea class="[^"]*" cols="[^"]*" id="translation_other" name="translation_other" rows="[^"]*">' '%d opcji</textarea>', response.data.decode()) assert re.search('<textarea class="[^"]*" cols="[^"]*" id="translator_comment" name="translator_comment" ' 'rows="[^"]*">translator_comment</textarea>', response.data.decode()) assert 'action="/lang/pl/edit/34/"' in response.data.decode()
def test_upload_po_file_with_plural_translations(set_translated_string, add_or_update_base_string): add_or_update_base_string.return_value = 'string_pk' application.upload_po_file('1', test_plural_po, translated_language_code='pl') assert add_or_update_base_string.mock_calls == [ mock.call( '1', '%d option', plural='%d options', context=None, comment='Programmer comment', ) ] assert set_translated_string.mock_calls == [ mock.call('pl', 'string_pk', translation='%d opcję', translator_comment='', plural_translations=structures.PluralTranslations( few='%d opcje', many='%d opcji', other='%d opcji', )) ]
def get_translated_string_kwargs(self): return { 'translation': self.data['translation_one'], 'plural_translations': structures.PluralTranslations( few=self.data['translation_few'], many=self.data['translation_many'], other=self.data['translation_other'], ), **super().get_translated_string_kwargs(), }
def translated_string_kwargs(self): one = self.entry.msgstr or self.entry.msgstr_plural.get(0, '') few = self.entry.msgstr_plural.get(1, one) many = self.entry.msgstr_plural.get(2, few) other = self.entry.msgstr_plural.get(3, many) return { 'translation': one, 'plural_translations': structures.PluralTranslations( few=few, many=many, other=other, ), **super().translated_string_kwargs, }
def test_get_po_file_with_plural_translations(get_po_metadata, get_translated_strings): get_translated_strings.return_value = [ structures.TranslatedStringData( pk='34', base_string='%d option', plural='%d options', translation='%d opcję', comment='Programmer comment', translator_comment='', context='', resource_pk='1', plural_translations=structures.PluralTranslations( few='%d opcje', many='%d opcji', other='%d opcji', ), ) ] get_po_metadata.return_value = {} result = application.get_po_file('pl', '1') assert result == test_result_plural_po
def empty_plural_translations_data(self): if self.plural: return structures.PluralTranslations(few='', many='', other='') else: return None
def as_data(self): return structures.PluralTranslations( few=self.few, many=self.many, other=self.other, )