[Interest] Android: include and use the translation files of Qt (qt_*.qm)

René Hansen renehh at gmail.com
Mon Aug 19 10:30:24 CEST 2019


"You can use CONFIG += lrelease to automatically compile the files during
the build, and CONFIG += lrelease embed_translations to make them available
in The Qt Resource System."

Alternatively, you can just add the .qm files to a resource file yourself,
e.g. in the case where you want a different qrc path. I do the same, having
them at /translations/*.qm.

In-app you load them like so:

  QLocale defaultLocale;
  QTranslator app_translator;
  if (app_translator.load(defaultLocale, "your-app-name", "_",
":/translations"))
    app.installTranslator(&app_translator);
  else
    qDebug() << "Failed to load app translations, default 'en' will be
used.";

/René

On Mon, 19 Aug 2019 at 09:49, Alexander Dyagilev <alervdvcw at gmail.com>
wrote:

> Filed the bug...
> https://bugreports.qt.io/browse/QTBUG-77661
>
> On 8/19/2019 10:35 AM, Alexander Dyagilev wrote:
> > Hmm.... This QT_INSTALL_TRANSLATIONS is empty under Android config.
> >
> > However, it's defined for Windows/Mac/Desktop Linux.... Any help?
> >
> > On 8/19/2019 5:41 AM, Alexander Dyagilev wrote:
> >> Something like this?
> >>
> >> qt_qm_files.path = /assets/translations
> >> qt_qm_files.files += $$QT_INSTALL_TRANSLATIONS/qt_*.qm
> >> INSTALLS += qt_qm_files
> >>
> >> On 8/19/2019 5:39 AM, Alexander Dyagilev wrote:
> >>> Looks like I should use qmake's INSTALLS variable and install all
> >>> the required qt_*.qm files into assets folder?
> >>>
> >>> On 8/19/2019 5:36 AM, Alexander Dyagilev wrote:
> >>>> Hello,
> >>>>
> >>>> Is there a "good" way to achieve this?
> >>>>
> >>>> The only solution for know I'm thinking of is to manually copy all
> >>>> them into my project folder and include into resource files.
> >>>>
> >>>> This is not good because I'll have to store them in my repository
> >>>> and I'll have to update them every time I update Qt.
> >>>>
> >>>> What I want instead is to be able to tell qmake/androiddeployqt
> >>>> tools to add all these files automatically from Qt installation
> >>>> folder into my APK.
> >>>>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> https://lists.qt-project.org/listinfo/interest
>


-- 
Never fear, Linux is here.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20190819/73108c5b/attachment.html>


More information about the Interest mailing list