Time for action – getting different outputs with different locales

Ok, so now that we have a locale other than English-US, what's next? Let's start with a very simple one, the date program.

  1. Open a terminal.
  2. Type the following:
    LC_ALL=C date
  3. See the output, as shown here:
    Sun Oct 28 15:41:38 EET 2012
  4. Then type the following command (don't forget to change id_ID.utf8 to the locale that you have enabled previously).
    LC_ALL=id_ID.utf8 date
  5. Check the output; it will be similar to the one shown here:
    Min Okt 28 15:41:45 EET 2012

In this action, we configured the settings manually by using the LC_ALL environment variable. By setting the LC_ALL variable to any locale identifier, the POSIX system would immediately use the specified locale to transform the output of the application. As mentioned earlier, the system has many parameters that we can set. The LC_ALL variable is the magic parameter that sets all of the parameters with a single value.

Actually, the output of the date program is purely date and time data. So, the parameter affected is LC_TIME.

As we can see, the output is translated into Indonesian just after we set the locale. Try to provide any bogus locale identifier (or try to make a typo!) and you will see that it no longer works. Also, if you have other locales installed, try them all!