The locales-launch remote part

This remote part ships the locales-launch launcher to your snap, this launcher fixes Glibc locales support and allows GNU Gettext-based internationalization(I18N) to work.

example of gettext support

How to use?

Essential

Merge the following snapcraft recipe:

parts:
  locales-launch:

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

apps:
  _app_name_:
    command: locales-launch _original_app_command_chain_

That’s all you have to do, but if you want to directly embed the full set of pre-compiled locale data without generating them at runtime once per installation per locale and don’t care about the snap size increase by ~7MiB, override the stage-packages key to stage the locales-all package:

parts:
  locales-launch:
    stage-packages:
    - locales-all

The launcher will automatically use the in-snap locale data if found.

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: /

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.

The implementation

https://github.com/Lin-Buo-Ren/locales-launch-part

You may also run snapcraft define locales-launch to verify the actual implementation being used.

Snaps that use locale-launch

Credits

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

Reference

Happy snapcrafting!

2 Likes

Awesome, thanks for this!

I just tried it out with a python snap and it fixes the locale issues!

Can you add a link to a snap using this? Do you want to make this post into a wiki so others can help maintain this doc?

1 Like

Sure, I was originally using this to fix the GNU Hello snap.

It is now converted to a wiki.

The htop snap is now using this part as of revision 1066, on stable (commit + LP build). Thanks!

1 Like

It’s my pleasure! :slight_smile:

Here’s another solution that solves the problem slightly differently but doesn’t require locale data compilation:

https://forum.snapcraft.io/t/the-gettext-launch-remote-part/9111

Only use the above one if:

  • The snapped application doesn’t depend on LC_* environment variables other than LC_MESSAGES(if unsure you probably shouldn’t use it as it breaks parts of the localization other than message translation)

Just used this part for the toot snap. Thank’s so much.

2 Likes

Note that there’s a stage snap that ships the same launcher without manually add it into the packaging tree: The locales-launch stage snap