Nitrokey / nitrokey-app

Nitrokey's Application (Win, Linux, Mac)
https://www.nitrokey.com/
287 stars 55 forks source link

ui/mainwindow: Don't call tr() and use QT_TRANSLATE_NOOP on global objects. #348

Closed comio closed 6 years ago

comio commented 6 years ago

…nstead call when required and we are sure that translation engine is configured.

The main issue is that we call tr() before that translation is configured, then we cannot translate these string after that.

szszszsz commented 6 years ago

Hi! Thank you for the PR! I see the issue. Indeed some strings are not translated due to capturing translated value before it is configured (I thought during the beta/final tests that we miss some translations and not noticed the real cause). Solving it through splitting translation keys' and using tr()'s later would fix this, but make the translation work harder, since the keys are detected by tr() functions. We could wrap it to some macro (so it could be find-able), but this would introduce issue with translation context. As far as I see, the best option is moving the translations initialization to MainWindow constructor (or some helper entity). Will check it and let you know.

comio commented 6 years ago

How already you know I'm not a qt developer. Is there any best practice guide how write application with translation support?

szszszsz commented 6 years ago

Sure, there is one on the official site: https://doc.qt.io/qt-5/i18n-source-translation.html. Perhaps the minimum change for this PR to make it work is to use QT_TR_NOOP() and QT_TRANSLATE_NOOP() macros to mark the text for translation and see, would the existing translations be used or not. If you are interesting in correcting/testing this then it would be great! Otherwise I will get here once clearing some other tasks first.

comio commented 6 years ago

Something like this?

szszszsz commented 6 years ago

Exactly! Now to update the translations running lupdate nitrokey-app-qt5.pro is required. You could then easily git diff the changes on *.ts files and see, whether they are marked as missing or not.

comio commented 6 years ago

git diff is clean (I already checked before to push).