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

imagewriter: Use QCoreApplication::translate #805

Merged
merged 2 commits into from
Feb 6, 2024

Conversation

tdewey-rpi
Copy link
Collaborator

tr() is not safe for strings that you move between contexts, as it fails to provide a mechanism for specifying the context of the string.

Regenerate the translation files, and use QCoreApplication to locate the real translations.

Additionally, bodge a race condition between translator replacement and OS list fetching, by marking the OS list as something to be re-calculated on a translator change.

Fixes #799

tr() is not safe for strings that you move between contexts,
as it fails to provide a mechanism for specifying the context
of the string.

Regenerate the translation files, and use QCoreApplication to locate
the real translations.

Additionally, bodge a race condition between translator replacement
and OS list fetching, by marking the OS list as something to be
re-calculated on a translator change.

Fixes raspberrypi#799
@lurch
Copy link
Contributor

lurch commented Feb 6, 2024

Apologies if this is a stupid question, but how do you identify which strings "you move between contexts" ? (and therefore where you need to use QApplication::translate rather than just tr ?)

@tdewey-rpi
Copy link
Collaborator Author

Apologies if this is a stupid question, but how do you identify which strings "you move between contexts" ? (and therefore where you need to use QApplication::translate rather than just tr ?)

Unfortunately as I've mentioned the tooling doesn't help here. It's down to the individual developer to notice they are moving a translatable string, and annotate the new location with the previous context.

@lurch
Copy link
Contributor

lurch commented Feb 6, 2024

Ahhh, I misunderstood - I thought you were talking about the strings moving between different contexts at runtime, rather than simply the translatable strings being moved to a different "context" (i.e. file) in the source-code 🙂

@tdewey-rpi
Copy link
Collaborator Author

Ahhh, I misunderstood - I thought you were talking about the strings moving between different contexts at runtime, rather than simply the translatable strings being moved to a different "context" (i.e. file) in the source-code 🙂

Were it so simple! Contexts are logical units inside the source tree - typically tied to a QObject name, but I can't see any reason you couldn't have arbitrary ones. Moving things to arbitrary named contexts might prove more durable longer-term.

@lurch
Copy link
Contributor

lurch commented Feb 6, 2024

Moving things to arbitrary named contexts might prove more durable longer-term.

I guess that would also allow you to re-organise the translatable strings into groupings that make more (logical) sense for the people doing the translations, rather than simply being grouped depending on where those strings appear in the source code? Does the qml-side of this whole translation-shenanigans also allow the use of arbitrary named contexts?
(although for a relatively simple application like RPi Imager, there might not be enough translatable text to warrant re-organising the translations. Sorry, went off on a bit of a side-tangent...)

@tdewey-rpi
Copy link
Collaborator Author

Yes, that's one of the advantages I can see.

qml does offer a similar context-selecting translation function: https://doc.qt.io/qt-6/qml-qtqml-qt.html#qsTranslate-method

@tdewey-rpi tdewey-rpi merged commit 38ea837 into raspberrypi:qml Feb 6, 2024
@tdewey-rpi tdewey-rpi deleted the bugs/799 branch February 6, 2024 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] C++ tr() strings are not translated
3 participants