Search code examples
pythonandroidkivygettextbuildozer

kivy Buildozer Android build cannot find translation files


Post building my kivy app for Android using Buildozer the run step fails as it cannot find the message files for gettext. I have the following line in my .spec file:

source.include_exts = py,png,jpg,kv,atlas,mo,po,ini

The .mo files are in the current app dir under ./locales.

I have also included the following line in .spec:

source.include_patterns = locales/*

Finally, my code in main.py includes:

trans = gettext.translation('base', localedir='locales', languages=[locale.getdefaultlocale()[0][0:2]])

languages is set to en and an en directory is within the locales folder.

Is appears as if Buildozer is picking these up:

Listing '/Users/martinprater/PycharmProjects/kivy/.buildozer/android/app/locale/de'...
Listing '/Users/martinprater/PycharmProjects/kivy/.buildozer/android/app/locale/de/LC_MESSAGES'...
Listing '/Users/martinprater/PycharmProjects/kivy/.buildozer/android/app/locale/en'...
Listing '/Users/martinprater/PycharmProjects/kivy/.buildozer/android/app/locale/en/LC_MESSAGES'...

How can I validate if they are included in the app? Thanks, Martin


Solution

  • I am not sure if this is the easiest way, but could solve the issue by switching to p4a native and using setup.py:

    setup(
        ...
        package_data={'.': ['main.py', '*.kv', '*.png', 'locales/*/LC_MESSAGES/base.mo']}
    )
    

    Then accessing the file using pkg_resources:

    pkg_resources.resource_filename('pkg', 'locales')