1- <!-- $Header: /cvsroot/pgsql/doc/src/sgml/charset.sgml,v 2.23 2002/03/22 19:20:05 petere Exp $ -->
1+ <!-- $Header: /cvsroot/pgsql/doc/src/sgml/charset.sgml,v 2.24 2002/04/03 05:39:27 petere Exp $ -->
22
33<chapter id="charset">
44 <title>Localization</>
6363 <sect2>
6464 <title>Overview</>
6565
66- <para>
67- Locale support is not built into <productname>PostgreSQL</> by
68- default; to enable it, supply the <option>--enable-locale</> option
69- to the <filename>configure</> script:
70- <informalexample>
66+ <para>
67+ Locale support is automatically initialized when a database
68+ cluster is created using <command>initdb</command>.
69+ <command>initdb</command> will initialize the database cluster
70+ with the locale setting of its execution environment; so if your
71+ system is already set to use the locale that you want in your
72+ database cluster then there is nothing else you need to do. If
73+ you want to use a different locale (or you are not sure which
74+ locale your system is set to), you can tell
75+ <command>initdb</command> exactly which locale you want with the
76+ option <option>--locale</option>. For example:
7177<screen>
72- <prompt>$ </><userinput>./configure --enable- locale</>
78+ <prompt>$ </><userinput>initdb --locale=sv_SE </>
7379</screen>
74- </informalexample>
75- Locale support only affects the server; all clients are compatible
76- with servers with or without locale support.
77- </para>
78-
79- <para>
80- To enable messages translated to the user's preferred language,
81- the <option>--enable-nls</option> option must be used. This
82- option is independent of the other locale support.
8380 </para>
8481
8582 <para>
86- The information about which particular cultural rules to use is
87- determined by standard environment variables. If you are getting
88- localized behavior from other programs you probably have them set
89- up already. The simplest way to set the localization information
90- is the <envar>LANG</> variable, for example:
91- <programlisting>
92- export LANG=sv_SE
93- </programlisting>
94- This sets the locale to Swedish (<literal>sv</>) as spoken in
83+ This example sets the locale to Swedish (<literal>sv</>) as spoken in
9584 Sweden (<literal>SE</>). Other possibilities might be
9685 <literal>en_US</> (U.S. English) and <literal>fr_CA</> (Canada,
9786 French). If more than one character set can be useful for a locale
@@ -103,9 +92,9 @@ export LANG=sv_SE
10392
10493 <para>
10594 Occasionally it is useful to mix rules from several locales, e.g.,
106- use U.S. collation rules but Spanish messages. Todo that a set of
107- environment variables exist thatoverride the default of
108- <envar>LANG</> for a particular category:
95+ use U.S. collation rules but Spanish messages. Tosupport that, a
96+ set of locale subcategories exist thatcontrol only a certain
97+ aspect of the localization rules.
10998
11099 <informaltable>
111100 <tgroup cols="2">
@@ -138,49 +127,79 @@ export LANG=sv_SE
138127 </tgroup>
139128 </informaltable>
140129
141- Additionally, all of these specific variables and the
142- <envar>LANG</> variable can be overridden with the
143- <envar>LC_ALL</> environment variable.
130+ The category names translate into names of
131+ <command>initdb</command> options to override the locale choice
132+ for a specific category. For instance, to set the locale to
133+ French Canadian, but use U.S. rules for formatting currency, use
134+ <literal>initdb --locale=fr_CA --lc-monetary=en_US</literal>.
144135 </para>
145136
146- <note>
147- <para>
148- Some message localization libraries also look at the environment
149- variable <envar>LANGUAGE</envar> which overrides all other locale
150- settings for the purpose of setting the language of messages. If
151- in doubt, please refer to the documentation of your operating
152- system, in particular the
153- <citerefentry><refentrytitle>gettext</><manvolnum>3</></> manual
154- page, for more information.
155- </para>
156- </note>
157-
158137 <para>
159138 If you want the system to behave as if it had no locale support,
160- use the special locale <literal>C</> or <literal>POSIX</>, or
161- simply unset all locale-related variables.
139+ use the special locale <literal>C</> or <literal>POSIX</>.
140+ </para>
141+
142+ <para>
143+ The nature of some locale categories is that their value has to be
144+ fixed for the lifetime of a database cluster. That is, once
145+ <command>initdb</command> has run, you cannot change them anymore.
146+ <literal>LC_COLLATE</literal> and <literal>LC_CTYPE</literal> are
147+ those categories. They affect the sort order of indexes, so they
148+ must be kept fixed, or indexes on text columns will become corrupt.
149+ <productname>PostgreSQL</productname> enforces this by recording
150+ the values of <envar>LC_COLLATE</> and <envar>LC_CTYPE</> that are
151+ seen by <command>initdb</>. The server automatically adopts
152+ those two values when it is started.
153+ </para>
154+
155+ <para>
156+ The other locale categories can be changed as desired whenever the
157+ server is started by setting the run-time configuration variables
158+ that have the same name as the locale categories (see <xref
159+ linkend="runtime-config"> for details). The defaults that are
160+ chosen by <command>initdb</command> are actually only written into
161+ the configuration file <filename>postgresql.conf</filename> to
162+ serve as defaults when the server is started. If you delete the
163+ assignments from <filename>postgresql.conf</filename> then the
164+ server will inherit the settings from the execution environment.
162165 </para>
163166
164167 <para>
165168 Note that the locale behavior of the server is determined by the
166169 environment variables seen by the server, not by the environment
167- of any client. Therefore, be careful toset these variables
170+ of any client. Therefore, be careful toconfigure the correct locale settings
168171 before starting the server. A consequence of this is that if
169172 client and server are set up to different locales, messages may
170173 appear in different languages depending on where they originated.
171174 </para>
172175
176+ <note>
177+ <para>
178+ When we speak of inheriting the locale from the execution
179+ environment, this means the following on most operating systems:
180+ For a given locale category, say the collation, the following
181+ environment variables are consulted in this order until one is
182+ found to be set: <envar>LC_ALL</envar>, <envar>LC_COLLATE</envar>
183+ (the variable corresponding to the respective category),
184+ <envar>LANG</envar>. If none of these environment variables are
185+ set then the locale defaults to <literal>C</literal>.
186+ </para>
187+
188+ <para>
189+ Some message localization libraries also look at the environment
190+ variable <envar>LANGUAGE</envar> which overrides all other locale
191+ settings for the purpose of setting the language of messages. If
192+ in doubt, please refer to the documentation of your operating
193+ system, in particular the
194+ <citerefentry><refentrytitle>gettext</><manvolnum>3</></> manual
195+ page, for more information.
196+ </para>
197+ </note>
198+
173199 <para>
174- The <envar>LC_COLLATE</> and <envar>LC_CTYPE</> variables affect the
175- sort order of indexes. Therefore, these values must be kept fixed
176- for any particular database cluster, or indexes on text columns will
177- become corrupt. <productname>PostgreSQL</productname> enforces this
178- by recording the values of <envar>LC_COLLATE</> and <envar>LC_CTYPE</>
179- that are seen by <application>initdb</>. The server automatically adopts
180- those two values when it is started; only the other <envar>LC_</>
181- categories can be set from the environment at server start-up.
182- In short, only one collation order can be used in a database cluster,
183- and it is chosen at <application>initdb</> time.
200+ To enable messages translated to the user's preferred language,
201+ the <option>--enable-nls</option> option must be used. This
202+ option is independent of the other locale support.
184203 </para>
185204 </sect2>
186205