[SailfishDevel] Adding localization to sailfish app
Antoine Reversat
a.reversat at gmail.com
Thu Jan 9 01:43:34 UTC 2014
Hi,
I added localization to my sailfishos app, as I didn't see a real example
here I thought I'd post one for the sake of archiving (and googling).
The way it works is that I install qm files to
/usr/share/$NAME/localization the qm files are of the form <2 letter
language code>.qm, you could be more precise and produce e.g fr_FR.qm files
(see http://qt-project.org/doc/qt-5.0/qtcore/qtranslator.html#load). Here
is the relevant main function :
int main(int argc, char *argv[])
{
QGuiApplication* app = SailfishApp::application(argc, argv);
QString locale = QLocale::system().name();
QTranslator translator;
translator.load(locale,SailfishApp::pathTo(QString("localization")).toLocalFile());
app->installTranslator(&translator);
return SailfishApp::main(argc, argv);
}
And relevant parts in my .pro
localization.files = localization
localization.path = /usr/share/$${TARGET}
INSTALLS += localization
lupdate_only {
SOURCES = qml/*.qml \
qml/pages/*.qml
TRANSLATIONS = localization/fr.ts \
localization/en.ts
}
I think this could be integrated into libsailfishapp with lrelease being
integrated in the build process, it would then only be a matter of running
lupdate and making the translations, the rest would be automatic.
Antoine
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.sailfishos.org/pipermail/devel/attachments/20140108/d3951693/attachment.html>
More information about the Devel
mailing list