Freebsd

在 FreeBSD 上創建一個新的語言環境

  • November 4, 2019

我想在 FreeBSD 上創建一個新的語言環境。我以為我可以只複製現有的一個,/usr/share/locale但顯然它不是那麼簡單。

en_US.UTF-8首先,我只是創建了一個語言環境的副本。

$ sudo cp -R /usr/share/locale/en_US.UTF-8 /usr/share/locale/en_DK.UTF-8

我正在用 mosh 測試我的設置,所以使用標準en_US.UTF-8一切都很好:

$ LC_ALL=en_US.UTF-8 PATH_LOCALE=/usr/share/locale mosh xyz.example.org

但是,如果我嘗試使用新創建的en_DK.UTF-8語言環境,我會收到以下錯誤:

$ LC_ALL=en_DK.UTF-8 PATH_LOCALE=/usr/share/locale mosh xyz.example.org
The locale requested by LC_ALL=en_DK.UTF-8 isn't available here.
Running `locale-gen en_DK.UTF-8' may be necessary.

mosh-server needs a UTF-8 native locale to run.

Unfortunately, the local environment ([no charset variables]) specifies
the character set "US-ASCII",

The client-supplied environment (LC_ALL=en_DK.UTF-8) specifies
the character set "US-ASCII".

sh: warning: setlocale: LC_ALL: cannot change locale (en_DK.UTF-8)
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=en_DK.UTF-8
LC_CTYPE="en_DK.UTF-8"
LC_NUMERIC="en_DK.UTF-8"
LC_TIME="en_DK.UTF-8"
LC_COLLATE="en_DK.UTF-8"
LC_MONETARY="en_DK.UTF-8"
LC_MESSAGES="en_DK.UTF-8"
LC_PAPER="en_DK.UTF-8"
LC_NAME="en_DK.UTF-8"
LC_ADDRESS="en_DK.UTF-8"
LC_TELEPHONE="en_DK.UTF-8"
LC_MEASUREMENT="en_DK.UTF-8"
LC_IDENTIFICATION="en_DK.UTF-8"
LC_ALL=en_DK.UTF-8
Connection to xyz.example.org closed.
/usr/local/bin/mosh: Did not find mosh server startup message. (Have you installed mosh on your server?)

看來您正在 FreeBSD 上嘗試 Linuxism。在 FreeBSD 上,您應該使用登錄類

我應該將我的語言環境設置為什麼以及這樣做的含義是什麼?.

該答案中您可以忽略的部分是“安裝語言環境”。FreeBSD 安裝了所有常見的語言環境。您可以通過以下方式驗證這一點

locale -a

但是您可能聲稱您嘗試修改語言環境並進行設置。這就是我所說的 Linux 主義。人們在不了解實際發生的情況下將語言環境添加到 linux,然後設置 LC_ALL。**語言環境定義了一組LC_*變數。LC_ALL然後用於覆蓋那些!

在 FreeBSD 上,更改使用者(或系統)區域設置的首選方法是使用22.2.1.1。登錄類方法。您也可以在此處更改系統範圍的預設值。

LC_ALL 只有在您想(強制)否決任何和所有其他 LC_* 設置時才應設置。您可能認為您正在設置“語言環境”,LC_ALL但實際上您只是設置LANGLANG=en_DK.UTF-8. 那不是一種有效的語言,你應該把它留給Unicode CLDR Project。有關這方面的更多資訊,請查看“LC_ALL=C”做什麼?

我的問題是你不想發明你自己的新語言。但是從您選擇的組合中,我的猜測是您希望系統表現得像丹麥(DK)系統,但與您說英語。為此,您可以將LC_*變數與熱量內容混合併匹配。

例子:

LANG=en_US.UTF-8
LC_CTYPE="da_DK.UTF-8"
LC_COLLATE="da_DK.UTF-8"
LC_TIME="da_DK.UTF-8"
LC_NUMERIC="da_DK.UTF-8"
LC_MONETARY="da_DK.UTF-8"
LC_MESSAGES="en_US.UTF-8"

如果您不想設置登錄類(出於某種原因),那麼您仍然應該堅持使用 CLDR 定義的變數。這將為您提供最便攜的結果:

$ LC_ALL=C LANG=en_US.UTF-8 LC_CTYPE=da_DK.UTF-8 LC_COLLATE=da_DK.UTF-8 LC_TIME=da_DK.UTF-8 LC_NUMERIC=da_DK.UTF-8 LC_MONETARY=da_DK.UTF-8 LC_MESSAGES=en_US.UTF-8 mosh xyz.example.org
/usr/local/bin/mosh: could not get canonical name for xyz.example.org: hostname nor servname provided, or not known
ssh_exchange_identification: Connection closed by remote host
/usr/local/bin/mosh: Did not find remote IP address (is SSH ProxyCommand disabled?).
$

如果它是您想要常用的語言環境設置,那麼您可以使用登錄類進行設置。請參閱 FreeBSD 手冊或我對SSH to FreeBSD in UTF-8 的回答

我認為你的答案在上面的某個地方。但是,如果我們逐字詢問,那麼 FreeBSD 目前將在 13.0 中添加 UTF-8 C 語言環境(請參閱送出 r340144)。如果您真的想了解如何添加新語言環境,請查看介紹 C.UTF-8 語言環境

更新

該目錄/usr/share/locale/*只是一個目錄。如果您像 Q 中那樣進行逐字複製,那麼 FreeBSD 11.2 上就可以工作。我仍然建議使用詳細LC_ALL或登錄類。目前我認為問題在於*“胖手指”*。

該目錄包含符號連結和定義文件。這些文件可以由localdef創建,它在 2015 年取代了 mklocale 。

如果您不想更改實際的排序順序,那麼您可以連結到具有“正確”排序順序的語言 - 或簡單地複製文件。PATH_LOCALE=/usr/share/locale是隱含的,因為它是預設值。

我在我的系統上逐字複製到testen_DK.UTF-8. 他們locale -a立即出現。兩者都按預期工作:

$ locale -a | grep -e en_DK -e test
en_DK.UTF-8
test
$ LC_ALL=test mosh xyz.example.org
/usr/local/bin/mosh: could not get canonical name for xyz.example.org: hostname nor servname provided, or not known
ssh_exchange_identification: Connection closed by remote host
/usr/local/bin/mosh: Did not find remote IP address (is SSH ProxyCommand disabled?).
$ LC_ALL=test /bin/sh
$ locale
LANG=
LC_CTYPE="test"
LC_COLLATE="test"
LC_TIME="test"
LC_NUMERIC="test"
LC_MONETARY="test"
LC_MESSAGES="test"
LC_ALL=test
$ exit
$ LC_ALL=en_DK.UTF-8 mosh xyz.example.org
/usr/local/bin/mosh: could not get canonical name for xyz.example.org: hostname nor servname provided, or not known
ssh_exchange_identification: Connection closed by remote host
/usr/local/bin/mosh: Did not find remote IP address (is SSH ProxyCommand disabled?).
$ LC_ALL=dummy mosh xyz.example.org
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
       LC_ALL = "dummy",
       LANG = (unset)
   are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
       LC_ALL = "dummy",
       LANG = (unset)
   are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
/usr/local/bin/mosh: could not get canonical name for xyz.example.org: hostname nor servname provided, or not known
ssh_exchange_identification: Connection closed by remote host
/usr/local/bin/mosh: Did not find remote IP address (is SSH ProxyCommand disabled?).
$ uname -a
FreeBSD test 11.2-RELEASE FreeBSD 11.2-RELEASE #0 r335510: Fri Jun 22 04:32:14 UTC 2018     root@releng2.nyi.freebsd.org:/usr/obj/usr/src/sys/GENERIC  amd64

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