Subject: Internationalization environment variables

From: Jakub Wilk <[email-masked]>
Date: Sat, 12 Jan 2013 15:03:31 +0100

Setting `internationalization environment variables`_ is a bit tricky.
For example, this::

   $ LANG=sv_SE.UTF-8 stat /nonexistent

may look like a way to make ``stat(1)`` print the error message in
Swedish. Yet there are many ways it could go wrong:

1. ``LC_MESSAGES`` could be set in the environment, overriding ``LANG``.

2. ``LC_ALL`` could be set, overriding both ``LC_MESSAGES`` and
   ``LANG``.

3. ``LANGUAGE`` could be set, overriding ``LC_ALL``, ``LC_MESSAGES``,
   and ``LANG``. For extra complexity, ``LANGUAGE`` has no effect if
   ``LC_MESSAGES`` is effectively set to ``C``. (Also, this variable is a
   GNUism.)

4. The locale could be simply missing from the system.

To make these things a little less intricate, I wrote localehelper_.
It's a bit like ``env(1)``, but it takes care of:

- unsetting all internationalization variables that weren't explicitly
  set on the command line;

- if needed, generating missing locales (in a temporary location).

This does the right thing::

   $ localehelper LANG=sv_SE.UTF-8 stat /nonexistent
   stat: kan inte ta status på ”/nonexistent”: Filen eller katalogen finns inte

.. _internationalization environment variables:
    http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap08.html#tag_08_02
.. _localehelper:
    http://jwilk.net/software/localehelper