Capítulo 8. I18N e L10N

Índice

8.1. A entrada do teclado
8.1.1. O suporte a método de entrada com IBus
8.1.2. Um exemplo para Japonês
8.1.3. Desactivar o método de entrada
8.2. O mostrador de resultados
8.3. O locale
8.3.1. Bases de codificação
8.3.2. Rationale for UTF-8 locale
8.3.3. A reconfiguração do locale
8.3.4. O valor da variável de ambiente "$LANG"
8.3.5. O locale específico apenas sob X Window
8.3.6. Codificação de nomes de ficheiros
8.3.7. Mensagens localizadas e documentação traduzida
8.3.8. Efeitos do locale

Multilingualization (M17N) or Native Language Support for an application software is done in 2 steps.

[Dica] Dica

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.

The modern software such as GNOME and KDE are multilingualized. They are internationalized by making them handle UTF-8 data and localized by providing their translated messages through the gettext(1) infrastructure. Translated messages may be provided as separate localization packages. They can be selected simply by setting pertinent environment variables to the appropriate locale.

The simplest representation of the text data is ASCII which is sufficient for English and uses less than 127 characters (representable with 7 bits). In order to support much more characters for the international support, many character encoding systems have been invented. The modern and sensible encoding system is UTF-8 which can handle practically all the characters known to the human (see Secção 8.3.1, “Bases de codificação”).

Veja Introdução ao i18n para mais detalhes.

O suporte a hardware internacional é activado com dados de configuração de hardware localizados.

8.1. A entrada do teclado

O sistema Debian pode ser configurado para funcionar com muitas disposições internacionais de teclado.

Tabela 8.1. Lista de métodos de configuração do teclado

ambiente comando
Consola do Linux dpkg-reconfigure --priority=low console-data
X Window dpkg-reconfigure --priority=low xserver-xorg

This supports keyboard input for accented characters of many European languages with its dead-key function. For Asian languages, you need more complicated input method support such as IBus discussed next.

8.1.1. O suporte a método de entrada com IBus

Setup of multilingual input for the Debian system is simplified by using the IBus family of packages with the im-config package. The list of IBus packages are the following.

Tabela 8.2. Lista de suportes a método de entrada com IBus

pacote popcon tamanho locale suportado
ibus * V:0.2, I:0.2 4220 estrutura de método de entrada que usa dbus
ibus-anthy * V:0.04, I:0.10 684 Japonês
ibus-skk * V:0.00, I:0.03 404 , ,
ibus-pinyin * V:0.06, I:0.09 1184 Chinês (para zh_CN)
ibus-chewing * V:0.01, I:0.02 252 , , (para zh_TW)
ibus-hangul * V:0.01, I:0.03 216 Coreano
ibus-table * V:0.05, I:0.10 680 motor de tabela para IBus
ibus-table-thai * I:0.00 156 160 Thai
ibus-unikey * V:0.00, I:0.00 316 Vietnamita
ibus-m17n * V:0.02, I:0.05 180 Multilingue: Indiano, Árabe e outros

The kinput2 method and other locale dependent Asian classic input methods still exist but are not recommended for the modern UTF-8 X environment. The SCIM and uim tool chains are an slightly older approach for the international input method for the modern UTF-8 X environment.

8.1.2. Um exemplo para Japonês

I find the Japanese input method started under English environment ("en_US.UTF-8") very useful. Here is how I did this with IBus.

  1. Install the Japanese input tool package ibus-anthy with its recommended packages such as im-config.
  2. Execute "im-config" a partir da shell de utilizador e seleccione "ibus".
  3. Select "System" → "Preferences" → "IBus Preferences" → "Input Method" → "Select an input method" → "Japanese" → "Anthy" and click "Add".
  4. Relogin to user's account.
  5. Verificar definição por "im-config".
  6. Setup input method and mode by right clicking GUI toolbar. (You can reduce menu choice of input method.)
  7. Arrancar o método de entrada IBus por CTRL-ESPAÇO.

Por favor note o seguinte.

  • im-config(8) behaves differently if command is executed from root or not.
  • im-config(8) activa o melhor método de entrada do sistema e é predefinido sem qualquer acção do utilizador.
  • The GUI menu entry for im-config(8) is disable as default to prevent cluttering.

8.1.3. Desactivar o método de entrada

If you wish to input without going through XIM, set "$XMODIFIERS" value to "none" while starting a program. This may be the case if you use Japanese input infrastructure egg on emacs(1). From shell, execute as the following.

$ XMODIFIERS=none emacs

In order to adjust the command executed by the Debian menu, place customized configuration in "/etc/menu/" following method described in "/usr/share/doc/menu/html".

8.2. O mostrador de resultados

A consola do Linux apenas pode mostrar caracteres limitados. (Você precisa usar programas de terminal especiais como o jfbterm(1) para mostrar linguagens não-Europeias numa consola não-X.)

X Window can display any characters in the UTF-8 as long as required font data exists. (The encoding of the original font data is taken care by the X Window System and transparent to the user.)

8.3. O locale

O seguinte foca-se no locale para aplicações que correm sob ambiente X Window iniciado a partir do gdm(1).

8.3.1. Bases de codificação

A variável de ambiente "LANG=xx_YY.ZZZZ" define o locale para o código de linguagem "xx", código de país "yy", e codificação "ZZZZ" (veja Secção 1.5.2, “variável "$LANG"”).

Current Debian system normally sets the locale as "LANG=xx_YY.UTF-8". This uses the UTF-8 encoding with the Unicode character set. This UTF-8 encoding system is a multibyte code system and uses code points smartly. The ASCII data, which consist only with 7-bit range codes, are always valid UTF-8 data consisting only with 1 byte per character.

Previous Debian system used to set the locale as "LANG=C" or "LANG=xx_YY" (without ".UTF-8").

  • The ASCII character set is used for "LANG=C" or "LANG=POSIX".
  • The traditional encoding system in Unix is used for "LANG=xx_YY".

Actual traditional encoding system used for "LANG=xx_YY" can be identified by checking "/usr/share/i18n/SUPPORTED". For example, "en_US" uses "ISO-8859-1" encoding and "fr_FR@euro" uses "ISO-8859-15" encoding.

8.3.2. Rationale for UTF-8 locale

The UTF-8 encoding is the modern and sensible text encoding system for I18N and enables to represent Unicode characters, i.e., practically all characters known to human. UTF stands for Unicode Transformation Format (UTF) schemes.

I recommend to use UTF-8 locale for your desktop, e.g., "LANG=en_US.UTF-8". The first part of the locale determines messages presented by applications. For example, gedit(1) (text editor for the GNOME Desktop) under "LANG=fr_FR.UTF-8" locale can display and edit Chinese character text data while presenting menus in French, as long as required fonts and input methods are installed.

I also recommend to set the locale only using the "$LANG" environment variable. I do not see much benefit of setting a complicated combination of "LC_*" variables (see locale(1)) under UTF-8 locale.

Even plain English text may contain non-ASCII characters, e.g. left and right quotation marks are not available in ASCII.

“double quoted text”
‘single quoted text’

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.

Some programs consume more memory after supporting I18N. This is because they are coded to use UTF-32(UCS4) internally to support Unicode for speed optimization and consume 4 bytes per each ASCII character data independent of locale selected. Again, you loose nothing by deploying UTF-8 locale.

The vendor specific old non-UTF-8 encoding systems tend to have minor but annoying differences on some characters such as graphic ones for many countries. The deployment of the UTF-8 system by the modern OSs practically solved these conflicting encoding issues.

8.3.3. A reconfiguração do locale

In order for the system to access a particular locale, the locale data must be compiled from the locale database. (The Debian system does not come with all available locales pre-compiled unless you installed the locales-all package.) The full list of supported locales available for compiling are listed in "/usr/share/i18n/SUPPORTED". This lists all the proper locale names. The following lists all the available UTF-8 locales already compiled to the binary form.

$ locale -a | grep utf8

A execução do comando seguinte reconfigura o pacote locales.

# dpkg-reconfigure locales

Este processo involve 3 passos.

  1. Actualizar a lista de locales disponíveis
  2. Compilá-los num formato binário
  3. Definir o locale predefinido de todo o sistema em "/etc/defaults/locale" para usar com o PAM (veja Secção 4.5, “PAM e NSS”)

A lista dos locale disponíveis deve incluir "en_US.UTF-8" e todas as linguagens de interesse com "UTF-8".

O locale predefinido recomendado é "en_US.UTF-8" para Inglês dos Estados Unidos. Para outras linguagens, por favor certifique-se de escolher um locale com "UTF-8". Qualquer uma destas definições consegue lidar com quaisquer caracteres internacionais.

[Nota] Nota

Apesar da definição de locale para "C" usar mensagens em Inglês dos Estados Unidos, apenas lida com caracteres ASCII.

8.3.4. O valor da variável de ambiente "$LANG"

O valor da variável de ambiente "$LANG" é definido e alterado por muitas aplicações.

  • Definido inicialmente pelo mecanismo de login(1) PAM para os programas de consola local do Linux
  • Definido inicialmente pelo mecanismo PAM do gestor de ecrã para todos os programas do X
  • Definido inicialmente pelo mecanismo PAM do ssh(1) para os programas de consola remota.
  • Alterado por algum gestor de ecrã como o gdm(1) para todos os programas do X
  • Alterado pelo código de arranque da sessão X via "~/.xsessionrc" para todos os programas do X (funcionalidade do lenny)
  • Alterado pelo código de arranque da shell, ex. "~/.bashrc", para todos os programas de consola
[Dica] Dica

É uma boa ideia instalar um locale predefinido para todo o sistema como "en_US.UTF-8" para o máximo de compatibilidade.

8.3.5. O locale específico apenas sob X Window

Você pode escolher um locale específico apenas sob X Window não relacionado com o seu locale predefinido de todo o sistema usando personalização do PAM (veja xref linkend="_pam_and_nss"/>) como se segue.

Este ambiente deverá disponibilizar-lhe a melhor experiência de ambiente de trabalho com estabilidade. Você tem acesso ao terminal de caracteres funcional com mensagens legíveis mesmo quando o Sistema X Window não está a funcionar. Isto torna-se essencial para linguagens que usam caracteres não-romanos como o Chinês, Japonês e Coreano.

[Nota] Nota

There may be another way available as the improvement of X session manager package but please read following as the generic and basic method of setting the locale. For gdm(1), I know you can select the locale of X session via its memu.

A seguinte linha define a localização do ficheiro do ambiente de linguagem no ficheiro do configuração do PAM, como o "/etc/pam.d/gdm.

auth    required        pam_env.so read_env=1 envfile=/etc/default/locale

Mude isto para o seguinte.

auth    required        pam_env.so read_env=1 envfile=/etc/default/locale-x

Para Japonês, crie um ficheiro "/etc/defaults/locale-gdm" com permissões "-rw-r--r-- 1 root root" contendo o seguinte.

LANG="ja_JP.UTF-8"

Mantenha o ficheiro "/etc/defaults/locale" predefinido para outros programas com o seguinte.

LANG="en_US.UTF-8"

Esta é a técnica mais genérica para personalizar o locale e faz com que o diálogo de selecção de menu do próprio gdm(1) fique localizado (traduzido).

Alternativamente para este caso, você pode simplesmente alterar o locale usando o ficheiro "~/.xsessionrc".

8.3.6. Codificação de nomes de ficheiros

For cross platform data exchanges (see Secção 10.1.10, “Dispositivo de armazenamento amovível”), you may need to mount some filesystem with particular encodings. For example, mount(8) for vfat filesystem assumes CP437 if used without option. You need to provide explicit mount option to use UTF-8 or CP932 for filenames.

[Nota] Nota

When auto-mounting a hot-pluggable USB memory stick under modern desktop environment such as GNOME, you may provide such mount option by right clicking the icon on the desktop, click "Drive" tab, click to expand "Setting", and entering "utf8" to "Mount options:". The next time this memory stick is mounted, mount with UTF-8 is enabled.

[Nota] Nota

If you are upgrading system or moving disk drives from older non-UTF-8 system, file names with non-ASCII characters may be encoded in the historic and deprecated encodings such as ISO-8859-1 or eucJP. Please seek help of text conversion tools to convert them to UTF-8. See Secção 11.1, “Ferramentas de conversão de dados em texto”.

Samba uses Unicode for newer clients (Windows NT, 200x, XP) but uses CP850 for older clients (DOS and Windows 9x/Me) as default. This default for older clients can be changed using "dos charset" in the "/etc/samba/smb.conf" file, e.g., to CP932 for Japanese.

8.3.7. Mensagens localizadas e documentação traduzida

Translations exist for many of the text messages and documents that are displayed in the Debian system, such as error messages, standard program output, menus, and manual pages. GNU gettext(1) command tool chain is used as the backend tool for most translation activities.

aptitude(8) lists under "Tasks" → "Localization" provide extensive list of useful binary packages which add localized messages to applications and provide translated documentation.

For example, you can obtain the localized message for manpage by installing the manpages-<LANG> package. To read the Italian-language manpage for <programname> from "/usr/share/man/it/", execute as the following.

LANG=it_IT.UTF-8 man <nome_do_programa>

8.3.8. Efeitos do locale

The sort order of characters with sort(1) is affected by the language choice of the locale. Spanish and English locale sort differently.

The date format of ls(1) is affected by the locale. The date format of "LANG=C ls -l" and "LANG=en_US.UTF-8" are different (see Secção 9.2.5, “Amostragem personalizada de hora e data”).

Number punctuation are different for locales. For example, in English locale, one thousand one 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.