📄 using-localization.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta name="generator" content="HTML Tidy, see www.w3.org" /><title>Using Localization</title><meta name="GENERATOR" content="Modular DocBook HTML Stylesheet Version 1.7" /><link rel="HOME" title="FreeBSD Handbook" href="index.html" /><link rel="UP" title="Localization - I18N/L10N Usage and Setup" href="l10n.html" /><link rel="PREVIOUS" title="The Basics" href="l10n-basics.html" /><link rel="NEXT" title="Compiling I18N Programs" href="l10n-compiling.html" /><link rel="STYLESHEET" type="text/css" href="docbook.css" /></head><body class="SECT1" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#840084"alink="#0000FF"><div class="NAVHEADER"><table summary="Header navigation table" width="100%" border="0" cellpadding="0"cellspacing="0"><tr><th colspan="3" align="center">FreeBSD Handbook</th></tr><tr><td width="10%" align="left" valign="bottom"><a href="l10n-basics.html"accesskey="P">Prev</a></td><td width="80%" align="center" valign="bottom">Chapter 18 Localization - I18N/L10N Usageand Setup</td><td width="10%" align="right" valign="bottom"><a href="l10n-compiling.html"accesskey="N">Next</a></td></tr></table><hr align="LEFT" width="100%" /></div><div class="SECT1"><h1 class="SECT1"><a id="USING-LOCALIZATION" name="USING-LOCALIZATION">18.3 UsingLocalization</a></h1><p>In all its splendor, I18N is not FreeBSD-specific and is a convention. We encourageyou to help FreeBSD in following this convention.</p><p>Localization settings are based on three main terms: Language Code, Country Code, andEncoding. Locale names are constructed from these parts as follows:</p><pre class="PROGRAMLISTING"><var class="REPLACEABLE">LanguageCode</var>_<varclass="REPLACEABLE">CountryCode</var>.<var class="REPLACEABLE">Encoding</var></pre><div class="SECT2"><h2 class="SECT2"><a id="AEN26593" name="AEN26593">18.3.1 Language and CountryCodes</a></h2><p>In order to localize a FreeBSD system to a specific language (or any otherI18N-supporting <span class="TRADEMARK">UNIX</span>® like systems), the user needs tofind out the codes for the specify country and language (country codes tell applicationswhat 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 oflanguage/country codes:</p><div class="INFORMALTABLE"><a id="AEN26601" name="AEN26601"></a><table border="0" frame="void" class="CALSTABLE"><col /><col /><thead><tr><th>Language/Country Code</th><th>Description</th></tr></thead><tbody><tr><td>en_US</td><td>English - United States</td></tr><tr><td>ru_RU</td><td>Russian for Russia</td></tr><tr><td>zh_TW</td><td>Traditional Chinese for Taiwan</td></tr></tbody></table></div></div><div class="SECT2"><h2 class="SECT2"><a id="AEN26617" name="AEN26617">18.3.2 Encodings</a></h2><p>Some languages use non-ASCII encodings that are 8-bit, wide or multibyte characters,see <a href="http://www.FreeBSD.org/cgi/man.cgi?query=multibyte&sektion=3"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">multibyte</span>(3)</span></a> for moredetails. Older applications do not recognize them and mistake them for controlcharacters. Newer applications usually do recognize 8-bit characters. Depending on theimplementation, users may be required to compile an application with wide or multibytecharacters support, or configure it correctly. To be able to input and process wide ormultibyte characters, the <a href="../../../../ports/index.html" target="_top">FreeBSDPorts collection</a> has provided each language with different programs. Refer to theI18N documentation in the respective FreeBSD Port.</p><p>Specifically, the user needs to look at the application documentation to decide on howto configure it correctly or to pass correct values into theconfigure/Makefile/compiler.</p><p>Some things to keep in mind are:</p><ul><li><p>Language specific single C chars character sets (see <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=multibyte&sektion=3"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">multibyte</span>(3)</span></a>), e.g.ISO-8859-1, ISO-8859-15, KOI8-R, CP437.</p></li><li><p>Wide or multibyte encodings, e.g. EUC, Big5.</p></li></ul><p>You can check the active list of character sets at the <ahref="http://www.iana.org/assignments/character-sets" target="_top">IANARegistry</a>.</p><div class="NOTE"><blockquote class="NOTE"><p><b>Note:</b> FreeBSD versions 4.5 and up use X11-compatible locale encodingsinstead.</p></blockquote></div></div><div class="SECT2"><h2 class="SECT2"><a id="AEN26642" name="AEN26642">18.3.3 I18N Applications</a></h2><p>In the FreeBSD Ports and Package system, I18N applications have been named with <varclass="LITERAL">I18N</var> in their names for easy identification. However, they do notalways support the language needed.</p></div><div class="SECT2"><h2 class="SECT2"><a id="SETTING-LOCALE" name="SETTING-LOCALE">18.3.4 SettingLocale</a></h2><p>Usually it is sufficient to export the value of the locale name as <ttclass="ENVAR">LANG</tt> in the login shell. This could be done in the user's <ttclass="FILENAME">~/.login_conf</tt> file or in the startup file of the user's shell (<ttclass="FILENAME">~/.profile</tt>, <tt class="FILENAME">~/.bashrc</tt>, <ttclass="FILENAME">~/.cshrc</tt>). There is no need to set the locale subsets such as <ttclass="ENVAR">LC_CTYPE</tt>, <tt class="ENVAR">LC_CTIME</tt>. Please refer tolanguage-specific FreeBSD documentation for more information.</p><p>You should set the following two environment variables in your configurationfiles:</p><ul><li><p><tt class="ENVAR">LANG</tt> for <span class="TRADEMARK">POSIX</span>® <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=setlocale&sektion=3"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">setlocale</span>(3)</span></a> familyfunctions</p></li><li><p><tt class="ENVAR">MM_CHARSET</tt> for applications' MIME character set</p></li></ul><p>This includes the user shell configuration, the specific application configuration,and the X11 configuration.</p><div class="SECT3"><h3 class="SECT3"><a id="AEN26673" name="AEN26673">18.3.4.1 Setting LocaleMethods</a></h3><p>There are two methods for setting locale, and both are described below. The first(recommended one) is by assigning the environment variables in <ahref="using-localization.html#LOGIN-CLASS">login class</a>, and the second is by addingthe environment variable assignments to the system's shell <ahref="using-localization.html#STARTUP-FILE">startup file</a>.</p><div class="SECT4"><h4 class="SECT4"><a id="LOGIN-CLASS" name="LOGIN-CLASS">18.3.4.1.1 Login ClassesMethod</a></h4><p>This method allows environment variables needed for locale name and MIME charactersets to be assigned once for every possible shell instead of adding specific shellassignments to each shell's startup file. <ahref="using-localization.html#USR-SETUP">User Level Setup</a> can be done by an userhimself and <a href="using-localization.html#ADM-SETUP">Administrator Level Setup</a>require superuser privileges.</p><div class="SECT5"><h5 class="SECT5"><a id="USR-SETUP" name="USR-SETUP">18.3.4.1.1.1 User LevelSetup</a></h5><p>Here is a minimal example of a <tt class="FILENAME">.login_conf</tt> file in user'shome directory which has both variables set for Latin-1 encoding:</p><pre class="PROGRAMLISTING">me:\ :charset=ISO-8859-1:\ :lang=de_DE.ISO8859-1:</pre><p>Here is an example of a <tt class="FILENAME">.login_conf</tt> that sets the variablesfor Traditional Chinese in BIG-5 encoding. Notice the many more variables set becausesome software does not respect locale variables correctly for Chinese, Japanese, andKorean.</p><pre class="PROGRAMLISTING">#Users who do not wish to use monetary units or time formats#of Taiwan can manually change each variableme:\ :lang=zh_TW.Big5:\ :lc_all=zh_TW.Big:\ :lc_collate=zh_TW.Big5:\ :lc_ctype=zh_TW.Big5:\ :lc_messages=zh_TW.Big5:\ :lc_monetary=zh_TW.Big5:\ :lc_numeric=zh_TW.Big5:\ :lc_time=zh_TW.Big5:\ :charset=big5:\ :xmodifiers="@im=xcin": #Setting the XIM Input Server</pre><p>See <a href="using-localization.html#ADM-SETUP">Administrator Level Setup</a> and <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=login.conf&sektion=5"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">login.conf</span>(5)</span></a> for moredetails.</p></div><div class="SECT5"><h5 class="SECT5"><a id="ADM-SETUP" name="ADM-SETUP">18.3.4.1.1.2 Administrator LevelSetup</a></h5><p>Verify that the user's login class in <tt class="FILENAME">/etc/login.conf</tt> setsthe correct language. Make sure these settings appear in <ttclass="FILENAME">/etc/login.conf</tt>:</p><pre class="PROGRAMLISTING"><var class="REPLACEABLE">language_name</var>:<varclass="REPLACEABLE">accounts_title</var>:\ :charset=<var class="REPLACEABLE">MIME_charset</var>:\ :lang=<var class="REPLACEABLE">locale_name</var>:\ :tc=default:</pre><p>So sticking with our previous example using Latin-1, it would look like this:</p><pre class="PROGRAMLISTING">german:German Users Accounts:\ :charset=ISO-8859-1:\ :lang=de_DE.ISO8859-1:\ :tc=default:</pre><h4 class="BRIDGEHEAD"><a id="AEN26715" name="AEN26715"></a>Changing Login Classes with<a href="http://www.FreeBSD.org/cgi/man.cgi?query=vipw&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">vipw</span>(8)</span></a></h4><p>Use <tt class="COMMAND">vipw</tt> to add new users, and make the entry look likethis:</p><pre class="PROGRAMLISTING">user:password:1111:11:<varclass="REPLACEABLE">language</var>:0:0:User Name:/home/user:/bin/sh</pre><h4 class="BRIDGEHEAD"><a id="AEN26726" name="AEN26726"></a>Changing Login Classes with<a href="http://www.FreeBSD.org/cgi/man.cgi?query=adduser&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">adduser</span>(8)</span></a></h4><p>Use <tt class="COMMAND">adduser</tt> to add new users, and do the following:</p><ul><li><p>Set <var class="LITERAL">defaultclass = <var class="REPLACEABLE">language</var></var>in <tt class="FILENAME">/etc/adduser.conf</tt>. Keep in mind you must enter a <varclass="LITERAL">default</var> class for all users of other languages in this case.</p></li><li><p>An alternative variant is answering the specified language each time that</p><pre class="SCREEN"><samp class="PROMPT">Enter login class: default []:</samp></pre>appears from <a href="http://www.FreeBSD.org/cgi/man.cgi?query=adduser&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">adduser</span>(8)</span></a>.<br /><br /></li><li><p>Another alternative is to use the following for each user of a different language thatyou wish to add:</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbd class="USERINPUT">adduser -class <varclass="REPLACEABLE">language</var></kbd></pre></li></ul><h4 class="BRIDGEHEAD"><a id="AEN26757" name="AEN26757"></a>Changing Login Classes with<a href="http://www.FreeBSD.org/cgi/man.cgi?query=pw&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">pw</span>(8)</span></a></h4><p>If you use <a href="http://www.FreeBSD.org/cgi/man.cgi?query=pw&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">pw</span>(8)</span></a> for adding newusers, call it in this form:</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbd class="USERINPUT">pw useradd <varclass="REPLACEABLE">user_name</var> -L <var class="REPLACEABLE">language</var></kbd></pre></div></div>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -