This question is about best practices. I am currently sticking my head into the Qt internationalization system.
What do you use as source text in your Qt application?
Background: Let's say I use english as source language and have 5 more translation files for my application. Now it turns out that the english text is not well formulated and needs to be changed. Will I run into the problem that the other 5 translations "lose" this translation then after the change, due to the heuristic approach lupdate uses? Or do you typically see this as a benefit since the translations should then be reviewed as well?
Very interested in your experiences!
Greetings,
Fabian
Yes english even if it is not your native. It's AFAIK the only language in the world which is fully expressible with only 7-bit ASCII, hence not requiring you to juggle with source code encoding. It is also the universally understood language for human translators. However "writing" in source code means enclosing everything in tr(""), hence enabling prospective translations. In case there is no translation (no installTranslator()
call), tr()
is a no-op so the text will be displayed. The same applies for a missing translation of installed translator. So your translation doesn't need to be finished, untranslated texts will be displayed in your "source code" english.
"English translation" is good for one little used feature: instead of stupid "1 message(s) received" you can have correct texts for ANY plural and Qt will do it for you without any coding. Just use tr() overload with using the last numeric parameter and provide all pluralized variants in your TS file, per parameter n
. No more endless if-else spaghetti and ternary operators.
If you aim for multiple languages (i.e. not only english and something else) then setting up an "english translation" is also good for code consistency. English is treated just as another language and you switch to it the same way as any other language. If you won't have an english translation, you would need to uninstall translator to fall back to it, and then install again for any other language. Not that it is a big problem for Qt, it's only about the code consistency. You can do a map of [language,translator] and don't need to treat english specially.
No ids. You will find yourself developing naming conventions just to not overlap your own translations from different parts of the code. You will need to provide the mapping of ids to the readable strings to your human translators anyway. Regarding the fear of "losing the translation". If the original text changes significantly, then forcing a retranslation is a good thing. If it does not change that much, then Linguist will most probably retain it because TS file keeps a source file line too.
When in doubt, read Qt's internationalization guide
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With