Thanks for all your error reports, I didn't forget it. I'll cleanup my guide soon. Thanks again!

Exercise 6. Bash: language settings, LANG, locale, dpkg-reconfigure locales

In Linux language selection is as simple as an exporting of a variable. That is right, programs decide how to talk to you by looking into this varibale. Of course, for this to work program must support locales and have translation to your language available and installed. Let us see how it works by installing French locale.

Now you will learn how to install and select a locale.

Do this

1: echo $LANG
2: locale
3: man man # press q to exit man
4: sudo dpkg-reconfigure locales

Now, select the fr_FR.UTF-8 locale by navigating through the list using cursor keys and select the locale using space. Select en_US.UTF-8 as the default system locale.

 5: export LANG=fr_FR.UTF-8
 6: echo $LANG
 7: locale # press q to exit man
 8: man man
 9: export LANG=en_US.UTF-8

What you should see

user1@vm1:~$ echo $LANG
en_US.UTF-8
user1@vm1:~$ locale
LANG=en_US.UTF-8
LANGUAGE=en_US:en
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=
user1@vm1:~$ man man
MAN(1)                Manual pager utils                MAN(1)

NAME
       man - an interface to the on-line reference manuals
user1@vm1:~$ sudo dpkg-reconfigure locales
---------------| Configuring locales |-----------------------
|                                                           |
| Locales are a framework to switch between multiple        |
| languages and allow users to use their language,          |
| country, characters, collation order, etc.                |
|                                                           |
| Please choose which locales to generate. UTF-8 locales    |
| should be chosen by default, particularly for new         |
| installations. Other character sets may be useful for     |
| backwards compatibility with older systems and software.  |
|                                                           |
|                          <Ok>                             |
|                                                           |
-------------------------------------------------------------
           -----------| Configuring locales |--------
           | Locales to be generated:               |
           |                                        |
           |    [ ] fr_BE@euro ISO-8859-15          |
           |    [ ] fr_CA ISO-8859-1                |
           |    [ ] fr_CA.UTF-8 UTF-8               |
           |    [ ] fr_CH ISO-8859-1                |
           |    [ ] fr_CH.UTF-8 UTF-8               |
           |    [*] fr_FR ISO-8859-1                |
           |    [ ] fr_FR.UTF-8 UTF-8               |
           |    [ ] fr_FR@euro ISO-8859-15          |
           |                                        |
           |                                        |
           |        <Ok>            <Cancel>        |
           |                                        |
           ------------------------------------------
 ------------------ Configuring locales ----------------------
 |                                                           |
 | Many packages in Debian use locales to display text in    |
 | the correct language for the user. You can choose a       |
 | default locale for the system from the generated          |
 | locales.                                                  |
 |                                                           |
 | This will select the default language for the entire      |
 | system. If this system is a multi-user system where not   |
 | all users are able to speak the default language, they    |
 | will experience difficulties.                             |
 |                                                           |
 |                          <Ok>                             |
 |                                                           |
 -------------------------------------------------------------
------------ Configuring locales --------------
| Default locale for the system environment:  |
|                                             |
|                 None                        |
|                 en_US.UTF-8                 |
|                 fr_FR.UTF-8                 |
|                                             |
|                                             |
|          <Ok>              <Cancel>         |
|                                             |
-----------------------------------------------
Generating locales (this might take a while)...
  en_US.UTF-8... done
  fr_FR.UTF-8... done
Generation complete.
user1@vm1:~$ export LANG=fr_FR.UTF-8
user1@vm1:~$ echo $LANG
fr_FR.UTF-8
user1@vm1:~$ locale
LANG=fr_FR.UTF-8
LANGUAGE=en_US:en
LC_CTYPE="fr_FR.UTF-8"
LC_NUMERIC="fr_FR.UTF-8"
LC_TIME="fr_FR.UTF-8"
LC_COLLATE="fr_FR.UTF-8"
LC_MONETARY="fr_FR.UTF-8"
LC_MESSAGES="fr_FR.UTF-8"
LC_PAPER="fr_FR.UTF-8"
LC_NAME="fr_FR.UTF-8"
LC_ADDRESS="fr_FR.UTF-8"
LC_TELEPHONE="fr_FR.UTF-8"
LC_MEASUREMENT="fr_FR.UTF-8"
LC_IDENTIFICATION="fr_FR.UTF-8"
LC_ALL=
user1@vm1:~$ man man
MAN(1)  Utilitaires de l'afficheur des pages de manuel  MAN(1)

NOM
       man   -   interface  de  consultation  des  manuels  de
       référence en ligne
user1@vm1:~$ export LANG=en_US.UTF-8
user1@vm1:~$

Explanation

  1. Prints out your current LANG variable which is used by programs to determine which language to use when interacting with you.
  2. Prints out all locale variables which are used by programs for setting up number, address, phone format, etc. according to the format of the specified country.
  3. Shows you manual page about unix manual system. Notice how I used # to comment an action, everything after # is not executed.
  4. Executes a program for re-configuring your locales. Because this change is system wide, you need to run this command as root, that's why there is sudo in front of dpkg-reconfigure locales. Don't bother about sudo now, I'd set it up for you.
  5. Exports LANG variable which is used to set all other locale variables.
  6. Prints out LANG variable, you can see that it's changed as you would expect.
  7. Prints out other locale variables which are changed also.
  8. Shows you man manual page, in French.
  9. Reverts LANG variable back to English.

Extra credit

  1. Read manual page about locale. To do this, type in man locale.
  2. Now, read a man 7 locale page. Notice how I used 7 here to call a man page about conventions. If you want, read man man now to understand what other possible codes are, or just wait for exercise which covers it.

Discussion

Navigation

Learn Linux The Hard Way