Skip to content

Commit

Permalink
Fix updating plural translations.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub Skiepko committed May 12, 2017
1 parent 8273e8b commit 9022c52
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
10 changes: 5 additions & 5 deletions dila/data/translated_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ def set_translated_string(language_code, pk, *, plural_translations=None, **kwa
for key, value in kwargs.items():
setattr(translated_string, key, value)
if plural_translations:
translated_string.plural_translated_strings = PluralTranslatedString(
few=plural_translations.few,
many=plural_translations.many,
other=plural_translations.other,
)
if not translated_string.plural_translated_strings:
translated_string.plural_translated_strings = PluralTranslatedString()
translated_string.plural_translated_strings.few=plural_translations.few,
translated_string.plural_translated_strings.many=plural_translations.many,
translated_string.plural_translated_strings.other=plural_translations.other,
engine.session.flush()
39 changes: 37 additions & 2 deletions tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def test_fetching_one_plural_untranslated_string(db_connection):
)


def test_fetching_one_translated_string(db_connection):
def test_fetching_one_plural_translated_string(db_connection):
data.add_language('polish', 'pl')
resource_pk = data.add_resource('r').pk
string_pk = data.add_or_update_base_string(resource_pk, 'one x', plural='%d xs', comment='comment', context='ctx')
Expand Down Expand Up @@ -181,7 +181,7 @@ def test_fetching_one_translated_string(db_connection):
)


def test_fetching_one_plural_translated_string(db_connection):
def test_fetching_one_translated_string(db_connection):
data.add_language('polish', 'pl')
resource_pk = data.add_resource('r').pk
string_pk = data.add_or_update_base_string(resource_pk, 'x', comment='comment', context='ctx')
Expand Down Expand Up @@ -221,6 +221,41 @@ def test_updating_one_translated_string(db_connection):
)


def test_updating_one_plural_translated_string(db_connection):
data.add_language('polish', 'pl')
resource_pk = data.add_resource('r').pk
string_pk = data.add_or_update_base_string(resource_pk, 'one x', plural='%d xs', comment='comment', context='ctx')
data.set_translated_string('pl', string_pk, translation='jeden x', translator_comment='tcomment',
plural_translations=dila.application.structures.PluralTranslations(
few='%d x',
many='%d x',
other='%d x',
))
data.set_translated_string('pl', string_pk, translation='jeden iks', translator_comment='tcomment',
plural_translations=dila.application.structures.PluralTranslations(
few='%d iksy',
many='%d iksów',
other='%d iksów',
))
preserved_string = data.get_translated_string('pl', string_pk)
data.shutdown_session()
assert preserved_string == dila.application.structures.TranslatedStringData(
pk=string_pk,
base_string='one x',
plural='%d xs',
context='ctx',
translation='jeden iks',
comment='comment',
translator_comment='tcomment',
resource_pk=resource_pk,
plural_translations=dila.application.structures.PluralTranslations(
few='%d iksy',
many='%d iksów',
other='%d iksów',
),
)


def test_translating_string_into_multiple_languages(db_connection):
data.add_language('polish', 'pl')
data.add_language('dutch', 'nl')
Expand Down

0 comments on commit 9022c52

Please sign in to comment.