0

I am currently working on a Linux-native GUI for 7-zip and have already completed the menu and toolbar. In them are of course a lot of text snippets that I translate using gettext. It is possible to switch the language of gettext live (just call the .install() method of the wanted translation), but I am stuck on how to update the labels on all the buttons to reflect that change of language in the background, instead of just having new dialogs be in the newly-selected language until the program is restarted.

I hope what I want is possible with not-too-much effort. Otherwise I could also switch to PyQt's built-in translation mechanism, but I'd like to keep using gettext.

13
  • This question is similar to stackoverflow.com/q/53349623, but I asked this seperately because I don't use PyQt's built-in translation mechanisms unlike the author of the above-mentioned question. Commented Aug 2, 2024 at 8:17
  • 2
    Switching languages with gettext doesn't look like much fun, even for a pure Python project, and the problems are only going to multiply for a GUI application with an event-loop. Qt's i18n support is a fully integrated solution. It's probably not perfect, and PyQt's implementation isn't complete, but it's hard to see how a hand-rolled solution could be any better - for one thing, how will gettext handle all the built-in strings supplied by Qt? Commented Aug 2, 2024 at 12:30
  • @ekhumoro So in other words, you recommend me to use PyQt's translation mechanism? Commented Aug 2, 2024 at 17:57
  • 1
    Well, you obviously have to write it yourself, as stated in the answer to the question you linked to above. Did you read the code? There's no magic bullet here. Neither Qt nor gettext caches the original strings, so there's no way to undo a previous translation. You need to set the new translator, and then reapply all your retranslateUI slots. This could be done by connecting them to a custom signal emitted by a handler that watches for language-change events. Commented Aug 2, 2024 at 22:07
  • 1
    @Lampe2020, fair enough. But I think that there is no easy way to achieve that. You must iterate over all widgets and call setText() on them. From Qt's point of view, it just receives a string as the label, when you construct the icons. Alternatively, force a restart of the application after a language switch. Commented Aug 18, 2024 at 21:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.