The gettext-launch launcher: Fix gettext-based internationalization in the snap runtime

NOTE: This part does not support snaps that use bases

This launcher fixes GNU Gettext-based internationalization(I18N) without generating locale data like the locales-launch remote part does.

How to use?

Essential

Merge the following snapcraft recipe:

parts:
  gettext-launch:
    source: https://github.com/Lin-Buo-Ren/gettext-launch.git
    source-tag: v1.0.0
    plugin: dump
    stage:
      - bin/*

and prepend gettext-launch to the snap application command chain:

apps:
  _app_name_:
    command: gettext-launch _original_app_command_chain_

GNU Gettext-specific fixes

Due to the fact that the gettext library doesn’t support locating the localization data from a non-fixed location, additional modifications may be required to make I18N work.

For example for software using the GNU build system the following modification is usually necessary:

parts:
  _part_name_:
    configflags:
    - --datarootdir=/snap/$SNAPCRAFT_PROJECT_NAME/current/share

    organize:
      snap/$SNAPCRAFT_PROJECT_NAME/current: /

Alternative implementation

For users that uses the base keyword(thus not compatible with remote parts) or one simply doesn’t like remote parts here’s a Snapcraft YAML patch that has the same effect as using the gettext-launch remote part:

apps:
  _app_name_:
    environment:
      LANG: C.UTF-8
      LC_ALL: C.UTF-8

Demonstration:

NOTE

  • This launcher is not necessary if the snap target is a GUI application and you’re using the desktop-* remote part and the desktop-launch launcher. This remote part is primarily for CLI applications
  • This remote part fixes the locale problem by hardcoding all the locale variables to C.UTF-8, and should only be used when the snap doesn’t depend on LC_* environment variables for any kind of localization beside of LC_MESSAGES, for a general locale solution please use the locales-launch remote part instead

The implementation

Snaps that use gettext-launch

Credits

This part will not have great success without James Henstridge’s research and Sebastien Bacher’s initial implementation.

Reference

Happy snapcrafting!