13.3. Using Localization

In all its splendor, i18n is not FreeBSD-specific and is a convention. We encourage you to help FreeBSD in following this convention.

Localization settings are based on three main terms: Language Code, Country Code, and Encoding. Locale names are constructed from these parts as follows:

    LanguageCode_CountryCode.Encoding

13.3.1. Language and Country Codes

In order to localize a FreeBSD system to a specific language (or any other i18n-supporting UNIX's), the user needs to find out the codes for the specify country and language (country codes tell applications what variation of given language to use). In addition, web browsers, SMTP/POP servers, web servers, etc. make decisions based on them. The following are examples of language/country codes:

Language/Country Code Description
en_US English - United States
ru_RU Russian for Russia
zh_TW Traditional Chinese for Taiwan

13.3.2. Encodings

Some languages use non-ASCII encodings that are 8-bit, wide or multibyte characters, see multibyte(3) for more details. Older applications do not recognize them and mistake them for control characters. Newer applications usually do recognize 8-bit characters. Depending on the implementation, users may be required to compile an application with wide or multibyte characters support, or configure it correctly. To be able to input and process wide or multibyte characters, the FreeBSD Ports collection has provided each language with different programs. Refer to the i18n documentation in the respective FreeBSD Port.

Specifically, the user needs to look at the application documentation to decide on how to configure it correctly or to pass correct values into the configure/Makefile/compiler.

Some things to keep in mind are:

You can check the active list of character sets at the IANA Registry.

13.3.3. I18n applications

In the FreeBSD Ports and Package system, i18n applications have been named with i18n in their names for easy identification. However, they do not always support the language needed.

13.3.4. Setting Locale

Theoretically, one only needs to export the value of his/her locale name as LANG in the login shell and is usually done through the user's ~/.login_conf or the user login shell configuration (~/.profile, ~/.bashrc, ~/.cshrc). This should set all of the locale subsets (such as LC_CTYPE, LC_CTIME, etc.). Please refer to language-specific FreeBSD documentation for more information.

You should set the following two values in your configuration files:

This includes the user shell config, the specific application config, and the X11 config.

13.3.4.1. Setting Locale Methods

There are two methods for setting locale, and both are described below. The first (recommended one) is by assigning the environment variables in login class, and the second is by adding the environment variable assignments to the system's shell startup file.

13.3.4.1.1. Login Classes Method

This method allows environment variables needed for locale name and MIME character sets to be assigned once for every possible shell instead of adding specific shell assignments to each shell's startup file. User Level Setup can be done by an user himself and Administrator Level Setup require superuser privileges.

13.3.4.1.1.1. User Level Setup

Here is a minimal example of a .login_conf file in user's home directory which has both variables set for Latin-1 encoding:

    me:My Account:\
        :charset=ISO-8859-1:\
        :lang=de_DE.ISO_8859-1:

See Administrator Level Setup and login.conf(5) for more details.

13.3.4.1.1.2. Administrator Level Setup

Check that /etc/login.conf have the correct language user's class. Make sure these settings appear in /etc/login.conf:

    language_name:accounts_title:\
        :charset=MIME_charset:\
        :lang=locale_name:\
        :tc=default:

So sticking with our previous example using Latin-1, it would look like this:

    german:German Users Accounts:\
        :charset=ISO-8859-1:\
        :lang=de_DE.ISO_8859-1:\
        :tc=default:

Changing Login Classes with vipw(8)

Use vipw to add new users, and make the entry look like this:

    user:password:1111:11:language:0:0:User Name:/home/user:/bin/sh

Changing Login Classes with adduser(8)

Use adduser to add new users, and do the following:

  • Set defaultclass = language in /etc/adduser.conf. Keep in mind you must enter a default class for all users of other languages in this case.

  • An alternative variant is answering the specified language each time that

        Enter login class: default []:
    
    appears from adduser(8)

  • Another alternative is to use the following for each user of a different language that you wish to add:

        # adduser -class language
    

Changing Login Classes with pw(8)

If you use pw(8) for adding new users, call it in this form:

    # pw useradd user_name -L language

13.3.4.1.2. Shell Startup File Method

Note: This method is not recommended because it requires a different setup for each possible login program chosen. Use the Login Class Method instead.

To add the locale name and MIME character set, just set the two environment variables shown below in the /etc/profile and/or /etc/csh.login shell startup files. We will use the German language as an example below:

In /etc/profile:

    LANG=de_DE.ISO_8859-1; export LANG
    MM_CHARSET=ISO-8859-1; export MM_CHARSET

Or in /etc/csh.login:

    setenv LANG de_DE.ISO_8859-1
    setenv MM_CHARSET ISO-8859-1

Alternatively, you can add the above instructions to /usr/share/skel/dot.profile (similar to what was used in /etc/profile above), or /usr/share/skel/dot.login (similar to what was used in /etc/csh.login above).

For X11:

In $HOME/.xinitrc:

    LANG=de_DE.ISO_8859-1; export LANG

Or:

    setenv LANG de_DE.ISO_8859-1

Depending on your shell (see above).

13.3.5. Console Setup

For all single C chars character sets, set the correct console fonts in /etc/rc.conf for the language in question with:

    font8x16=font_name
    font8x14=font_name
    font8x8=font_name

The font_name here is taken from the /usr/share/syscons/fonts directory, without the .fnt suffix.

Also be sure to set the correct keymap and screenmap for your single C chars character set through /stand/sysinstall. Once inside sysinstall, choose Configure, then Console. Alternatively, you can add the following to /etc/rc.conf:

    scrnmap=screenmap_name
    keymap=keymap_name
    keychange="fkey_number sequence"

The screenmap_name here is taken from the /usr/share/syscons/scrnmaps directory, without the .scm suffix. A screenmap with a corresponding mapped font is usually needed as a workaround for expanding bit 8 to bit 9 on a VGA adapter's font character matrix in pseudographics area, i.e., to move letters out of that area if screen font uses a bit 8 column.

If you have the following settings, insert the kernel config specified in the paragraph after the list.

A workaround for expanding 8-bit to 9-bit on a VGA adapter is usually needed for the above settings. This workaround disables 8-bit to 9-bit expansion of the font character with the mouse cursor the sc0 console driver. To enable the workaround, insert the following line into the kernel config.

    options         SC_MOUSE_CHAR=0x03

The keymap_name here is taken from the /usr/share/syscons/keymaps directory, without the .kbd suffix.

The keychange is usually needed to program function keys to match the selected terminal type because function key sequences can not be defined in the key map.

Also be sure to set the correct console terminal type in /etc/ttys for all ttyv* entries. Current pre-defined correspondences are:

Character Set Terminal Type
ISO-8859-1 or ISO-8859-15 cons25l1
ISO-8859-2 cons25l2
KOI8-R cons25r
CP437 (hardware default) cons25

For wide or multibyte characters languages, use the correct FreeBSD port in your /usr/ports/language directory. Some ports appear as console while the system sees it as serial vtty's, hence you must reserve enough vtty's for both X11 and the pseudo-serial console. Here is a partial list of applications for using other languages in console:

Language Location
Traditional Chinese (BIG-5) /usr/ports/chinese/big5con
Japanese /usr/ports/japanese/ja-kon2-* or /usr/ports/japanese/Mule_Wnn
Korean /usr/ports/korean/ko-han

13.3.6. X11 Setup

Although X11 is not part of the FreeBSD Project, we have included some information here for FreeBSD users. For more details, refer to the XFree86 web site or whichever X11 Server you use.

In ~/.Xresources, you can additionally tune application specific i18n settings (e.g., fonts, menus, etc.).

13.3.6.1. Displaying Fonts

Install the X11 True Type-Common server (XTT-common) and install the language truetype fonts. Setting the correct locale should allow you to view your selected language in menus and such.

13.3.6.2. Inputting Non-English Characters

The X11 Input Method (XIM) Protocol is a new standard for all X11 clients. All X11 applications should be written as XIM clients that take input from XIM Input servers. There are several XIM servers available for different languages.

13.3.7. Printer Setup

Some single C chars character sets are usually hardware coded into printers. Wide or multibyte character sets require special setup and we recommend using apsfilter. You may also convert the document to Postscript or PDF formats using language specific converters.

13.3.8. Kernel and File Systems

The FreeBSD FFS filesystem is 8-bit clean, so it can be used with any single C chars character set (see multibyte(3)), but there is no character set name stored in the filesystem; i.e., it is raw 8-bit and does not know anything about encoding order. Officially, FFS does not support any form of wide or multibyte character sets yet. However, some wide or multibyte character sets have independent patches for FFS enabling such support. They are only temporary unportable solutions or hacks and we have decided to not include them in the source tree. Refer to respective languages' web sites for more informations and the patch files.

The FreeBSD MS-DOS filesystem has the configurable ability to convert between MS-DOS, Unicode character sets and chosen FreeBSD filesystem character sets. See mount_msdos(8) for details.

For questions about FreeBSD, e-mail <questions@FreeBSD.org>.
For questions about this documentation, e-mail <doc@FreeBSD.org>.