Skip to content

Commit

Permalink
Bugfix: identical translations aren't treated as missing (#1319)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazet authored Oct 10, 2024
1 parent 09af5c0 commit 31b2943
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions artemis/reporting/export/translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,26 @@ class TranslationRaiseException(gettext.GNUTranslations):
"""This class is used instead of GNUTranslations and raises exception when a message is not found,
so that we don't allow untranslated strings into the messages."""

messages_allowed_to_be_the_same_after_translation = ["time-based SQL injection"]
class _TranslationAlwaysRaiseException(gettext.GNUTranslations):
def gettext(self, message: str) -> str:
raise TranslationNotFoundException(f"Unable to translate '{message}'")

def ngettext(self, *args: Any) -> Any:
raise NotImplementedError()

def pgettext(self, *args: Any) -> Any:
raise NotImplementedError()

def npgettext(self, *args: Any) -> Any:
raise NotImplementedError()

def __init__(self, fp=None): # type: ignore
super().__init__(fp)

self.add_fallback(self._TranslationAlwaysRaiseException())

def gettext(self, message: str) -> str:
message_translated = super().gettext(message)
if (
message == message_translated
and message not in TranslationRaiseException.messages_allowed_to_be_the_same_after_translation
):
raise TranslationNotFoundException(f"Unable to translate '{message}'")
return message_translated

def ngettext(self, *args: Any) -> Any:
Expand Down

0 comments on commit 31b2943

Please sign in to comment.