![更新](https://linux22.com/image/163378/%E6%9B%B4%E6%96%B0.png)
我想在 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?)
答案1
看起来你正在 FreeBSD 上尝试 Linuxism。在 FreeBSD 上你应该使用登录类
有一个关于语言环境的很好的一般描述我应该将区域设置设置为什么?这样做会产生什么影响?。
该答案中您可以忽略的部分是“安装语言环境”。 FreeBSD 附带安装了所有常见的语言环境。您可以通过以下方式验证这一点
locale -a
但后来你大概声称您尝试修改区域设置并进行设置。这就是我所说的 Linuxism。人们添加了语言环境到linux而不了解实际发生了什么,然后设置LC_ALL。这语言环境定义一组LC_*
变量。LC_ALL
然后用于覆盖那些!
在 FreeBSD 上,更改用户(或系统)的区域设置的首选方法是使用22.2.1.1。登录类方法。您也可以在此处更改系统范围的默认值。
仅当您想要(强制)否决任何和所有其他 LC_* 设置时才应设置 LC_ALL。您可能认为您正在设置“区域设置”,LC_ALL
但实际上您只是设置LANG
为LANG=en_DK.UTF-8
。这不是一种有效的语言,您应该将其留给Unicode CLDR 项目。有关更多信息,请查看“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 到 FreeBSD(UTF-8)
我认为你的答案就在上面的某个地方。但如果我们逐字逐句地回答你的问题,那么当前的 FreeBSD 将在 13.0 中添加 UTF-8 C 语言环境(请参阅提交 r340144)。如果您真的想了解如何添加新语言环境然后看看引入C.UTF-8语言环境
更新
目录/usr/share/locale/*
只是一个目录。如果您按照 Q 中的方式进行逐字复制,则可以在 FreeBSD 11.2 上运行。我仍然建议使用详细LC_ALL
或登录类。目前我认为问题是“胖手指”。
该目录包含符号链接和定义文件。这些文件可以通过以下方式创建本地定义它取代了2015 年 mklocale。
如果您不想更改实际的排序顺序,则可以链接到具有“正确”排序顺序的语言 - 或者只需复制文件。PATH_LOCALE=/usr/share/locale
是隐式的,因为它是默认的。
我在我的系统上逐字复制到test
和en_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 [email protected]:/usr/obj/usr/src/sys/GENERIC amd64