[Interest] lrelease before compiling qrc

Petric Frank pfrank at gmx.de
Tue Nov 7 20:12:37 CET 2023


Hello,

Am Dienstag, 7. November 2023, 15:54:07 CET schrieb Robert Hairgrove via
Interest:
> On 07.11.23 14:59, Petric Frank wrote:
> > Hello,
> >
> > in my app i have translation files. I added them to the qrc-file because i
> >
> > want to load the translations from resource:
> >          <file>app-de_DE.qm</file>
> >          <file>app-en_US.qm</file>
> >
> > They are are generated from *.ts files. In *.pro i added
> >
> >          CONFIG += lrelease
> >          TRANSLATIONS = app-de_DE.ts \
> >
> >                         app-en_US.ts
> >
> > The problem is when i build the app it breaks at compiling the qrc-file:
> >    make: *** No rule to make target '../app/app-de_DE.qm', needed by
> >
> > 'qrc_app.cpp'.  Stop.
> >
> > I think that the lrelease step comes too late.
> >
> > So the question is how to overcome this ?
> > For example executing lrelease earlier - maybe at first - at make run. How
> > i have to modify the *.pro file ?
> >
> > kind regards
> >
> >    Petric
>
> I always thought that 'lupdate' and 'lrelease' needed to run as external
> applications? Adding it to the CONFIG variable will most likely not do
> anything.

They are documented in the qmake manual.

I found the solution after more digging into the qmake variables documentation
and some tests.

Do not manually add the qm-files to the qrc file. Instead add following to the
*.pro file:

     CONFIG += lrelease embed_translations

which will embed the compiled translations into the resource prefixed by "/
i18n/". This prefix can changed by the variable QM_FILES_RESOURCE_PREFIX.

In the code you can access the file under ":/i18n/app-de_DE.pm".

Hope that help others.

regards
  Petric






More information about the Interest mailing list