Locale

fr_FR.UTF-8 和 C.UTF-8 語言環境在語言環境列表中不可用,因此我無法使用它們

  • May 15, 2019

fr_FR.UTF-8和語言環境在C.UTF-8語言環境列表(由 給出locale -a)中不可用,因此我無法使用它們。

這是我嘗試添加它們的方法:

$ sudo locale-gen en_US en_US.UTF-8 fr_FR fr_FR.UTF-8 
Generating locales...
 en_US.ISO-8859-1... up-to-date
 en_US.UTF-8... up-to-date
 fr_FR.ISO-8859-1... up-to-date
 fr_FR.UTF-8... up-to-date
Generation complete.
$ sudo dpkg-reconfigure locales 
Generating locales...
 en_AG.UTF-8... done
 en_AU.UTF-8... done
 en_BW.UTF-8... done
 en_CA.UTF-8... done
 en_DK.UTF-8... done
 en_GB.UTF-8... done
 en_HK.UTF-8... done
 en_IE.UTF-8... done
 en_IN.UTF-8... done
 en_NG.UTF-8... done
 en_NZ.UTF-8... done
 en_PH.UTF-8... done
 en_SG.UTF-8... done
 en_US.ISO-8859-1... up-to-date
 en_US.UTF-8... up-to-date
 en_ZA.UTF-8... done
 en_ZM.UTF-8... done
 en_ZW.UTF-8... done
 fr_BE.UTF-8... done
 fr_CA.UTF-8... done
 fr_CH.UTF-8... done
 fr_FR.ISO-8859-1... up-to-date
 fr_FR.UTF-8... up-to-date
 fr_LU.UTF-8... done
Generation complete.
$ export LC_CTYPE=C.UTF-8
$ export LC_COLLATE=C.UTF-8
$ export LC_MESSAGES=fr_FR.UTF-8
$ locale -a
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_COLLATE to default locale: No such file or directory
C
POSIX
en_US.utf8

編輯 1:在我的系統上,locale-gen可以接受參數,因為它有點舊(包語言環境 v2.13)。

無論如何,涉及的其他方法/etc/locale.gen也不起作用:

$ cat <<-EOF | sudo tee -a /etc/locale.gen
en_US.UTF-8 UTF-8
en_US ISO-8859-1
en_US.ISO-8859-15 ISO-8859-15
fr_FR.UTF-8 UTF-8
fr_FR ISO-8859-1
fr_FR@euro ISO-8859-15
EOF
en_US.UTF-8 UTF-8
en_US ISO-8859-1
en_US.ISO-8859-15 ISO-8859-15
fr_FR.UTF-8 UTF-8
fr_FR ISO-8859-1
fr_FR@euro ISO-8859-15
$ sudo locale-gen
Generating locales...
 en_AG.UTF-8... up-to-date
 en_AU.UTF-8... up-to-date
 en_BW.UTF-8... up-to-date
 en_CA.UTF-8... up-to-date
 en_DK.UTF-8... up-to-date
 en_GB.UTF-8... up-to-date
 en_HK.UTF-8... up-to-date
 en_IE.UTF-8... up-to-date
 en_IN.UTF-8... up-to-date
 en_NG.UTF-8... up-to-date
 en_NZ.UTF-8... up-to-date
 en_PH.UTF-8... up-to-date
 en_SG.UTF-8... up-to-date
 en_US.ISO-8859-1... up-to-date
 en_US.UTF-8... up-to-date
 en_ZA.UTF-8... up-to-date
 en_ZM.UTF-8... up-to-date
 en_ZW.UTF-8... up-to-date
 fr_BE.UTF-8... up-to-date
 fr_CA.UTF-8... up-to-date
 fr_CH.UTF-8... up-to-date
 fr_FR.ISO-8859-1... up-to-date
 fr_FR.UTF-8... up-to-date
 fr_LU.UTF-8... up-to-date
Generation complete.
$ locale -a
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_COLLATE to default locale: No such file or directory
C
POSIX
en_US.utf8

fr_FR.UTF-8和語言環境在 . 給出的C.UTF-8語言環境列表中仍然不可用locale -a

我該怎麼做?

請大家不要生我的氣:)

我終於找到了原因,我的 PATH 出了點問題:

$ ssh localhost locale -a >/dev/null
$ which -a locale
/home/linuxbrew/.linuxbrew/bin/locale
/usr/bin/locale
$ /home/linuxbrew/.linuxbrew/bin/locale -a >/dev/null 
/home/linuxbrew/.linuxbrew/bin/locale: Cannot set LC_CTYPE to default locale: No such file or directory
/home/linuxbrew/.linuxbrew/bin/locale: Cannot set LC_MESSAGES to default locale: No such file or directory
/home/linuxbrew/.linuxbrew/bin/locale: Cannot set LC_COLLATE to default locale: No such file or directory
$ /usr/bin/locale -a >/dev/null
$ /usr/bin/locale -a | egrep -i "(C|fr_FR|en_US).utf-?8"
C.UTF-8
en_US.utf8
fr_FR.utf8

locale-gen不接受任何命令行參數。相反,它讀取/etc/locale.gen要生成的語言環境列表。

編輯/etc/locale.gen以取消註釋您想要的語言環境,然後locale-gen再次執行。

或者,如果 中沒有註釋掉的行/etc/locale.gen,找到支持的語言環境列表並從那裡複製;在 Debian(以及可能的相關發行版)中,您可以在/usr/share/i18n/SUPPORTED.

引用自:https://unix.stackexchange.com/questions/518723