Locale
Locale
後記
後來發現,修改「/etc/default/locale」,只要留下一行就可以切換了
預設英文界面,設定「/etc/default/locale」如下:
LANG="en_US.UTF-8"
預設中文界面,設定「/etc/default/locale」如下:
LANG="zh_TW.UTF-8"
這樣設定的好處,就是其他的「LC_*」不會被寫死,
然後若使用「LightDM」登入時,可以選擇不同的語系登入,
登入後就會自動切換語系,操作界面也會隨之切換了。
以下是原本文章的論述,沒有刪除,對照參考用。
範例 Script
更多參考
- The Debian Administrator’s Handbook / 8.1. Configuring the System for Another Language
- Debian Wiki / Locale
- Debian Wiki / ChangeLanguage
- Ubuntu Community Help Wiki / Locale
修改說明
我是選擇英文來安裝,時區選「Asia/Taipei」,安裝程式會將「/etc/default/locale」設定如下
# File generated by update-locale
LANG="en_US.UTF-8"
LC_NUMERIC="lzh_TW"
LC_TIME="lzh_TW"
LC_MONETARY="lzh_TW"
LC_PAPER="lzh_TW"
LC_NAME="lzh_TW"
LC_ADDRESS="lzh_TW"
LC_TELEPHONE="lzh_TW"
LC_MEASUREMENT="lzh_TW"
LC_IDENTIFICATION="lzh_TW"
而我個人習慣是使用英文界面,所以會改成設定如下
# File generated by update-locale
LANG="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
重新登入系統後,
接著執行下面指令
$ locale
顯示
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC=en_US.UTF-8
LC_TIME=en_US.UTF-8
LC_COLLATE="en_US.UTF-8"
LC_MONETARY=en_US.UTF-8
LC_MESSAGES="en_US.UTF-8"
LC_PAPER=en_US.UTF-8
LC_NAME=en_US.UTF-8
LC_ADDRESS=en_US.UTF-8
LC_TELEPHONE=en_US.UTF-8
LC_MEASUREMENT=en_US.UTF-8
LC_IDENTIFICATION=en_US.UTF-8
LC_ALL=
額外一提
若是要中文介面,則要將「/etc/default/locale」改成設定如下
# File generated by update-locale
LANG="zh_TW.UTF-8"
LC_NUMERIC="zh_TW.UTF-8"
LC_TIME="zh_TW.UTF-8"
LC_MONETARY="zh_TW.UTF-8"
LC_PAPER="zh_TW.UTF-8"
LC_NAME="zh_TW.UTF-8"
LC_ADDRESS="zh_TW.UTF-8"
LC_TELEPHONE="zh_TW.UTF-8"
LC_MEASUREMENT="zh_TW.UTF-8"
LC_IDENTIFICATION="zh_TW.UTF-8"
接著要登出系統,再登入系統,
然後再執行下面指令
$ locale
有可能會顯示
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=zh_TW.UTF-8
LANGUAGE=
LC_CTYPE="zh_TW.UTF-8"
LC_NUMERIC=zh_TW.UTF-8
LC_TIME=zh_TW.UTF-8
LC_COLLATE="zh_TW.UTF-8"
LC_MONETARY=zh_TW.UTF-8
LC_MESSAGES="zh_TW.UTF-8"
LC_PAPER=zh_TW.UTF-8
LC_NAME=zh_TW.UTF-8
LC_ADDRESS=zh_TW.UTF-8
LC_TELEPHONE=zh_TW.UTF-8
LC_MEASUREMENT=zh_TW.UTF-8
LC_IDENTIFICATION=zh_TW.UTF-8
LC_ALL=
會多出現三行
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
只要執行下面的指令,就可以解決
$ sudo locale-gen zh_TW.UTF-8
再執行「locale」,就不會出現上面那三行,會顯示
LANG=zh_TW.UTF-8
LANGUAGE=
LC_CTYPE="zh_TW.UTF-8"
LC_NUMERIC=zh_TW.UTF-8
LC_TIME=zh_TW.UTF-8
LC_COLLATE="zh_TW.UTF-8"
LC_MONETARY=zh_TW.UTF-8
LC_MESSAGES="zh_TW.UTF-8"
LC_PAPER=zh_TW.UTF-8
LC_NAME=zh_TW.UTF-8
LC_ADDRESS=zh_TW.UTF-8
LC_TELEPHONE=zh_TW.UTF-8
LC_MEASUREMENT=zh_TW.UTF-8
LC_IDENTIFICATION=zh_TW.UTF-8
LC_ALL=
執行完「sudo locale-gen zh_TW.UTF-8」成功後,接著可以執行下面指令
$ locale -a
會出現一個列表,應該可以看到其中一行是「zh_TW.UTF-8」。
另外「locale-gen」也可以接多個參數,例如可以執行「sudo locale-gen zh_TW zh_TW.UTF-8 zh_CN.UTF-8 en_US.UTF-8」。
另外有些軟體,要顯示中文訊息,也需要額外安裝相關的「language-pack」,可以執行下面指令,查詢相關的套件。
$ apt-cache search language-pack | grep zh
顯示
language-pack-gnome-zh-hans - GNOME translation updates for language Simplified Chinese
language-pack-gnome-zh-hans-base - GNOME translations for language Simplified Chinese
language-pack-gnome-zh-hant - GNOME translation updates for language Traditional Chinese
language-pack-gnome-zh-hant-base - GNOME translations for language Traditional Chinese
language-pack-zh-hans - translation updates for language Simplified Chinese
language-pack-zh-hans-base - translations for language Simplified Chinese
language-pack-zh-hant - translation updates for language Traditional Chinese
language-pack-zh-hant-base - translations for language Traditional Chinese
language-pack-kde-zh-hans - KDE translation meta package for language zh_CN
language-pack-kde-zh-hant - KDE translation meta package for language zh_TW
或是也可以使用「check-language-support」這個指令,來查詢相關的套件。
例如執行
$ check-language-support -l zh
或是執行
$ check-language-support -l zh_TW
相關討論
- [索引] 文件編碼
- [索引] 套件操作實務
- #10 回覆: 安裝 ubuntu server 1604時發生這樣的問題
- #11 回覆: 安裝 ubuntu server 1604時發生這樣的問題
- #4 回覆: ubuntun 14.04, psql 無法使用
- #4 回覆: 手機照片無法預覽
- #8 回覆: Kubuntu 15.04 (Plasma 5.0) Fcitx、gcin輸入法無法打中文