Skip to content

Chinese

标签
Linux
Chinese
Font
Flatpak
字数
1602 字
阅读时间
9 分钟

1 Basic Chinese Support

1.1 Locale Settings

1.1.1 Install Chinese Locale

It is recommended to use UTF-8 locale. You need to modify /etc/locale.gen to set the locales that can be used in the system (erase the comment symbol "#" before the corresponding item):

en_US.UTF-8 UTF-8
zh_CN.UTF-8 UTF-8

After executing locale-gen, the selected locales can be used in the system. You may use locale to view the currently used locale(s), and locale -a to view the currently available locales.

1.1.2 Enable Chinese Locales

Warning: Globally setting Chinese locales in /etc/locale.conf will cause tty to display garbled texts due to the tty glyph limitation of Linux kernel. To properly display Chinese characters under tty, install and configure zhconAUR.

1.1.2.1 Set the Global Default Locale to English (optional)

To avoid the tty garbled text issue mentioned above, globally set the LANG locale to en_US.UTF-8 in /etc/locale.conf:

LANG=en_US.UTF-8
1.1.2.2 User-specific Locales

You may set your own user environment variables in ~/.bashrc, ~/.xinitrc, or ~/.xprofile.

  • .bashrc: Settings are applied everytime you log in using the terminal.
  • .xinitrc: Settings are applied everytime you use startx or SLiM to start the X interface.
  • .xprofile: Settings are applied everytime you log in using a display manager such as GDM.
1.1.2.3 Set Chinese Locales for Graphical Interfaces

It is not recommended to set a global Chinese locale in /etc/locale.conf because it causes tty to display garbled characters.

As mentioned earlier, Chinese locale can be set separately in ~/.xinitrc or ~/.xprofile. Prepend the following two lines to one of the two files (if you are not sure which file to use, prepend to both):

export LANG=zh_CN.UTF-8  
export LANGUAGE=zh_CN:en_US

Note:

  • Be sure to put them before the exec __example_WM_or_DE__ line in ~/.xinitrc.
  • This method is suitable for SLiM users or for people who do not use a graphical login interface (aka greeter). GDM and SDDM users can configure the display language in GNOME or KDE settings.
  • It is not recommended to override all locale settings with a global export LC_ALL. LC_ALL should be reserved for diagnostic debugging purposes only. LC_ALL will bring unnecessary difficulties for diagnosing language settings issues.
  • KDE
    • edit ~/. config/plasma-localerc
    • sudo locale-gen
[Formats]
LANG=zh_CN.UTF-8

[Translations]
LANGUAGE=zh_CN:en_US

1.2 Chinese Fonts

1.2.1 Install Fonts

bash
sudo pacman -S adobe-source-han-sans-cn-fonts adobe-source-han-serif-cn-fonts noto-fonts-cjk wqy-microhei wqy-microhei-lite wqy-bitmapfont wqy-zenhei ttf-arphic-ukai ttf-arphic-uming ttf-sarasa-gothic

1.2.2 Chinese Characters Displayed as Variant (Japanese) Glyphs

After installing Noto Sans CJK adobe-source-han-sans-otc-fonts (Source Han Sans, lit. Siyuan Bold), or Noto Serif CJK adobe-source-han-serif-otc-fonts (Source Han Serif, lit. Siyuan Song), in some cases (framework undefined area), rendered Chinese characters do not match the standard form, such as 门, 关, and 复.

This is because different default fonts can be set in each program, such as Arial or Tahoma, and the attributes of these fonts are controlled by fontconfig. The order of use is based on the regional code and the default order of A-Z. Since ja-JP is before zh_{CN,HK,SG,TW}, Japanese fonts are used first.
Tip: Fonts can be set separately in Chromium/Chrome/Firefox browser settings, for example, adjust the font option to Noto xxx CJK SC.
You can use the following methods to solve the issue (taking simplified Chinese as an example):

Create a file under /etc/fonts/conf.d/ or /etc/fonts/conf.avail/, such as 64-language-selector-prefer.conf, or modify or create ~/.config/fontconfig/fonts.conf (only effective for the user):

html
<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<fontconfig>
 <dir>~/.fonts</dir>
  <alias>
  <family>serif</family>
  <prefer>
   <family>Sarasa Gothic SC</family>
   <family>Sarasa Gothic TC</family>
   <family>Sarasa Gothic J</family>
   <family>Sarasa Gothic K</family>
  </prefer>
 </alias>
 <alias>
  <family>sans-serif</family>
  <prefer>
   <family>Sarasa Gothic SC</family>
   <family>Sarasa Gothic TC</family>
   <family>Sarasa Gothic J</family>
   <family>Sarasa Gothic K</family>
  </prefer>
 </alias>
 <alias>
  <family>monospace</family>
  <prefer>
   <family>Sarasa Mono SC</family>
   <family>Sarasa Mono TC</family>
   <family>Sarasa Mono J</family>
   <family>Sarasa Mono K</family>
  </prefer>
 </alias>
 <match target="font">
  <edit mode="assign" name="rgba">
   <const>rgb</const>
  </edit>
 </match>
 <match target="font">
  <edit mode="assign" name="hinting">
   <bool>true</bool>
  </edit>
 </match>
 <match target="font">
  <edit mode="assign" name="hintstyle">
   <const>hintslight</const>
  </edit>
 </match>
 <match target="font">
  <edit mode="assign" name="antialias">
   <bool>true</bool>
  </edit>
 </match>
</fontconfig>

Note that if you create an xml file under /etc/fonts/conf.avail, for example:

ln -s /etc/fonts/conf.avail/64-language-selector-prefer.conf /etc/fonts/conf.d/64-language-selector-prefer.conf

you have to update the font cache to take effect:

fc-cache -fv

Execute the following command to check. If NotoSansCJK-Regular.ttc: "Noto Sans CJK SC" "Regular" appears, the settings are successfully applied:

fc-match -s | grep 'Noto Sans CJK'

1.3 Chinese Input Method

1.3.1 Install

bash
sudo pacman -S fcitx5-im fcitx5-rime
1.3.1.1 Model

要获取更好的体验,你可以根据需要安装以下模块。即使不安装,输入法在大部分的应用程序中仍可能正常工作,但你可能会遇到输入法挂起、预览窗口位置错误或没有预览的问题。

提示:通常,只需安装 fcitx5-qt 包和 fcitx5-gtk 包就足够了。(Include in fcitx5-im)

1.3.2 Usage

1.3.2.1 集成
GTK_IM_MODULE=fcitx
QT_IM_MODULE=fcitx
XMODIFIERS=@im=fcitx
SDL_IM_MODULE=fcitx
INPUT_METHOD=fcitx
GLFW_IM_MODULE=fcitx
1.3.2.1.1 KDE Wayland
  • 要使用 Wayland 输入法协议, 首先退出正在运行的 Fcitx 5 进程, 前往 系统设置 > 输入设备 > 虚拟键盘, 选择 Fcitx 5.
  • 对于 XWayland 程序, 设置 XMODIFIERS 环境变量

1.3.3 Configure

1.3.3.1 配置工具

fcitx5 包的配置文件位于 ~/.config/fcitx5,尽管您可以使用文本编辑器编辑配置文件,但是使用 GUI 配置显然更方便。安装 fcitx5-configtool 软件包。(Include in fcitx5-im)

2 Cultural Configuration in Software

2.1 Firefox

sudo pacman -S firefox-i18n-zh-cn

2.2 Libreoffice

sudo pacman -S libreoffice-fresh-zh-cn

3 Fix Chinese under Flatpak

[XDG_Desktop_Portal](https://wiki.archlinux.org/title/XDG_Desktop_Portal)

  1. 安装 xdg-desktop-portalxdg-desktop-portal-gtk
    这些组件有助于改进 Flatpak 应用的字体渲染和整体显示效果:

    sh
    sudo pacman -S xdg-desktop-portal xdg-desktop-portal-gtk
  2. 安装 Flatseal
    Flatseal 是一个管理 Flatpak 应用权限的工具,可以轻松调整应用的设置:

    sh
    flatpak install flathub com.github.tchx84.Flatseal
  3. 配置 Flatpak 应用的字体访问权限
    使用 Flatseal 配置应用权限以访问系统字体:

    • 打开 Flatseal

    • All Applications 中选择你想要调整的应用。

    • 进入 Filesystem 选项。

    • Other files 中添加以下路径:

      xdg-config/fontconfig:ro
  • Environment 中添加以下变量:

    export GDK_DPI_SCALE=1
  1. 设置 DPI 环境变量
    在你的配置文件中添加 GDK_DPI_SCALE 环境变量以调整应用的 DPI 设置:
    • 编辑你的 .profile.bashrc 文件,添加如下行:

      bash
      export GDK_DPI_SCALE=1
    • 保存文件后,执行以下命令来应用更改:

      bash
      source ~/.profile  # 或者 source ~/.bashrc