第8章 I18N と L10N

目次

8.1. ロケール
8.1.1. UTF-8 ロケールを使う根拠
8.1.2. ロケールの再設定
8.1.3. ファイル名の符号化方式
8.1.4. 地域化されたメッセージと翻訳された文書
8.1.5. ロケールの効果
8.2. キーボード入力
8.2.1. The keyboard input for Linux console and X Window
8.2.2. Wayland 向けのキーボード入力
8.2.3. IBus を使うインプットメソッドのサポート
8.2.4. 日本語の例
8.3. ディスプレー出力
8.4. 東アジア不明瞭文字幅文字

アプリケーションソフトの多言語化 (M17N) とかネイティブ言語サポートは2段階で行います。

[ヒント] ヒント

There are 17, 18, or 10 letters between "m" and "n", "i" and "n", or "l" and "n" in multilingualization, internationalization, and localization which correspond to M17N, I18N, and L10N. See Introduction to i18n for details.

The behavior of programs supporting internationalization are configured by the environment variable "$LANG" to support localization. Actual support of locale dependent features by the libc library requires to install locales or locales-all packages. The locales package requires to be initialized properly.

If neither locales or locales-all package are installed, support of locale features are lost and system uses US English messages and handles data as ASCII. This behavior is the same way as "$LANG" is set by "LANG=", "LANG=C", or "LANG=POSIX".

GNOME や KDE 等の現代的なソフトは多言語化されています。UTF-8 データーを扱えるようにすることで国際化され、gettext(1) インフラで翻訳されたメッセージを提供することで地域化されています。翻訳されたメッセージは別の地域化パッケージとして供給されているかもしれません。

The current Debian desktop GUI system normally sets the locale under GUI environment as "LANG=xx_YY.UTF-8". Here, "xx" is ISO 639 language codes and "YY" is ISO 3166 country codes. These values are set by the desktop configuration GUI dialogue and change the program behavior. See 「"$LANG" 変数」

テキストデータの最も単純な表現は ASCII で、英語には十分で 127 未満の文字 (7 ビットで表現可能) を使います。

プレーンな英語のテキストですら非 ASCII 文字を含んでいるかもしれません。例えば微妙に曲がった左右のクォテーションマークは ASCII 内では利用できません。

“double quoted text” is not "double quoted ASCII"
‘single quoted text’ is not 'single quoted ASCII'

より多くの文字をサポートするために、多くの言語をサポートする多数の文字集合とエンコーディング体系が使用されてきました (表11.2「符号化方式値とその使い方リスト」 を参照)。

ユニコード 文字セットは実質的に人類が知り得る全ての文字を21ビットのコードポイント範囲 (16進表記で 0 から 10FFFF まで) で表記できます。

Text encoding system UTF-8 fits Unicode code points into a sensible 8 bit data stream mostly compatible with the ASCII data processing system. This makes UTF-8 the modern preferred choice. UTF stands for Unicode Transformation Format. When ASCII plain text data is converted to UTF-8 one, it has exactly the same content and size as the original ASCII one. So you loose nothing by deploying UTF-8 locale.

Under UTF-8 locale with the compatible application program, you can display and edit any foreign language text data as long as required fonts and input methods are installed and enabled. For example under "LANG=fr_FR.UTF-8" locale, gedit(1) (text editor for the GNOME Desktop) can display and edit Chinese character text data while presenting menus in French.

[ヒント] ヒント

新標準の "en_US.UTF-8" ロケールと旧標準の "C"/"POSIX" ロケールは標準アメリカ英語のメッセージを使いますが、ソート順などでわずかに違います。古い "C" ロケールの挙動を保守する際に、ASCII 文字を扱うだけでなく、UTF-8 でエンコードされた全ての文字を優雅に扱いたい場合は、非標準の "C.UTF-8" ロケールを Debian で使います。

[注記] 注記

一部のプログラムは I18N をサポートした後でより多くのメモリーを消費するようになります。それらのプログラムは、実行速度最適化のために内部的に UTF-32 (UCS4) で Unicode のサポートをコードされていて、選ばれたロケールに無関係にそれぞれの ASCII 文字データー毎に4バイトを消費するからです。ここでも、UTF-8 ロケールを使ったからといって何も失うわけではありません。

クロスプラットフォームのデーター交換 (「リムーバブルストレージデバイス」参照下さい) のために、特定の符号化方式 (エンコーディング) でファイルシステムをマウントする必要があるかもしれません。例えば、vfat ファイルシステムに関して mount(8) はオプション無しの場合 CP437 とみなします。ファイル名に UTF-8 とか CP932 を使うためには明示的にマウントオプションを提供する必要があります。

[注記] 注記

GNOME のような現代的なデスクトップ環境の下では、デスクトップアイコンを右クリックし "Drive" タブをクリックし "Setting" を開くようにクリックし "Mount options:" に"utf8" を入力すれば、ホットプラグできる USB メモリーを自動マウントする時のマウントオプションを設定できます。このメモリースティックを次にマウントする機会には UTF-8 でのマウントが有効です。

[注記] 注記

もしシステムをアップグレードしたり旧式非 UTF-8 システムからディスクを移動したりする場合には、非 ASCII 文字のファイル名は ISO-8859-1 とか eucJP 等の今は非推奨の歴史的符号化方式で符号化をしているかもしれません。テキスト変換ツールの助力を得て、ファイル名を UTF-8 に変換します。「テキストデーター変換ツール」を参照下さい。

Samba は新規クライアント (Windows NT、200x、XP) には Unicode を使いますが、旧式クライアント (DOS、Windows 9x/Me) には CP850 をデフォールトで使います。この旧式クライアントへのデフォールトは "/etc/samba/smb.conf" ファイル中の "dos charset" を使って例えば日本語なら CP932 等と変更できます。

Debian システム中で表示されるエラーメッセージや標準のプログラムの出力やメニューやマニュアルページ等のテキストメッセージや文書の多くに翻訳があります。ほとんどの翻訳行為のバックエンドツールとして GNU gettext(1) コマンドツールチェインが使われています。

"Tasks" → "Localization" の下の aptitude(8) リストは地域化されたメッセージをアプリケーションに追加したり翻訳された文書を提供する有用なバイナリーパッケージの徹底的なリストを提供します。

例えば、manpages-LANG パッケージをインストールするとマンページで地域化したメッセージに使えるようになります。programname に関するイタリア語のマンページを "/usr/share/man/it/" から読むには、次を実行します。

LANG=it_IT.UTF-8 man programname

GNU gettext can accommodate priority list of translation languages with $LANGUAGE environment variable. For example:

 $ export LANGUAGE="pt:pt_BR:es:it:fr"

For more, see info gettext and read the section "The LANGUAGE variable".

sort(1) のソート順はロケールの言語選択に影響されます。スペイン語と英語のロケールではソート順が違います。

ls(1) の日付形式はロケールに影響されます。"LANG=C ls -l" と "LANG=en_US.UTF-8" の日付形式は違います (「時間と日付のカスタム化表示」を参照)。

Number punctuation are different for locales. For example, in English locale, one thousand point one is displayed as "1,000.1" while in German locale, it is displayed as "1.000,1". You may see this difference in spreadsheet program.

Each detail feature of "$LANG" environment variable may be overridden by setting "$LC_*" variables. These environment variables can be overridden again by setting "$LC_ALL" variable. See locale(7) manpage for the details. Unless you have strong reason to create complicated configuration, please stay away from them and use only "$LANG" variable set to one of the UTF-8 locales.

For GNOME on Wayland desktop system, 「The keyboard input for Linux console and X Window」 can't support non-English European languages. IBus was made to support not only Asian languages but also European languages. The package dependency of GNOME Desktop Environment recommends "ibus" via "gnome-shell". The code of "ibus" has been updated to integrate setxkbmap and XKB option functionalities. You need to configure ibus from "GNOME Settings" or "GNOME Tweaks" for the multilingualized keyboard input.

[注記] 注記

If ibus is active, your classic X keyboard configuration by the setxkbmap may be overridden by ibus even under classic X-based desktop environment. You can disable installed ibus using im-config to set input method to "None". For more, see Debian Wiki on keyboard.

Since GNOME Desktop Environment recommends "ibus" via "gnome-shell", "ibus" is the good choice for input method.

アプリケーションへの多言語入力は次のように処理されます。

Keyboard                                       Application
   |                                                 ^
   |                                                 |
   +-> Linux kernel ->  Input method (ibus)  -> Gtk, Qt, X, Wayland
                          +-- Engine--+

IBus とそのエンジンパッケージの一覧は以下の通りです。


[注記] 注記

For Chinese, "fcitx5" may be an alternative input method framework. For Emacs aficionados, "uim" may be an alternative. Either cases, you may need to do extra manual configuration with im-config. Some old classic input methods such as "kinput2" may still exist in Debian repository but are not recommended for the modern environment.

日本語インプットメソッドを英語環境 ("en_US.UTF-8") 下で起動すると非常に便利です。Wayland 環境下で IBus を使ってどう実現したかを以下に記します。

  1. Install the Japanese input tool package ibus-mozc (or ibus-anthy) with its recommended packages such as im-config.

  2. 有効になっていない場合は "Settings" → "Keyboard" → "Input Sources" → click "+" in "Input Sources" → "Japanese" → "Japanese mozc (or anthy)" を選択し "Add" をクリックします。

  3. You may chose as many input sources.

  4. ユーザーアカウントに再ログインします。

  5. Setup each input source by right clicking the GUI toolbar icon.

  6. インプットソース間を、SUPER-SPACE を用いて切り替えます。(SUPER は通常 Windows キーです。)

[ヒント] ヒント

If you wish to have access to alphabet only keyboard environment with the physical Japanese keyboard on which shift-2 has " (double quotation mark) engraved, you select "Japanese" in the above procedure. You can enter Japanese using "Japanese mozc (or anthy)" with physical "US" keyboard on which shift-2 has @ (at mark) engraved.

  • The GUI menu entry for im-config(8) is "Input method".

  • あるいは、ユーザのシェルから "im-config" を実行します。

  • im-config(8) は実行されるのが root からかどうかによって違った挙動をします。

  • im-config(8) はユーザーからのアクション無しにシステム上で最も好ましいインプットメソッドを有効にします。

Linux コンソールは限定された文字しか表示できません。(非 GUI コンソール上で非ヨーロッパ言語を表示するには jfbterm(1) のような特別なターミナルプログラムを使う必要があります。)

GUI environment (7章GUI システム) can display any characters in the UTF-8 as long as required fonts are installed and enabled. (The encoding of the original font data is taken care and transparent to the user.)

東アジアのロケールでは、箱描画文字やギリシャ文字やキリル文字はあなたが望むよりも広い幅で表示されて、ターミナル出力が揃わなくなるかもしれません(Unicode標準附属書 #11 参照)。

この問題は回避可能です:

  • gnome-terminal: Preferences → Profiles → Profile name → Compatibility → Ambiguous-wide characters → Narrow

  • ncurses: 環境変数を export NCURSES_NO_UTF8_ACS=0 と設定します。