[SailfishDevel] QML translations don't work

Lukáš Karas lukas.karas at centrum.cz
Fri Mar 9 12:37:32 UTC 2018


Well, I am not familiar with Qt development in Python, but in C++ world, 
there is necessary to initialise translator before showing QML view... 

Try to look to these lines: 
https://github.com/Karry/osmscout-sailfish/blob/master/src/OSMScout.cpp#L147



  // install translator
  QTranslator translator;
  QLocale locale;
  if (translator.load(locale.name(),
           SailfishApp::pathTo("translations").toLocalFile())) {
    qDebug() << "Install translator for locale " 
             << locale << "/" << locale.name();
    app->installTranslator(&translator);
  }else{
    qWarning() << "Can't load translator for locale" 
            << locale << "/" << locale.name() <<
            "(" << SailfishApp::pathTo("translations").toLocalFile() << ")";
  }


Lukas

Dne čtvrtek 8. března 2018 22:14:48 CET Boris Pohler napsal(a):
> That's how it works with my program.
> 
> Just to be on the safe side, are the translation files in your rpm and in
> /usr/share/harbour-sailcash/translations on the device?
> 
> In your spec file in the given repo this information is missing in my
> opinion, or am I missing something?
> 
> Am Donnerstag, den 08.03.2018, 21:04 +0000 schrieb Yann Büchau:
> > Thanks Boris for the hint with setting the LANG variable. Although it
> > should rather be LANG=de_DE.utf8 :-) Unfortunately, this still doesn't
> > help with the QML translation problem. When I launch the app from the
> > grid (which definitely has the locale set because the Python translation
> > works), the QML ist not translated. Is it correct to have this?:
> > 
> > Label {
> > id: label
> > anchors.centerIn: parent
> > text: qsTr("Plain Cover")
> > }
> > 
> > If I run "strings" on the *.qm-files, both the translated and the original
> > texts appear. I really don't get what I am doing wrong... I tried both
> > creating the *.qm-files with msgfmt --qt and lconvert. No difference.
> > 
> > Any clue?
> > 
> > Regards,
> > 
> > Yann
> > 
> > Le Jeudi 8 mars 2018, Boris Pohler a écrit :
> > > Sorry, should be
> > > 
> > > export LANG=de
> > > 
> > > Am Donnerstag, den 08.03.2018, 21:42 +0100 schrieb Boris Pohler:
> > > > The behavior is normal and your directory structure is fine.
> > > > 
> > > > If you log in via ssh and want to start the program, the language is
> > > > not
> > > > set:
> > > > 
> > > > [nemo at Sailfish ~]$ locale
> > > > LANG=
> > > > LANGUAGE=
> > > > LC_CTYPE="POSIX"
> > > > LC_NUMERIC="POSIX"
> > > > LC_TIME="POSIX"
> > > > LC_COLLATE="POSIX"
> > > > LC_MONETARY="POSIX"
> > > > LC_MESSAGES="POSIX"
> > > > LC_PAPER="POSIX"
> > > > LC_NAME="POSIX"
> > > > IC_ADDRESS="POSIX"
> > > > IC_TELEPHONE="POSIX"
> > > > LC_MEASUREMENT="POSIX"
> > > > LC_IDENTIFICATION="POSIX"
> > > > LC_ALL=
> > > > 
> > > > Therefore, no language file can be loaded. For example, if you
> > > > manually
> > > > set
> > > > the
> > > > language with e. g.
> > > > 
> > > > export LANG=en
> > > > 
> > > > the German translation should be loaded afterwards.
> > > > 
> > > > Grüße
> > > > Boris
> > > > 
> > > > Am Donnerstag, den 08.03.2018, 18:21 +0000 schrieb Yann Büchau:
> > > > > Hey everyone,
> > > > > 
> > > > > I am finally hopping into developing Python-based apps for Sailfish.
> > > > > I
> > > > > am
> > > > > pretty amazed how easy it is actually. Being not so much of a gui
> > > > > guy, I
> > > > > like
> > > > > to do everything from CLI and by hand, not clicking stuff together.
> > > > > I am
> > > > > also
> > > > > more familiar with autotools that the QT build system. As a start I
> > > > > used
> > > > > the
> > > > > python-sample project from github/sailfishos. What I managed to do
> > > > > so
> > > > > far
> > > > > (gitlab.com/nobodyinperson/harbour-sailcash) is autotooling the rpm
> > > > > packaging
> > > > > (also on GitLab CI) without any interaction with the IDE, automated
> > > > > deployment
> > > > > to the device/emulator via ssh for quick development and Python
> > > > > gettext
> > > > > translation. All of this works wonderfully, except for the QML
> > > > > translation.
> > > > > I
> > > > > peeked at github/otsaloma/pan-transit and tried to replicate the
> > > > > folder
> > > > > structure, but the QML part just won't translate, no matter what
> > > > > translation
> > > > > function (qsTr, qsTrId, qsTranslate,QT_TR_NOOP [or whatever],
> > > > > etc...) I
> > > > > use.
> > > > > The Python part works flawlessly, similar to desktop apps or in
> > > > > general.
> > > > > However I noticed that when logged in via SSH, somehow none of the
> > > > > the
> > > > > LANG/locale environment variables are set which is a little annoying
> > > > > when
> > > > > starting the app from command line because no translation is
> > > > > performed.
> > > > > When
> > > > > launching the app from the grid, everything works.
> > > > > 
> > > > > Now my question is, what am I doing wrong so QML stuff won't
> > > > > translate?
> > > > > My
> > > > > QML
> > > > > is just the python-sample with some strings wrapped with qsTr(). Is
> > > > > the
> > > > > 
> > > > > "translations" folder placed correctly?:
> > > > > > rpm -ql harbour-sailcash
> > > > > 
> > > > > /usr/share/applications/harbour-sailcash.desktop
> > > > > /usr/share/harbour-sailcash/locale/de/LC_MESSAGES/harbour-sailcash.m
> > > > > o
> > > > > /usr/share/harbour-sailcash/locale/fr/LC_MESSAGES/harbour-sailcash.m
> > > > > o
> > > > > /usr/share/harbour-sailcash/qml/cover/CoverPage.qml
> > > > > /usr/share/harbour-sailcash/qml/cover/coveractions.py
> > > > > /usr/share/harbour-sailcash/qml/harbour-sailcash.qml
> > > > > /usr/share/harbour-sailcash/qml/pages/FirstPage.qml
> > > > > /usr/share/harbour-sailcash/qml/pages/datadownloader.py
> > > > > /usr/share/harbour-sailcash/translations/harbour-sailcash-de.qm
> > > > > /usr/share/harbour-sailcash/translations/harbour-sailcash-fr.qm
> > > > > /usr/share/icons/hicolor/108x108/apps/harbour-sailcash.png
> > > > > /usr/share/icons/hicolor/128x128/apps/harbour-sailcash.png
> > > > > /usr/share/icons/hicolor/256x256/apps/harbour-sailcash.png
> > > > > /usr/share/icons/hicolor/86x86/apps/harbour-sailcash.png
> > > > > /usr/share/icons/hicolor/scalable/apps/harbour-sailcash.svg
> > > > > 
> > > > > Is there anything I need to do in the QML to let it find the *.qm
> > > > > files?
> > > > > 
> > > > > Regards,
> > > > > 
> > > > > Yann
> > > > > _______________________________________________
> > > > > SailfishOS.org Devel mailing list
> > > > > To unsubscribe, please send a mail to
> > > > > devel-unsubscribe at lists.sailfishos
> > > > > .org
> > > > 
> > > > _______________________________________________
> > > > SailfishOS.org Devel mailing list
> > > > To unsubscribe, please send a mail to
> > > > devel-unsubscribe at lists.sailfishos.o
> > > > rg
> > > 
> > > --
> > > PGP Public Key:
> > > http://pgp.mit.edu/pks/lookup?op=get&search=0xF5122BC2972E426
> > 
> > _______________________________________________
> > SailfishOS.org Devel mailing list
> > To unsubscribe, please send a mail to
> > devel-unsubscribe at lists.sailfishos.org
> --
> PGP Public Key:
> http://pgp.mit.edu/pks/lookup?op=get&search=0xF5122BC2972E426D
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 455 bytes
Desc: This is a digitally signed message part.
URL: <https://lists.sailfishos.org/pipermail/devel/attachments/20180309/6098a926/attachment.sig>


More information about the Devel mailing list