107.3 Localisation and

Tech Tutorial: 107.3 Localization and Internationalization #

Introduction #

Localization (often abbreviated as “l10n”) and internationalization (abbreviated as “i18n”) are crucial in today’s global environment, enabling applications and systems to interact with users in multiple languages and regional formats. In this tutorial, we’ll explore how to localize a Linux system to a language other than English, and discuss the significance of using LANG=C in shell scripting.

Key Knowledge Areas: #

  • Understand locale settings
  • Configure system-wide and user-specific settings
  • Interpret and modify locale environment variables
  • Use locale command to manage locale settings
  • Importance of LANG=C in scripting

Step-by-Step Guide #

1. Understanding Locale #

A locale is a set of parameters that defines the user’s language, country, and any special variant preferences. These parameters affect various functions in the system, such as time and date formatting, number formatting, and language-specific output for applications.

2. Checking Current Locale Configuration #

To view your current locale settings, you can use the locale command:

locale

This command will display all the current locale settings, including language, character encoding, and other specific settings.

3. Listing Available Locales #

Before you configure your locale, you might want to see what locales are available on your system:

locale -a

This command lists all locales that your system supports.

4. Setting Locale Settings #

To change the locale settings for your session, you can set the LANG environment variable. For example, to switch to German (Germany) with UTF-8 encoding, you would use:

export LANG=de_DE.UTF-8

To make this change permanent for your user, add the above line to your ~/.bashrc or ~/.profile file. For system-wide changes, you can set this variable in /etc/environment or /etc/locale.conf (this may vary depending on your distribution).

5. Configuring Detailed Locale Settings #

Sometimes, you might want to configure detailed settings like number formats or monetary formats while keeping the language the same. You can set these with their respective environment variables:

export LC_NUMERIC="de_DE.UTF-8"
export LC_TIME="de_DE.UTF-8"
export LC_MONETARY="de_DE.UTF-8"
export LC_PAPER="de_DE.UTF-8"
export LC_NAME="de_DE.UTF-8"

6. Locale on Applications #

Some applications may require specific locale settings to display content correctly. You can run an application with a different locale by prefixing it with the LANG variable:

LANG=es_ES.UTF-8 gedit

This command runs gedit with Spanish locale settings.

7. Why LANG=C is Useful in Scripting #

Using LANG=C in scripts is beneficial because it sets the locale to the default C locale, which is standard across all Linux systems. This prevents scripts from breaking due to localized outputs in commands and ensures consistent sorting and character handling. Here’s an example:

#!/bin/bash

# Force C locale
LANG=C

# Perform text processing with tools like awk, sort, etc.
cat file.txt | awk '{print $1}' | sort

This script ensures that tools like awk and sort behave predictably regardless of the user’s locale settings.

Conclusion #

Understanding and properly configuring locale settings are essential for managing a multilingual Linux environment. By localizing your system, you can provide a more personalized experience for users in different regions. Moreover, using LANG=C in your scripts can help avoid unexpected behaviors due to locale differences, ensuring your scripts are portable and reliable.

Feel free to experiment with different locale settings to see how they affect your system and applications, and incorporate these practices into your configuration management to handle diverse environments effectively.