Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset the has error flag on po import #507

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions wagtail_localize/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,7 @@ def import_po(
string_translation.tool_name = tool_name
string_translation.last_translated_by = user
string_translation.updated_at = timezone.now()
string_translation.has_error = False # reset the error flag.
string_translation.save()

except TranslationContext.DoesNotExist:
Expand Down
42 changes: 42 additions & 0 deletions wagtail_localize/tests/test_translation_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,48 @@ def test_import_po_with_invalid_translation_id(self):
# Should delete both the translations
self.assertFalse(StringTranslation.objects.exists())

def test_import_po_with_valid_string_clears_has_error_flag(self):
translation = StringTranslation.objects.create(
translation_of=String.objects.get(data="This is some test content"),
context=TranslationContext.objects.get(path="test_charfield"),
locale=self.fr_locale,
data=(
"This value is way too long for a char field so it should fail to publish and add an error to the translation. "
"This value is way too long for a char field so it should fail to publish and add an error to the translation. "
"This value is way too long for a char field so it should fail to publish and add an error to the translation."
),
has_error=True,
field_error="Ensure this value has at most 255 characters (it has 329).",
)
self.assertTrue(translation.has_error)

po = polib.POFile(wrapwidth=200)
po.metadata = {
"POT-Creation-Date": str(timezone.now()),
"MIME-Version": "1.0",
"Content-Type": "text/plain; charset=utf-8",
"X-WagtailLocalize-TranslationID": str(self.translation.uuid),
}

po.append(
polib.POEntry(
msgid="This is some test content",
msgctxt="test_charfield",
msgstr="Contenu de test",
)
)

warnings = self.translation.import_po(po)
self.assertEqual(warnings, [])

translation.refresh_from_db()
self.assertEqual(
translation.context, TranslationContext.objects.get(path="test_charfield")
)
self.assertEqual(translation.locale, self.fr_locale)
self.assertEqual(translation.data, "Contenu de test")
self.assertFalse(translation.has_error)

def test_warnings(self):
String.from_value(
self.en_locale,
Expand Down