Enable localization for KStars on Android

As a first KDE application, KStars got localization working on Android. KStars has the traditional gettext translations in the KDE system and these translations had to be downloaded, converted and packaged inside the apk.

The basic steps were to enable localization on Android:

1. Set CMake variable KDE_L10N_AUTO_TRANSLATIONS to ON. This step will automatically download the translations during the build with a custom build target "fetch-translations".
2. Convert the translations from .po extension into .mo format. This step was done with a custom build target in CMake:

    ADD_CUSTOM_TARGET(convert_translations_to_android ${CMAKE_SOURCE_DIR}/tools/convert_translations.sh ${CMAKE_BINARY_DIR}/android/export/share/kstars
                        WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
    ADD_DEPENDENCIES(convert_translations_to_android fetch-translations)

The convert_translations.sh script can be found here: https://github.com/KDE/kstars/blob/master/tools/convert_translations.sh

3. Set the application domain for translation as usual in the sources:


4. Add the installation directory on the device like a locale dir:

#if defined(__ANDROID__)
KLocalizedString::addDomainLocaleDir("kstars", "/data/data/org.kde.kstars.lite/qt-reserved-files/share/kstars/locale");

With the above steps and the current bleeding-edge KI18n KF5 module, your application will load with the current system language on the device.

You can check the whole commit by visiting: https://github.com/KDE/kstars/commit/bf4ac1e6a9a745eb37fc2e719e3fd95b00f84135

Of course, it was not so easy. There were some challenges with the KI18n module because it uses libintl-lite on Android and this lightweight library does not work exactly like the GNU gettext. This library expects a locale filename to bind for the current localization context instead of the location of locale subdirectories. KI18n had to be fixed to provide the filename for libintl-lite on Android platform.


Népszerű bejegyzések ezen a blogon

Improving the reliability and usability of KStars

The achievements during the second GSoC period in KStars