Using translatable strings in a static library
-
Am I correct in thinking that it isn't possible to build translatable strings into a static library such that they will be picked up by any executable or dynamic library that is built with that static library?
If that is the case how should this be handled? Should the static library project be set up to create .ts and .qm files that a .qrc file in the project for the executable picks up?
ALternatively is there a way to run lupdate etc against an entire Visual Studio solution or group of VS projects?
If the above aren't the best way to do it, please let me know what I should be doing.
Thank you
David -
Am I correct in thinking that it isn't possible to build translatable strings into a static library such that they will be picked up by any executable or dynamic library that is built with that static library?
If that is the case how should this be handled? Should the static library project be set up to create .ts and .qm files that a .qrc file in the project for the executable picks up?
ALternatively is there a way to run lupdate etc against an entire Visual Studio solution or group of VS projects?
If the above aren't the best way to do it, please let me know what I should be doing.
Thank you
David@Perdrix said in Using translatable strings in a static library:
Am I correct in thinking that it isn't possible to build translatable strings into a static library such that they will be picked up by any executable or dynamic library that is built with that static library?
No, because there is nothing as "translation strings" somewhere - there are 'strings' which should be translated. In Qt tihs is done with the QObject::tr() function. But I don't see why one of them should not work in a static library.
When you want to use a qrc file in a static lib then you should follow the documentation: https://doc.qt.io/qt-6/resources.html#explicit-loading-and-unloading-of-embedded-resources
-
@Perdrix said in Using translatable strings in a static library:
Am I correct in thinking that it isn't possible to build translatable strings into a static library such that they will be picked up by any executable or dynamic library that is built with that static library?
No, because there is nothing as "translation strings" somewhere - there are 'strings' which should be translated. In Qt tihs is done with the QObject::tr() function. But I don't see why one of them should not work in a static library.
When you want to use a qrc file in a static lib then you should follow the documentation: https://doc.qt.io/qt-6/resources.html#explicit-loading-and-unloading-of-embedded-resources
@Christian-Ehrlicher Translatable strings == stuff passed to tr()
So should I simply add a file called (e.g.) kernel_translations.qrc to the static library project and list all the kernel.<language>.qm files for the static library in that file?
Then, if I read the link you gave correctly I add:
Q_INIT_RESOURCE(kernel_translations);
When I come to load the translations, I currently do this to pick up the executables translations:
translatorFileName = QLatin1String("DSS."); translatorFileName += language; qDebug() << "app translator filename: " << translatorFileName; // // Install the language if it actually exists. // if (theAppTranslator.load(translatorFileName, ":/i18n/")) { app.installTranslator(&theAppTranslator); }
How should I modify that to also load the ts files starting with "kernel"?
Many thanks
-
@Christian-Ehrlicher Translatable strings == stuff passed to tr()
So should I simply add a file called (e.g.) kernel_translations.qrc to the static library project and list all the kernel.<language>.qm files for the static library in that file?
Then, if I read the link you gave correctly I add:
Q_INIT_RESOURCE(kernel_translations);
When I come to load the translations, I currently do this to pick up the executables translations:
translatorFileName = QLatin1String("DSS."); translatorFileName += language; qDebug() << "app translator filename: " << translatorFileName; // // Install the language if it actually exists. // if (theAppTranslator.load(translatorFileName, ":/i18n/")) { app.installTranslator(&theAppTranslator); }
How should I modify that to also load the ts files starting with "kernel"?
Many thanks
@Perdrix said in Using translatable strings in a static library:
How should I modify that to also load the ts files starting with "kernel"?
The same way - there is no difference, the only thing you have to do for static app is, as the doc says and you do - init the resources with Q_INIT_RESOURCE