Internationalisation not working

I am writing a Sailfish application called Pigeon in C++ and QML, and want to include translations. I looked into the descriptions on I18n | Sailfish OS Documentation but don’t get it working.

I changed the .spec file as described there.

My .pro file, included

CONFIG += sailfishapp
c++14
sailfishapp_i18n
sailfishapp_i18n_idbased

DISTFILES +=translations/*.ts

TRANSLATIONS += translations/Pigeon.ts

TS_FILE = $$OUT_PWD/$$TARGET.ts

When running the project, I get the following, and application is not deploying/starting on my device. Build is running fine

Updating ‘../Pigeon/translations/Pigeon.ts’…Found 15 source text(s) (15 new and 0 already existing)Updating ‘../Pigeon/translations/Pigeon.ts’…Found 15 source text(s) (0 new and 15 already existing)Updating ‘/home/ajonck/Sailfishprojects/build-Pigeon-SailfishOS_5_1_0_11_aarch64_in_Sailfish_SDK_Build_Engine-Debug/translations/Pigeon.qm’…Dropped 14 message(s) which had no ID.Generated 0 translation(s) (0 finished and 0 unfinished)
install -m 644 -p /home/ajonck/Sailfishprojects/build-Pigeon-SailfishOS_5_1_0_11_aarch64_in_Sailfish_SDK_Build_Engine-Debug/translations/Pigeon.qm /home/deploy/installroot/usr/share/Pigeon/translations/

…

RPM build errors:error: 
File not found: /home/deploy/installroot/usr/share/translations/.qm
File not found: /home/deploy/installroot/usr/share/translations/.qm
12:02:08: The process “/home/ajonck/SailfishOS/bin/sfdk” exited with code 1.
Error while building/deploying project Pigeon (kit: SailfishOS-5.1.0.11-aarch64 (in Sailfish SDK Build Engine))
When executing step "RPM Build"

I am also getting the message in QT Creator

The file Pigeon.ts has been changed on disk. Do you want to reload it.

Details:

/home/ajonck/Sailfishprojects/build-Pigeon-SailfishOS_5_1_0_11_aarch64_in_Sailfish_SDK_Build_Engine-Debug/translations/Pigeon.ts

I see files generated:

ajonck@localhost:~/Sailfishprojects/build-Pigeon-SailfishOS_5_1_0_11_aarch64_in_Sailfish_SDK_Build_Engine-Debug/translations> ls -al
totaal 8
drwxr-xr-x 1 ajonck users 36 12 jul 12:04 .
drwxr-xr-x 1 ajonck users 2132 12 jul 11:32 ..
-rw-r–r-- 1 ajonck users 16 12 jul 12:16 Pigeon.qm
-rw-r–r-- 1 ajonck users 3330 12 jul 12:16 Pigeon.ts

I normally start coding by creating a template with SDK to avoid simple typos etc. By creating untitled1 with Sailfish SDK 3.13.5 gives pro-file slightly different than yours. Translations seem to work on Jolla C2 5.1.0.11 fine.

# The name of your application
TARGET = untitled1

CONFIG += sailfishapp

SOURCES += src/untitled1.cpp

DISTFILES += qml/untitled1.qml \
    qml/cover/CoverPage.qml \
    qml/pages/FirstPage.qml \
    qml/pages/SecondPage.qml \
    rpm/untitled1.changes.in \
    rpm/untitled1.changes.run.in \
    rpm/untitled1.spec \
    translations/*.ts \
    untitled1.desktop

SAILFISHAPP_ICONS = 86x86 108x108 128x128 172x172

# to disable building translations every time, comment out the
# following CONFIG line
CONFIG += sailfishapp_i18n

# German translation is enabled as an example. If you aren't
# planning to localize your app, remember to comment out the
# following TRANSLATIONS line. And also do not forget to
# modify the localized app name in the the .desktop file.
TRANSLATIONS += translations/untitled1-de.ts


Apparently you have a typo in the .spec file %files section. Should read ‘*.qm’ instead of ‘.qm’

2 Likes

Tx, tried it, updated my .pro file to the default except following, but did not help.

CONFIG += sailfishapp_i18n
sailfishapp_i18n_idbased

# Translation source

TS_FILE = $$OUT_PWD/$$TARGET.ts

I asked Claude for help, it suggested changing .spec file with

%install
%qmake5_install

mkdir -p %{buildroot}%{_datadir}/%{name}/translations
install -m 644 -p translations/Pigeon.ts %{buildroot}%{_datadir}/%{name}/translations/

desktop-file-install --delete-original --dir %{buildroot}%{_datadir}/applications %{buildroot}%{_datadir}/applications/*.desktop

%files
%defattr(-,root,root,-)
%{_bindir}/%{name}
%{_datadir}/%{name}
%exclude %{_datadir}/%{name}/translations/.ts
%{_datadir}/applications/%{name}.desktop
%{_datadir}/icons/hicolor/
/apps/%{name}.png

%package ts-devel
Summary: Translation source for %{name}
License: XXX

%description ts-devel
%{summary}.

%files ts-devel
%{_datadir}/%{name}/translations/*.ts

This works, but now when deploying it also asks to install the translations, so probably not perfect yet.

I got it working without the indicated changes to the .spec file.

Via putting TARGET between {} in the .pro file

TS_FILE = $$OUT_PWD/$${TARGET}.ts

...

EE_QM = $$OUT_PWD/$${TARGET}_eng_en.qm