如何在 Ubuntu 12.04 上安装 cs_CZ.ISO8859-2 语言环境

如何在 Ubuntu 12.04 上安装 cs_CZ.ISO8859-2 语言环境

我需要 Ubuntu 12.04 上存在 cs_CZ.ISO8859-2 语言环境,以便特定的单元测试可以通过。该测试进行以下调用:

std::locale("cs_CZ.ISO8859-2")

在我安装的 OS X Lion 上,该语言环境确实存在,因此对 std::locale 的调用应该有效:

$ locale -a | grep cs
cs_CZ
cs_CZ.ISO8859-2
cs_CZ.UTF-8
$

然而,在我安装的 Ubuntu 12.04 上,尽管已安装,但只有 UTF8 变体,并且没有 ISO8859-2 版本的 cs_CZ 语言环境language-pack-cs

$ dpkg -l | grep language-pack-cs
ii  language-pack-cs                       1:12.04+20120417                        translation updates for language Czech
ii  language-pack-cs-base                  1:12.04+20120417                        translations for language Czech
$ locale -a | grep cs_
cs_CZ.utf8
$

在这台机器上单元测试失败。在 strace 下运行单元测试表明它确实在寻找 ISO8859-2 变体,但在任何地方都找不到它:

open("/usr/lib/locale/cs_CZ.ISO8859-2/LC_CTYPE", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/cs_CZ.iso88592/LC_CTYPE", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/cs_CZ/LC_CTYPE", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/cs.ISO8859-2/LC_CTYPE", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/cs.iso88592/LC_CTYPE", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib/locale/cs/LC_CTYPE", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/cs_CZ.ISO8859-2/LC_CTYPE", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/cs_CZ.iso88592/LC_CTYPE", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/cs_CZ/LC_CTYPE", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/cs.ISO8859-2/LC_CTYPE", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/cs.iso88592/LC_CTYPE", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/cs/LC_CTYPE", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)

我对语言环境、i18n 等一无所知。但是,我希望通过此测试,并且无法更改测试。如果有人能够提供有关如何使该语言环境存在于 Ubuntu 12.04 上的任何见解,我将不胜感激。

答案1

以下步骤适用于 Arch Linux(不确定 Ubuntu 是否适用)。

  1. 编辑文件/etc/locale.gen
  2. 添加行cs_CZ ISO-8859-2
  3. 运行sudo locale-gen以生成语言环境文件。

之后std::locale("cs_CZ.ISO8859-2")应该可以正常工作。

答案2

Ubuntu 已经调整了locale-gen公用事业。使用您想要生成的语言环境的名称来调用它。

locale-gen cs_CZ.ISO8859-2

相关内容