Multiple qrc files
-
We've just split our code into two projects. One project is the kernel or engine code that doesn't do GUI which is build into a static library. The other is the GUI code which is built to an executable.
The GUI project has a set of ts files and "translations.qrc" that looks like:
<!DOCTYPE RCC><RCC version="1.0"> <qresource prefix="i18n"> <file>DSS.ca.qm</file> <file>DSS.cs.qm</file> <file>DSS.de.qm</file> <file>DSS.en.qm</file> : </qresource> </RCC>
The kernel project has ts filenames starting with DSSKernel. Can we have a qrc file in that project with (I assume) a different name than "translations" that looks like:
<!DOCTYPE RCC><RCC version="1.0"> <qresource prefix="i18n"> <file>DSSKernel.ca.qm</file> : </qresource> </RCC>
OR
Do we neeed to modify translations.qrc so that it looks like:
<!DOCTYPE RCC><RCC version="1.0"> <qresource prefix="i18n"> <file>DSS.ca.qm</file> <file>DSS.cs.qm</file> <file>DSS.de.qm</file> <file>DSS.en.qm</file> : <file>../../DSSKernel/i18n/DSSKernel.ca.qm</file> </qresource> </RCC>
When we load the languages, can we "wild card" the names of the files to load? e.g.
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); }
So that both DSS and DSSKernel qm files are picked up?
Many thanks
David -
We've just split our code into two projects. One project is the kernel or engine code that doesn't do GUI which is build into a static library. The other is the GUI code which is built to an executable.
The GUI project has a set of ts files and "translations.qrc" that looks like:
<!DOCTYPE RCC><RCC version="1.0"> <qresource prefix="i18n"> <file>DSS.ca.qm</file> <file>DSS.cs.qm</file> <file>DSS.de.qm</file> <file>DSS.en.qm</file> : </qresource> </RCC>
The kernel project has ts filenames starting with DSSKernel. Can we have a qrc file in that project with (I assume) a different name than "translations" that looks like:
<!DOCTYPE RCC><RCC version="1.0"> <qresource prefix="i18n"> <file>DSSKernel.ca.qm</file> : </qresource> </RCC>
OR
Do we neeed to modify translations.qrc so that it looks like:
<!DOCTYPE RCC><RCC version="1.0"> <qresource prefix="i18n"> <file>DSS.ca.qm</file> <file>DSS.cs.qm</file> <file>DSS.de.qm</file> <file>DSS.en.qm</file> : <file>../../DSSKernel/i18n/DSSKernel.ca.qm</file> </qresource> </RCC>
When we load the languages, can we "wild card" the names of the files to load? e.g.
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); }
So that both DSS and DSSKernel qm files are picked up?
Many thanks
David@Perdrix You can use multiple qrc files, you just have to make sure they are added to each project where they are needed, and that you don't have naming conflicts in single resources.
You may want to add aliases to your files so you can have a consistent naming scheme when accessing resources. -
We've just split our code into two projects. One project is the kernel or engine code that doesn't do GUI which is build into a static library. The other is the GUI code which is built to an executable.
The GUI project has a set of ts files and "translations.qrc" that looks like:
<!DOCTYPE RCC><RCC version="1.0"> <qresource prefix="i18n"> <file>DSS.ca.qm</file> <file>DSS.cs.qm</file> <file>DSS.de.qm</file> <file>DSS.en.qm</file> : </qresource> </RCC>
The kernel project has ts filenames starting with DSSKernel. Can we have a qrc file in that project with (I assume) a different name than "translations" that looks like:
<!DOCTYPE RCC><RCC version="1.0"> <qresource prefix="i18n"> <file>DSSKernel.ca.qm</file> : </qresource> </RCC>
OR
Do we neeed to modify translations.qrc so that it looks like:
<!DOCTYPE RCC><RCC version="1.0"> <qresource prefix="i18n"> <file>DSS.ca.qm</file> <file>DSS.cs.qm</file> <file>DSS.de.qm</file> <file>DSS.en.qm</file> : <file>../../DSSKernel/i18n/DSSKernel.ca.qm</file> </qresource> </RCC>
When we load the languages, can we "wild card" the names of the files to load? e.g.
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); }
So that both DSS and DSSKernel qm files are picked up?
Many thanks
David@Perdrix said in Multiple qrc files:
Can we have a qrc file in that project with (I assume) a different name than "translations" that looks like:
Multiple qrc files are not a problem for Qt. You should just make sure that you don't have the same file names in different qrc files. This is not the case in your example.
@Perdrix said in Multiple qrc files:
So that both DSS and DSSKernel qm files are picked up?
You cannot use a wildcard for this. Wildcards are usually resolved by the command line. So, you would need explicit code in any application (Qt or not) to resolve wildcards. However, the documentation for QTranslator talks about multiple translations:
Multiple translation files can be installed in an application. Translations are searched for in the reverse order in which they were installed, so the most recently installed translation file is searched for translations first and the earliest translation file is searched last. The search stops as soon as a translation containing a matching string is found.
So, you need to manually install both translation files to use them. The origin (i.e. two different qrc files) does not matter to QTranslator.