Unsolved Translation approach for non-gui application with auto-generated code parts
I'am developing a framework that consists of several qt-based backend libraries without a gui (frontend will follow later).
The applications, that use those libraries contain a lot of sourcecode, which will be generated by a 3rd party code-preprocessor.
In case those auto generated code modules contain strings (they do a lot), I want the code-generator to generate translation files for them, on a per module basis.
What would be the workflow to get those translation files loaded at runtime for the corresponding source modules.
Example (just what I think it should look like):
Code generator provides:
Backend library contains a
fooLoader, which does stuff with the autogenerated source code parts.
fooLoaderwill have a
QString giveMeALocalizedString(someStringIndex)-method which I can use to access strings at runtime. That probably would have to lookup the
fooLoaderwill have a
setLanguage(languageDescriptor)-method that shall switch the used language for it at runtime.
The tutorials for QT I found so far for internationalization only cover cases where you have a Gui application and translate your whole application from one point on using a qtranslator attached to the
I feel that my needs are not covered by such an approach. But I have also not that much experience with qt's translation system.
Do my above ideas sound ok? If yes, how should I implement the functionality in my application, my auto generated code and my consuming backend libs?
Thank you in advance
Christian Ehrlicher Lifetime Qt Champion last edited by
It's QCoreApplication::installTranslator - the QTranslator example is a little bit misleading here since it uses a QApplication: https://doc.qt.io/qt-5/qtranslator.html#details
Thanks, so a QTranslator on the application level is the only possibility and users have to load all the available qm files delivered with the library manually in their application?
Christian Ehrlicher Lifetime Qt Champion last edited by Christian Ehrlicher
It's the same what Qt is doing - they're providing the qm files but you have to load them by your own.