Localization in Linux¶
Localization in Linux refers to the process of adapting the system and its applications to a specific language, region, or culture. This involves configuring environment variables, system settings, and files to match the conventions of the target locale. Applications rely on these configurations to display the correct language, time, and date formats.
Key Concepts and Commands¶
1. Time and Date¶
date
¶
Displays the current date and time. You can customize the output using format specifiers:
date +'%Y-%M-%D %C' # Year, Month, Day, Century
cal
¶
Displays the calendar. Use cal -#
to show previous and next months:
cal -3 # Shows the current, previous, and next month
timedatectl
¶
Displays local time, timezone, UTC, and other time-related information:
timedatectl
tzselect
¶
Provides an interactive method to select a default timezone:
tzselect
2. Timezone Configuration¶
/etc/timezone
: Stores the system's timezone./etc/localtime
: Contains data for the OS to adjust its clock. It is often a symbolic link to a file in/usr/share/zoneinfo
./usr/share/zoneinfo
: Directory containing all timezone files. For example, the timezone for Douala, Africa, is located at:
/usr/share/zoneinfo/Africa/Douala
3. Language and Character Encoding¶
Locale¶
A set of parameters defining the user's language, country, and preferences. The LANG
environment variable stores the basic locale configuration in the format ab_CD
, where:
ab
: Language code (e.g.,en
for English).CD
: Region code (e.g.,US
for the United States).
locale
¶
Displays the current locale settings, including sub-environment variables:
locale
Locale Sub-Variables¶
LC_COLLATE
: Sets alphabetical ordering.LC_CTYPE
: Defines character handling.LC_MESSAGES
: Sets message language.LC_NUMERIC
: Sets numerical format for non-monetary values.LC_PAPER
: Sets standard paper size.LC_TIME
: Sets time and date format.LC_ALL
: Overrides all other locale variables.
localectl
¶
Available on systems using systemd
, it changes the system locale:
localectl set-locale LANG=en_US.UTF-8
4. Encoding Conversion¶
iconv
¶
Converts text files between character encodings. For example, to convert a file from ISO-8859-1 to UTF-8:
iconv -f ISO-8859-1 -t UTF-8 original.txt > converted.txt
Example¶
Original ISO-8859-1 encoded file (example.txt
):
Bonjour, comment allez-vous?
Das ist ein Beispieltext auf Deutsch.
Este es un ejemplo de texto en español.
ƒ (U+0192) is a special character.
€ (U+20AC) is another special character.
Convert to UTF-8:
iconv -f ISO-8859-1 -t UTF-8 example.txt > converted.txt
Summary¶
Localization in Linux involves configuring time, date, language, and character encoding to suit a specific region or culture. Key tools include date
, cal
, timedatectl
, tzselect
, locale
, and iconv
. Understanding these concepts ensures your system and applications display information correctly for your locale.