Skip to content

Linux local command (localization and internationalization)

The Linux local command works with the environmental variables that define the internationalization of the system, such as characters, dates, and numbering.

Linux maintains a list of environmental variables to define the internationalization standards of language, number format, time format, date format, currency format, among others.

The variables are:

  • LC_COLLATE: defines character or string grouping information;
  • LC_CTYPE: defines the type of character encoding;
  • LC_MONETARY: defines how numbers are written, whether semicolons are used to separate houses;
  • LC_MESSAGES : defines the format for affirmative and negative answers;
  • LC_NUMERIC: defines a list of rules and symbols for the formatting of non-numeric monetary information;
  • LC_TIME: defines how times are written;
  • LC_ALL: defines a standard that It has the other definitions above.

Local

The locale command reports these environmental variables.

$ locale <br></br>lang=pt_BR.UTF-8 <br></br>LANGUAGE= <br></br>lc_ctype="pt_br.utf-8" <br></br>lc_numeric="pt_br.utf-8" <br></br>lc_time="pt_br.utf-8" lc_br.utf-8" lc_br.utf-8" <br></br><br></br>lc_monetary="pt_br.utf-8" lc_messages="pt_br.utf-8" lc_br.utf-8" <br></br>lc_br.utf-8" lc_br.utf-8" <br></br>lc_messages="pt_br.utf-8" lc_br.utf-8" <br></br>lc_br.utf-8" UTF-8" LC_NAME="en_BR.UTF-8" <br></br>LC_ADDRESS="en_BR.UTF-8"

LC_TELEPHONE=“PT_BR.UTF-8”
LC_MEASUREMENT=“PT_BR.UTF-8”
LC_IDENTIFICATION=“PT_BR.UTF-8”
LC_ALL=pt_BR.UTF-8

The LC_ALL variable can be used to configure all the others.

The “-a” option provides the list of possible locations:

$ local -a en_US.utf8 pt_BR.utf8

The desired location may not always be available in the system. If it does not appear with the “-a” option in the locale command, it is necessary to generate the location.

To see the list of all locations that can be generated, check the contents of the /etc/locale.gen file:

$ cat /etc/locale.gen # AA_Dj ISO-8859-1 # AA_dj.UTF-8 UTF-8 # AA_er UTF-8 (...)

To generate the desired location and be able to use it in the LC_ALL variable, the locale-gen command is used to generate the location:

$ locale-gen pt_BR.UTF-8 <br></br>Generating locals (this might take a while)... <br></br>pt_BR.UTF-8... done <br></br>Generation complete.

To change the location setting, simply change the LC_ALL variable:

$ export LC_ALL=en_BR.UTF-8

Since the location is configured by environment variables, they must be in the shell load script or in the profile for them to be permanent in the system.

localectl command

The systemd localectl service can be used to query and change the system’s location and keyboard layout settings.

This service can be used to control the language settings of the system services and the user interface before the user logs in.

Example:

To view the configured location:

$ localectl status System Locale: lang=en_US.UTF-8 VC Keymap: n/a X11 Layout: n/a

To change the location:

$ sudo localectl set-locale lc_time=EN_IN.UTF-8