Unsolved When using id based translations, how to show the engineering english text, if no translator has been installed
-
I try to change my libraries application from using plain
QString
s for translations to using text ids instead.
To get used to the system, I started by writing a very simple example app, where I want to see the effects:int main(int argc, char **argv) { QCoreApplication app(argc, argv); QTranslator trans(&app); qDebug() << "locale: " << QLocale::system().name(); qDebug() << trans.load("transtest_" + QLocale::system().name()); qDebug() << QCoreApplication::installTranslator(&trans); //% "Blahblahblah" QString Text = qtTrId("blablubbid"); qDebug() << Text; return app.exec(); }
When I run that very example, it prints my translated text as expected. However, when I do not install the translator, it will not print the engineering english text
//% "Blahblahblah"
but instead prints the text id itself, which is not what I want.What am I doing wrong here?
Edit: After a bit of thinking I start to doubt that the id-based translations are only usable when you are sure that a translator is installed at application runtime. As I cannot guarantee that users of my libraries will really do load the
*.qm
files I provide and install an appropriate translator, it seems to make more sense to stay with the plain text translation system, so that you always have default strings in the library. If I am not wrong, this totally takes the "industrial strength" advantages of Id based translations away for good. At least for developing shared libraries.Thanks
-
@devjb said in When using id based translations, how to show the engineering english text, if no translator has been installed:
However, when I do not install the translator, it will not print the engineering english text //% "Blahblahblah"
When there is no translator - how should it be possible to get to 'Blahblahblah' at all?
-
@christian-ehrlicher said in When using id based translations, how to show the engineering english text, if no translator has been installed:
When there is no translator - how should it be possible to get to 'Blahblahblah' at all?
Because it is not explicietly stated in the documentation:
The "Engineering English" text that you see in the user interface for development builds is indicated with a //% comment. If you do not include this, the text ID will be shown in the user interface. This is especially important when you have texts with parameters. The //% comment needs to include the parameters indicators in the string. For example, //% "Number of files: %1"
I assumed that somehow the moc would take care of it. Again, my opinion is that the id based system is only useful on your own application level. Not for shared libraries. Because it requires manual action from users that develop applications on top of those libs. In the meantime I also noticed, that the Qt framework itself, despite containing a lot of strings and thus matching the description
This requires a little more work for the user interface developers but makes it much easier to manage large numbers of translated texts.
does not use the id based system at all.
I like the id based approach a lot, but I cannot deliver libraries to customers when there is a chance that they see cryptic text ids in their debug outputs. Default strings are a must have. Furthermore, imagine the situation when you want to have id based translations in your application but at the same time you want to use a translated qt framework, you are forced to mix plain text and text id approaches, since the framework is only using plain texts. And you have to load both id based and plain text
*.qm
files together. This is discouraged as well by the documentation.I will stay with the plain texts for now.
-
@devjb said in When using id based translations, how to show the engineering english text, if no translator has been installed:
I assumed that somehow the moc would take care of it
Moc has absolutely nothing to do with the translation.
You can init your translation for a library in a library_init() call and load the translation from resources if you want. But then every user has to call library_init() before using the lib. -
@devjb said in When using id based translations, how to show the engineering english text, if no translator has been installed:
the Qt framework itself, despite containing a lot of strings and thus matching the description
does not use the id based system at all.I think that's one strong advantage of the "string based" translations schema that Qt proposes. Even with no translator loaded, or missing .qm files the application/library can still display some "meaningful" string, the one used to do the query for a translation.
Regarding "Engineering English", if you check the example in the same documentation you pointed to, you'll see that //% comment actually ends up as the "source" field in the .ts file, see:
Text { id: backTxt; //: The back of the object, not the front //% "Back" //~ Context Not related to back-stepping text: qsTrId("id-back-not-front"); }
The example text-ID-based user interface text from above results in the following content in the .ts file:
<message id="id-back-not-front"> <source>Back</source> <extracomment>The back of the object, not the front</extracomment> <translation type="unfinished"></translation> <extra-Context>Not related to back-stepping</extra-Context>
And very important, that whole example assumes that you'll go through the full cycle: lupdate (create .ts files), manual translation via Linguist, lrelease (create .qm files), app installing translator so the value of the source field (in this case //% "Back" will display as the translation.
I'd suggest that you use a plain-text-based approach for translation of your library. Qt framework itself is a long time example it works fine.
I'd only recommend going with text-ID-base approach if you already have such translations using such schema (i.e. existing translations shared by lots of applications)