tencent cloud

TencentOS Server

Localization Management

다운로드
포커스 모드
폰트 크기
마지막 업데이트 시간: 2026-10-19 17:15:15
AI 번역
This document describes the basics of localization management on TencentOS Server and the related configuration methods. Localization management can make the system better align with the usage habits of the user's region.
Localization management typically involves the following:
Configuration
Description
Set the system display language, date and time format, currency symbol, and so on.
Set the local time displayed by the system.
Different countries and regions may use different keyboard layouts, such as QWERTY, AZERTY, and QWERTZ.
Set the display style of text in the system. Different fonts may support different character sets and typographic effects.
Allows input of different character sets in the system, such as Chinese and Japanese.

Language and Region

System settings such as language and region are controlled by locale variables. locale environment variables are a set of variables used to control localization settings, affecting aspects such as language, character encoding, and date in the system. The main locale environment variables and their functions are as follows:
Variable
Description
LANG
Sets the system's default language and character encoding. Other unset LC_* variables use the value of the LANG variable.
LC_CTYPE
Controls character classification and conversion, such as character case conversion, character sets, and encoding. Also affects character display in input methods and terminals.
LC_NUMERIC
Controls the display format of numbers, such as decimal point symbols and thousands separators.
LC_TIME
Controls the display format of dates and times, such as weekday names, month names, and date order.
LC_COLLATE
Controls the rules for string comparison and sorting. Affects operations such as file name sorting and command line argument sorting.
LC_MONETARY
Controls the display format of currency, such as currency symbols and positive and negative number representations.
LC_MESSAGES
Controls the language of system messages and prompts. Affects text output such as program error messages and help information.
LC_PAPER
Controls the default paper size for printing and page settings.
LC_NAME
Controls the display format of personal names, such as name order and name abbreviations.
LC_ADDRESS
Controls the display format of addresses, such as country names, city names, and postal codes.
LC_TELEPHONE
Controls the display format of phone numbers, such as country codes and area codes.
LC_MEASUREMENT
Controls the display format of measurement units, such as metric or imperial units.
LC_IDENTIFICATION
Controls the display format of metadata, such as language codes and country codes.

Viewing the Current locale Configuration

The locale configuration is recorded in the /etc/locale.conf file. The system default configuration is LANG="C.UTF-8". During initial systemd startup, this file is read to configure the system environment.
View the contents of the /etc/locale.conf file:
cat /etc/locale.conf
The returned result is as follows:
# This is the fallback locale configuration provided by systemd.
LANG="C.UTF-8"
Run the locale command to view the current locale configuration. Any unset LC_* variables will use the value of the LANG variable:
locale
The returned result is as follows:
LANG=C.UTF-8
LC_CTYPE="C.UTF-8"
LC_NUMERIC="C.UTF-8"
LC_TIME="C.UTF-8"
LC_COLLATE="C.UTF-8"
LC_MONETARY="C.UTF-8"
LC_MESSAGES="C.UTF-8"
LC_PAPER="C.UTF-8"
LC_NAME="C.UTF-8"
LC_ADDRESS="C.UTF-8"
LC_TELEPHONE="C.UTF-8"
LC_MEASUREMENT="C.UTF-8"
LC_IDENTIFICATION="C.UTF-8"
LC_ALL=

Listing Available Character Sets

Run the following command to list all locale character sets supported by the system, which mainly include Chinese, English, and the default C.UTF-8:
localectl list-locales
The returned result is as follows:
C.UTF-8
en_AU.UTF-8
en_BW.UTF-8
en_CA.UTF-8
en_DK.UTF-8
en_GB.UTF-8
en_HK.UTF-8
en_IE.UTF-8
en_NZ.UTF-8
en_PH.UTF-8
en_SC.UTF-8
en_SG.UTF-8
en_US.UTF-8
en_ZA.UTF-8
en_ZW.UTF-8
zh_CN.UTF-8
zh_HK.UTF-8
zh_SG.UTF-8
zh_TW.UTF-8
The locale naming convention is: language_region.character_set_encoding. Common Chinese and English locale definitions are as follows:
zh_CN.UTF-8: indicates that the language is Chinese zh, the region is Chinese mainland CN, and the character set encoding is UTF-8.
en_US.UTF-8: indicates that the language is English en, the region is the United States US, and the character set encoding is UTF-8.

Viewing Current Language and Region Settings

View the current language and region settings, where System Locale indicates the default LANG value used by the system, which defaults to C.UTF-8:
localectl status
The returned result is as follows:
System Locale: LANG=C.UTF-8
VC Keymap: n/a
X11 Layout: n/a
Note:
C.UTF-8 uses standard C as the language environment, but its character encoding is UTF-8. String sorting and comparison are based on byte values rather than specific language rules, and date, time, and number formats use basic English representation. Using C.UTF-8 does not depend on specific localization settings, ensuring better compatibility and portability of programs across different systems. This system uses C.UTF-8 as the default locale.

Setting System Language and Region

Typically, use the localectl command to configure the language and region. Directly modifying the /etc/locale.conf file is not recommended.
1. Set the system's localized character set to Simplified Chinese:
sudo localectl set-locale zh_CN.UTF-8
2. After the configuration is complete, run the following command to restart the system for the configuration to take effect:
reboot
Note:
During the restart, the instance will be unable to provide services normally. Therefore, before restarting, ensure that the instance has paused business requests.
To view more parameters and information, run localectl --help.

Time zone

A time zone represents the difference between a computer's local time and Coordinated Universal Time (UTC). Correctly setting the time zone is critical to ensuring accurate system time and the proper functioning of features such as scheduled tasks and logging.

Basic Concepts

Concept
Description
Universal Time Coordinated (UTC)
The primary world time standard, based on the second length of atomic time and independent of time zones.
Time Zone
Time standard based on the user's location.
Hardware Clock (Real-Time Clock, RTC)
A physical clock powered by a battery on the motherboard that continues to operate normally after system power loss.
System Clock
During system startup, the initial value is calculated based on the hardware clock. After startup, it runs independently of the hardware clock.
Both timedatectl and date are commands used in Linux systems to manage and display date and time, but their features differ:
Command
Description
timedatectl
A systemd tool that focuses on managing the system clock and time zone settings and can modify both the system time and hardware time.
date
A UNIX tool used to view and set the current date and time. It only modifies the system time and must be used with hwclock to modify the hardware time.

Using timedatectl

List all currently available time zones:
timedatectl list-timezones
The returned result is as follows (partially displayed):
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara
Africa/Asmera
...
View the current date, time, and time synchronization status of the system:
timedatectl status
The returned result is as follows:
Local time: Mon 2023-05-08 16:19:13 CST # Local time
Universal time: Mon 2023-05-08 08:19:13 UTC # UTC time
RTC time: Mon 2023-05-08 08:19:13 # RTC time
Time zone: Asia/Beijing (CST, +0800) # Time zone
System clock synchronized: no # NTP synchronization status
NTP service: active # NTP service status
RTC in local TZ: no # Whether RTC uses local time
Change the system time zone. Replace <TIMEZONE> with the target time zone, for example, Asia/Shanghai:
timedatectl set-timezone <TIMEZONE>
Modify the system date and time separately. Replace the date and time values with the actual ones as needed:
timedatectl set-time <YYYY-MM-DD> # Modifies only the year, month, and day of the system calendar, leaving the time unchanged
timedatectl set-time <HH:MM:SS> # Modifies only the hour, minute, and second of the system clock, leaving the date unchanged

Setting Up NTP Time Synchronization

The Network Time Protocol (NTP) is used to synchronize clocks between clients and servers. An NTP server receives the precise Coordinated Universal Time (UTC) from an authoritative clock source, such as an atomic clock or GPS, and clients then request and receive the time from the server.
Run the following command to enable or disable NTP time synchronization. Replace <BOOL> with true or false. This operation modifies the status of the NTP service:
timedatectl set-ntp <BOOL>

Using date and hwclock

Viewing System Time

View the current local time:
date
View the current UTC time:
date --utc
To customize the date output format, use date +"format". For details about the format parameter, run man date to view the manual:
Example 1: Output the abbreviated year, month, and day of the current date:
date +%y%m%d
The returned result is as follows:
230508
Example 2: Output the current date and time, including the date, hour, minute, and second:
date +"%D %H:%M:%S"
The returned result is as follows:
05/08/23 17:48:31

Modifying System Time

Run the following command to modify the system date and time separately. Replace the date and time values with the actual ones as needed:
date --set <YYYY-MM-DD> # Sets the system date to the specified value, leaving the time unchanged
date --set <HH:MM:SS> # Sets the system time to the specified value, leaving the date unchanged

Viewing Hardware Time

View the current hardware clock date and time:
hwclock

Modifying Hardware Time

Run the following command to modify the hardware clock date and time. Make sure to replace MM/DD/YYYY HH:MM with the actual date and time:
hwclock --set --date "MM/DD/YYYY HH:MM"

Synchronizing Hardware Time and System Time

If the hardware clock time differs from the system time, you can synchronize them in either direction by using the following commands:
Synchronize the hardware clock time to the system time:
hwclock --hctosys
Synchronize the system time to the hardware clock time:
hwclock --systohc
Note:
If the time is incorrect after startup in a virtual machine environment, the virtual machine may have incorrectly set the hardware clock by treating the local time as UTC, which then affected the system time. You can restore the correct time by modifying the hardware clock and synchronizing it to the system time.
To view more parameters and information, run timedatectl --help or refer to man timedatectl(1), man date(1), and man hwclock(8).

Keyboard Layout

Different countries and regions may use different keyboard layouts. You can set the keyboard layout of the current system by using localectl.
List all keyboard layouts supported by the system:
localectl list-keymaps
The returned result is as follows (partially displayed):
al
al-plisi
at
at-mac
at-nodeadkeys
az
ba
...
View the current keyboard layout settings:
localectl status
The returned result is as follows:
System Locale: LANG=en_US.UTF-8
VC Keymap: n/a
X11 Layout: n/a
Set the system keyboard layout. For example, to replace us with the target keyboard layout, run the following command as the root user:
sudo localectl set-keymap us

Font

You can control the display style of text in the system by configuring fonts. This section describes how to install Chinese fonts and use fontconfig for font management.

Installing System Fonts

First, install the fontconfig software package for subsequent font management operations.
1. Install fontconfig:
yum install fontconfig
2. After the installation is complete, run the following command to view the fonts currently available on the system:
fc-list
To filter and view available Chinese fonts, run the following command:
fc-list :lang=zh
Run the following command to list the Simplified Chinese font packages available for download on the system:
dnf list *cjk-sc*
The returned result is as follows:
Last metadata expiration check: 3:44:09 ago on Thu May 25 13:03:02 2023.
Available Packages
# Simplified Chinese Sans-Serif Fonts
google-noto-sans-cjk-sc-fonts.noarch 20201206-4.ocs23 AppStream
# Simplified Chinese Monospace Fonts
google-noto-sans-mono-cjk-sc-fonts.noarch 20201206-4.ocs23 AppStream
# Simplified Chinese Serif Fonts
google-noto-serif-cjk-sc-fonts.noarch 20201206-4.ocs23 AppStream
3. To install Simplified Chinese sans-serif fonts, run the following command:
dnf install google-noto-sans-cjk-sc-fonts.noarch
After the installation is complete, run the following command to verify whether the Chinese fonts are installed successfully:
fc-list :lang=zh

Installing Third-Party Fonts

If the system does not provide the required fonts, you can obtain the font files and install them yourself.
1. First, create a directory to store the font files, and upload the font files to be installed to that directory.
To install fonts for all users, copy the font files to the /usr/local/share/fonts/ directory:
mkdir -p /usr/local/share/fonts/new_fonts
cp example.ttf /usr/local/share/fonts/new_fonts
To install fonts for a single user, copy the font files to ~/.local/share/fonts/ in the user's home directory:
mkdir -p ~/.local/share/fonts/new_fonts
cp example.ttf ~/.local/share/fonts/new_fonts
2. After the font files are placed, run the following command to update the system font cache and make the new fonts take effect:
fc-cache
3. Run the following command to check whether the newly added fonts appear in the list of available fonts:
fc-list | grep -i new_fonts
4. (Optional) To verify the actual font file that the system matches for a specified font name, run the following command to return the first matching font:
fc-match Font-Name
Note:
To view more parameters and information, run fc-list --help.

Input Method

This section describes how to use Pinyin and Wubi input methods in the graphical interface through the IBus (Intelligent Input Bus) input method framework.

(Optional) Installing a Graphical Interface

If the current system already has a graphical interface, you can skip this step.
1. Run the following command to install the graphical interface:
dnf groupinstall 'Server with GUI'
2. Run the following command to set the graphical mode as the default boot target:
systemctl set-default graphical.target
3. Run the following command to restart the system for the configuration to take effect:
Note:
During the restart, the instance will be unable to provide services normally. Therefore, before restarting, ensure that the instance has paused business requests.
reboot

Installing a Chinese Input Method

Run the following command to install the Pinyin input method:
dnf install ibus-libpinyin
The system provides two Wubi input methods: "Haifeng Wubi" and "Jidian Wubi". Select one to install as needed. Run the following command to install the Haifeng Wubi input method:
dnf install ibus-table-chinese-wubi-haifeng
Run the following command to install the Jidian Wubi input method:
dnf install ibus-table-chinese-wubi-jidian
After the installation is complete, run the following command to restart the system for the input method to take effect:
Note:
During the restart, the instance will be unable to provide services normally. Therefore, before restarting, ensure that the instance has paused business requests.
reboot

Configuring Input Methods

After restarting and entering the graphical interface, go to System Settings, select Input Sources in Keyboard, click + to add an input method, select Chinese (China), and add the desired input method. GNOME displays the currently selected input source on the menu bar. The default shortcut for switching input methods is Super + Space, where the Super key is usually the Windows key (logo key).
To view all Chinese input methods provided by the system, run the following command to see the available list:
dnf list ibus-table-chinese*
The returned result is as follows:
Last metadata expiration check: 2:34:07 ago on Thu May 25 13:03:02 2023.
Available Packages
ibus-table-chinese.noarch 1.8.11-3.ocs23 AppStream
# Array Input Method
ibus-table-chinese-array.noarch 1.8.11-3.ocs23 AppStream
# Cangjie Input Method
ibus-table-chinese-cangjie.noarch 1.8.11-3.ocs23 AppStream
# Cantonese Input Method
ibus-table-chinese-cantonese.noarch 1.8.11-3.ocs23 AppStream
# Yale Romanization-Based Cantonese Input Method
ibus-table-chinese-cantonyale.noarch 1.8.11-3.ocs23 AppStream
# Easy Input Method
ibus-table-chinese-easy.noarch 1.8.11-3.ocs23 AppStream
# Two-Stroke Input Method
ibus-table-chinese-erbi.noarch 1.8.11-3.ocs23 AppStream
# Quick Input Method
ibus-table-chinese-quick.noarch 1.8.11-3.ocs23 AppStream
# Quick Cangjie Input Method
ibus-table-chinese-scj.noarch 1.8.11-3.ocs23 AppStream
# Stroke Order Five-Code Input Method
ibus-table-chinese-stroke5.noarch 1.8.11-3.ocs23 AppStream
# Shanghai Wu Phonetic Input Method
ibus-table-chinese-wu.noarch 1.8.11-3.ocs23 AppStream
# Haifeng Wubi Input Method
ibus-table-chinese-wubi-haifeng.noarch 1.8.11-3.ocs23 AppStream
# Jidian Wubi 86 Input Method with Jishuang Lexicon 6.0
ibus-table-chinese-wubi-jidian.noarch 1.8.11-3.ocs23 AppStream
# Yongma Input Method
ibus-table-chinese-yong.noarch 1.8.11-3.ocs23 AppStream


도움말 및 지원

문제 해결에 도움이 되었나요?

피드백