> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/ask/flat/chapter-12-localization-and-input-methods/di-12.1-jie-ben-di-hua-huan-jing-bian-liang.md).

# 12.1 Localization Environment Variables

Localization environment variables (`LANG`, `LC_*`, `MM_CHARSET`) determine the system interface language, character encoding, and sorting rules. This section describes configuration methods for various scenarios.

## Localization Environment Variable Configuration File Paths

### Display Manager Configuration Paths

| Display Manager    | Configuration File Path             |
| ------------------ | ----------------------------------- |
| SDDM, LightDM, GDM | **\~/.xprofile**                    |
| LightDM, GDM       | **\~/.profile**                     |
| SDDM               | User login Shell configuration file |

### Shell Configuration Paths

| Shell | Configuration File Path                  |
| ----- | ---------------------------------------- |
| sh    | **\~/.profile**                          |
| bash  | **\~/.bash\_profile** or **\~/.profile** |
| zsh   | **\~/.zprofile**                         |
| csh   | **\~/.cshrc**                            |

## Localization-Related Environment Variables

The `LC_*` family of variables are core environment variables used in UNIX and UNIX-like operating systems to implement internationalization (i18n) and localization (l10n). `LC_COLLATE`, `LC_CTYPE`, `LC_MESSAGES`, `LC_MONETARY`, `LC_NUMERIC`, `LC_TIME`, as well as `LC_ALL` and `LANG`, are defined by the POSIX (IEEE Std 1003.1, i.e., ISO/IEC 9945) standard. `LC_ADDRESS`, `LC_NAME`, `LC_PAPER`, `LC_TELEPHONE`, `LC_MEASUREMENT`, and `LC_IDENTIFICATION` are GNU extensions of glibc (introduced since glibc 2.2). ISO/IEC TR 30112:2014 (a technical report, now withdrawn, later superseded by the ISO/IEC 30112:2020 international standard) referenced these existing practices during its development (see Debian manpages. locale(7)\[EB/OL]. \[2026-04-17]. <https://manpages.debian.org/unstable/manpages/locale.7.en.html>). These variables control localization behavior across multiple dimensions including text character encoding, date and time formats, currency symbols, and interface language.

| Variable            | Description                                                                                                              |
| ------------------- | ------------------------------------------------------------------------------------------------------------------------ |
| `LC_COLLATE`        | Defines the rules for string collation                                                                                   |
| `LC_CTYPE`          | Defines the character set and character type classification rules, such as letters, digits, punctuation marks, etc.      |
| `LC_MONETARY`       | Defines the monetary format and currency symbol                                                                          |
| `LC_MESSAGES`       | Defines the language of program runtime output messages                                                                  |
| `LC_NUMERIC`        | Defines the numeric format, such as decimal point and thousands separator                                                |
| `LC_TIME`           | Defines the date and time format                                                                                         |
| `LC_ADDRESS`        | Defines the address format                                                                                               |
| `LC_NAME`           | Defines the personal name format                                                                                         |
| `LC_PAPER`          | Defines the default paper size                                                                                           |
| `LC_TELEPHONE`      | Defines the telephone number format                                                                                      |
| `LC_MEASUREMENT`    | Defines the measurement unit format (metric or imperial)                                                                 |
| `LC_IDENTIFICATION` | Defines metadata about the locale itself (locale name, language, region, currency, and other identification information) |
| `MM_CHARSET`        | Sets the MIME character set, used by applications to determine character encoding when processing multilingual content   |

### Special Variable Descriptions

| Variable   | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `LC_ALL`   | Setting this variable overrides the values of all other `LC_*` variables simultaneously                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `LANG`     | Used to set the default language and character set, typically providing locale information when no other `LC_*` variables are set. If both `LANG` and `LC_*` variables are set, the `LC_*` variables will override the corresponding settings in the `LANG` variable                                                                                                                                                                                                                                                                                                                                                                 |
| `LANGUAGE` | Primarily used to specify the preferred language for interface messages (such as command-line prompts, error messages, menu text, etc.) for localization libraries like GNU gettext. GNU gettext gives `LANGUAGE` higher priority than `LC_ALL` and `LANG`. It generally does not affect date, number, or currency formats; these format-related localizations are still controlled by the corresponding `LC_TIME`, `LC_NUMERIC`, `LC_MONETARY`, and other `LC_*` variables or `LANG`. If `LANGUAGE` is not set, programs typically fall back to `LC_MESSAGES` or other locale variables to determine the interface message language |

#### References

* GNU gettext Manual. The LANGUAGE variable\[EB/OL]. \[2026-06-08]. <https://www.gnu.org/software/gettext/manual/html_node/The-LANGUAGE-variable.html>.

### Common Configuration Schemes

A Chinese language environment can be achieved through multiple approaches:

1. Setting only `LC_MESSAGES` to `zh_CN.UTF-8` is sufficient for a Chinese interface (verified in SDDM/Xfce environment)
2. A common practice is to set all three environment variables `LANG`, `LC_ALL`, and `LANGUAGE` to `zh_CN.UTF-8`
3. Keep the system interface in English while using a Chinese input method; set only input method-related variables and leave other environment variables at the default English settings

Different software may have varying priorities when reading localization variables, so it is recommended to set all three environment variables to `zh_CN.UTF-8` to ensure consistency in language settings.

### Different Configurations Produce Different Effects

When only `LC_MESSAGES` is set, this setting only affects the interface and prompt messages, and does not affect the output of other formats. Taking sh as an example:

```sh
$ locale        # Display current system localization settings
LANG=C.UTF-8
LC_CTYPE="C.UTF-8"
LC_COLLATE="C.UTF-8"
LC_TIME="C.UTF-8"
LC_NUMERIC="C.UTF-8"
LC_MONETARY="C.UTF-8"
LC_MESSAGES=zh_CN.UTF-8
LC_ALL=
$ date  # Display time and date
Fri Apr 21 21:14:43 UTC 2023
$ export LC_TIME=zh_CN.UTF-8
$ date
2023年 4月21日 星期五 21时15分07秒 UTC
```

Defaults:

* `LC_TIME` environment variable value is `C.UTF-8`
* `date` command outputs `Fri Apr 21 21:14:43 UTC 2023`
* `LC_TIME` environment variable value is set to `zh_CN.UTF-8`
* `date` command outputs `2023年 4月21日 星期五 21时15分07秒 UTC`

> **Note**
>
> Keeping the `date` command's English output may be very important in certain scripts. Similar situations exist for other information controlled by `LC_*` variables.

## Exercises

1. Configure localization environment variables for different Shells (sh, bash, zsh, csh) on a FreeBSD system, and verify the output of the `date` command in English and Chinese environments respectively.
2. Set up an environment with only `LC_MESSAGES=zh_CN.UTF-8`, and test the availability of Chinese prompts in common commands (such as ls, pkg, man).
3. Analyze the priority relationships among `LANG`, `LC_ALL`, and various `LC_*` variables, and provide examples to illustrate the actual behavior under different setting combinations.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://book.bsdcn.org/ask/flat/chapter-12-localization-and-input-methods/di-12.1-jie-ben-di-hua-huan-jing-bian-liang.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
