-
-
Notifications
You must be signed in to change notification settings - Fork 394
fix: restore translate_formatted()
method
#830
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No issues besides what was mentioned before
tagstudio/src/qt/translations.py
Outdated
) | ||
return text | ||
|
||
def translate_formatted(self, key: str, **kwargs) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest renaming this to formatted as outlined in the comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was looking forward to doing this as well
@@ -27,6 +27,21 @@ def change_language(self, lang: str): | |||
self._lang = lang | |||
self._strings = self.__get_translation_dict(lang) | |||
|
|||
def __format(self, text: str, **kwargs) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest porting the improvements from #829
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would change it to this (plus an import for defaultdict
at the top):
def __format(self, text: str, *args, **kwargs) -> str:
try:
return text.format(*args, **kwargs)
except (KeyError, ValueError):
logger.error(
"[Translations] Error while formatting translation.",
text=text,
kwargs=kwargs,
language=self._lang,
)
params: defaultdict = defaultdict(lambda: "{missing_key}")
params.update(kwargs)
return super().format_map(params)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 499b548
…ev#830) * fix: restore `translate_formatted()` method * fix: set "Create & Add" button text * refactor: rename "translate_formatted" to "format" * translations: replace invalid format key names with "{unknown_key}"
Summary
This PR restores the use of the
translate_formatted()
method (now refactored as justformat()
) that was removed in #817 in order to catch KeyErrors raised from invalid formatting keys being added in the translation files and passed to.format()
calls.Tasks Completed
Tested on:
Tested for:
Closes [Bug]: Switching translations causes error on program start #827, along with the fixed translations in Translations update from Hosted Weblate #826.