How to internationalize an app?

Hi all,

I’ve been trying to translate an app in German by following what seemed to me the simplest way to translate an app : .ts files.

To do so I created the TS files, mentioned them as so in the .pro file :

TRANSLATIONS += translations/harbour-deepfish_en.ts \

Added the

  • ‘%{_datadir}/%{name}/translations’

in the .yaml file “Files’s” section as suggested by the libsailfishapp documentation

Used the qsTr() variables as suggested by the QML docs. And even lupdated the TS files to have qm files.

But in the end, it doesn’t seem to work, at least in the emulator, so I am wondering what did I forget ? I don’t see other modifications/files in other sailfish apps so I guess it’s something I’m missing when building the app from the Sailfish IDE. I failed in finding additional documentation so if you have something I’d be glad and thankful about it !

Thank you very much !

The app : sfos_apps / harbour-deepfish · GitLab

Hi! I don’t have the '%{_datadir}/%{name}/translations'} line so I don’t think it’s mandatory.
However you missed the first instruction and need to add this in your .pro:

CONFIG += sailfishapp_i18n

Thank you for your reply !

When doing so, i get the following error:

/srv/mer/toolings/SailfishOS- /usr/lib/crt1.o: in function _start': (.text+0x18): undefined reference to main’

Which means I lack a main function somewhere. Should I create a main in the initial page although my code has no C in it ?

Oh I hadn’t noticed that your app doesn’t use SailfishApp (which indeed requires a main .cpp file with a main function), so those instructions are probably not adapted. I don’t know then, sorry :slightly_frowning_face:

How would I do it if I had to use SailfishApp ? Maybe that’s the solution I should use and I’m not aware of it.

The steps are explained in the How to use SailfishApp in your project paragraph.
But I don’t know the exact changes that you have to do to transform a pure QML project to one with a .cpp file and a main, what I had done a few years ago was to generate a Sailfish OS application with the SDK and start from the generated structure: Sailfish SDK Your First App - SailfishOS Documentation

So indeed @Sthocs you provided me with the solution, thank you very much.

For new comers struggling, bellow is the explanation of my struggling and how I’ve fixed it.

When I first created my app I followed the Creating an application in Python example, which did not require any c++ file to work.
But when I saw your commentary I decided to check the SDK documentation and discovered that you can (should ?) indeed add a .cpp file in the src/ folder.

I did so, added the proper libraries (I just copied the ones from Quickddit ) :


#include <QtGui/QGuiApplication>
#include <QtQml/qqml.h>
#include <QtQml/QQmlContext>
#include <QtQuick/QQuickView>
#include <sailfishapp.h>

CONFIG += sailfishapp sailfishapp_i18n
SOURCES += src/harbour-deepfish.cpp

and ignored unpackaged files in /usr/env which were blocking:
%define _unpackaged_files_terminate_build 0

lupdate and lrealease my .ts files which generated .qm binary files.

Maybe it’s breaking something elsewhere, can’t tell, but for now it works like a charm.

1 Like