This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Configure regen to pick up the new installation directories
[perl5.git] / pod / perllocale.pod
index f4ca0dd..510117f 100644 (file)
@@ -169,15 +169,23 @@ combination of language, country or territory, and codeset.  Read on for
 hints on the naming of locales: not all systems name locales as in the
 example.
 
-If no second argument is provided, the function returns a string naming
-the current locale for the category.  You can use this value as the
-second argument in a subsequent call to setlocale().  If a second
-argument is given and it corresponds to a valid locale, the locale for
-the category is set to that value, and the function returns the
-now-current locale value.  You can then use this in yet another call to
-setlocale().  (In some implementations, the return value may sometimes
-differ from the value you gave as the second argument--think of it as
-an alias for the value you gave.)
+If no second argument is provided and the category is something else
+than LC_ALL, the function returns a string naming the current locale
+for the category.  You can use this value as the second argument in a
+subsequent call to setlocale().
+
+If no second argument is provided and the category is LC_ALL, the
+result is implementation-dependent.  It may be a string of
+concatenated locales names (separator also implementation-dependent)
+or a single locale name.  Please consult your L<setlocale(3)> for
+details.
+
+If a second argument is given and it corresponds to a valid locale,
+the locale for the category is set to that value, and the function
+returns the now-current locale value.  You can then use this in yet
+another call to setlocale().  (In some implementations, the return
+value may sometimes differ from the value you gave as the second
+argument--think of it as an alias for the value you gave.)
 
 As the example shows, if the second argument is an empty string, the
 category's locale is returned to the default specified by the
@@ -207,26 +215,30 @@ I<SEE ALSO> section).  If that fails, try the following command lines:
 
         ls /usr/lib/nls
 
+       ls /usr/share/locale
+
 and see whether they list something resembling these
 
         en_US.ISO8859-1     de_DE.ISO8859-1     ru_RU.ISO8859-5
+        en_US.iso88591      de_DE.iso88591      ru_RU.iso88595
         en_US               de_DE               ru_RU
         en                  de                  ru
         english             german              russian
         english.iso88591    german.iso88591     russian.iso88595
+        english.roman8                          russian.koi8r
 
-Sadly, even though the calling interface for setlocale() has
-been standardized, names of locales and the directories where the
+Sadly, even though the calling interface for setlocale() has been
+standardized, names of locales and the directories where the
 configuration resides have not been.  The basic form of the name is
-I<language_country/territory>B<.>I<codeset>, but the latter parts after
-I<language> are not always present.  The I<language> and I<country> are
-usually from the standards B<ISO 3166> and B<ISO 639>, the two-letter
-abbreviations for the countries and the languages of the world,
-respectively.  The I<codeset> part often mentions some B<ISO 8859>
-character set, the Latin codesets.  For example, C<ISO 8859-1> is the
-so-called "Western codeset" that can be used to encode most Western
-European languages.  Again, there are several ways to write even the
-name of that one standard.  Lamentably.
+I<language_territory>B<.>I<codeset>, but the latter parts after
+I<language> are not always present.  The I<language> and I<country>
+are usually from the standards B<ISO 3166> and B<ISO 639>, the
+two-letter abbreviations for the countries and the languages of the
+world, respectively.  The I<codeset> part often mentions some B<ISO
+8859> character set, the Latin codesets.  For example, C<ISO 8859-1>
+is the so-called "Western European codeset" that can be used to encode
+most Western European languages adequately.  Again, there are several
+ways to write even the name of that one standard.  Lamentably.
 
 Two special locales are worth particular mention: "C" and "POSIX".
 Currently these are effectively the same locale: the difference is
@@ -266,10 +278,10 @@ The two quickest fixes are either to render Perl silent about any
 locale inconsistencies or to run Perl under the default locale "C".
 
 Perl's moaning about locale problems can be silenced by setting the
-environment variable PERL_BADLANG to a non-zero value, for example
-"1".  This method really just sweeps the problem under the carpet: you
-tell Perl to shut up even when Perl sees that something is wrong.  Do
-not be surprised if later something locale-dependent misbehaves.
+environment variable PERL_BADLANG to a zero value, for example "0".
+This method really just sweeps the problem under the carpet: you tell
+Perl to shut up even when Perl sees that something is wrong.  Do not
+be surprised if later something locale-dependent misbehaves.
 
 Perl can be run under the "C" locale by setting the environment
 variable LC_ALL to "C".  This method is perhaps a bit more civilized
@@ -320,7 +332,7 @@ Second, if using the listed commands you see something B<exactly>
 (prefix matches do not count and case usually counts) like "En_US"
 without the quotes, then you should be okay because you are using a
 locale name that should be installed and available in your system.
-In this case, see L<Fixing system locale configuration>.
+In this case, see L<Permanently fixing system locale configuration>.
 
 =head2 Permanently fixing your locale configuration
 
@@ -339,7 +351,7 @@ rules for matching locale names are a bit vague because
 standardization is weak in this area.  See again the L<Finding
 locales> about general rules.
 
-=head2 Permanently fixing system locale configuration
+=head2 Fixing system locale configuration
 
 Contact a system administrator (preferably your own) and report the exact
 error message you get, and ask them to read this same documentation you
@@ -368,11 +380,12 @@ with a single parameter--see L<The setlocale function>.)
 
 localeconv() takes no arguments, and returns B<a reference to> a hash.
 The keys of this hash are variable names for formatting, such as
-C<decimal_point> and C<thousands_sep>.   The values are the corresponding,
-er, values.  See L<POSIX (3)/localeconv> for a longer example listing
-the categories an implementation might be expected to provide; some
-provide more and others fewer, however.  You don't need an explicit C<use
-locale>, because localeconv() always observes the current locale.
+C<decimal_point> and C<thousands_sep>.  The values are the
+corresponding, er, values.  See L<POSIX (3)/localeconv> for a longer
+example listing the categories an implementation might be expected to
+provide; some provide more and others fewer.  You don't need an
+explicit C<use locale>, because localeconv() always observes the
+current locale.
 
 Here's a simple-minded example program that rewrites its command-line
 parameters as integers correctly formatted in the current locale:
@@ -387,13 +400,29 @@ parameters as integers correctly formatted in the current locale:
 
         # Apply defaults if values are missing
         $thousands_sep = ',' unless $thousands_sep;
-        $grouping = 3 unless $grouping;
+
+       # grouping and mon_grouping are packed lists
+       # of small integers (characters) telling the
+       # grouping (thousand_seps and mon_thousand_seps
+       # being the group dividers) of numbers and
+       # monetary quantities.  The integers' meanings:
+       # 255 means no more grouping, 0 means repeat
+       # the previous grouping, 1-254 means use that
+       # as the current grouping.  Grouping goes from
+       # right to left (low to high digits).  In the
+       # below we cheat slightly by never using anything
+       # else than the first grouping (whatever that is).
+       if ($grouping) {
+           @grouping = unpack("C*", $grouping);
+       } else {
+           @grouping = (3);
+       }
 
         # Format command line params for current locale
         for (@ARGV) {
             $_ = int;    # Chop non-integer part
             1 while
-            s/(\d)(\d{$grouping}($|$thousands_sep))/$1$thousands_sep$2/;
+            s/(\d)(\d{$grouping[0]}($|$thousands_sep))/$1$thousands_sep$2/;
             print "$_";
         }
         print "\n";
@@ -412,6 +441,14 @@ environment variable to determine the application's notions on collation
 alphabets, but where do 'E<aacute>' and 'E<aring>' belong?  And while
 'color' follows 'chocolate' in English, what about in Spanish?
 
+The following collations all make sense and you may meet any of them
+if you "use locale".
+
+       A B C D E a b c d e
+       A a B b C c D d D e
+       a A b B c C d D e E
+       a b c d e A B C D E
+
 Here is a code snippet to tell what alphanumeric
 characters are in the current locale, in that locale's order:
 
@@ -571,8 +608,12 @@ obeys the current C<LC_TIME> locale.
 
 The remaining locale category, C<LC_MESSAGES> (possibly supplemented
 by others in particular implementations) is not currently used by
-Perl--except possibly to affect the behavior of library functions called
-by extensions outside the standard Perl distribution.
+Perl--except possibly to affect the behavior of library functions
+called by extensions outside the standard Perl distribution and by the
+operating system and its utilities.  Note especially that the string
+value of C<$!> and the error messages given by external utilities may
+be changed by C<LC_MESSAGES>.  If you want to have portable error
+codes, use C<%!>.  See L<Errno>.
 
 =head1 SECURITY
 
@@ -675,7 +716,7 @@ case-mapping with C<\l>, C<\L>,C<\u> or C<\U>.
 
 =item B<In-memory formatting function> (sprintf()):
 
-Result is tainted if "use locale" is in effect.
+Result is tainted if C<use locale> is in effect.
 
 =item B<Output formatting functions> (printf() and write()):
 
@@ -750,9 +791,10 @@ of a match involving C<\w> while C<use locale> is in effect.
 A string that can suppress Perl's warning about failed locale settings
 at startup.  Failure can occur if the locale support in the operating
 system is lacking (broken) in some way--or if you mistyped the name of
-a locale when you set up your environment.  If this environment variable
-is absent, or has a value that does not evaluate to integer zero--that
-is, "0" or ""--Perl will complain about locale setting failures.
+a locale when you set up your environment.  If this environment
+variable is absent, or has a value that does not evaluate to integer
+zero--that is, "0" or ""-- Perl will complain about locale setting
+failures.
 
 B<NOTE>: PERL_BADLANG only gives you a way to hide the warning message.
 The message tells about some problem in your system's locale support,
@@ -771,6 +813,20 @@ for controlling an application's opinion on data.
 C<LC_ALL> is the "override-all" locale environment variable. If
 set, it overrides all the rest of the locale environment variables.
 
+=item LANGUAGE
+
+B<NOTE>: C<LANGUAGE> is a GNU extension, it affects you only if you
+are using the GNU libc.  This is the case if you are using e.g. Linux.
+If you are using "commercial" UNIXes you are most probably I<not>
+using GNU libc and you can ignore C<LANGUAGE>.
+
+However, in the case you are using C<LANGUAGE>: it affects the
+language of informational, warning, and error messages output by
+commands (in other words, it's like C<LC_MESSAGES>) but it has higher
+priority than L<LC_ALL>.  Moreover, it's not a single value but
+instead a "path" (":"-separated list) of I<languages> (not locales).
+See the GNU C<gettext> library documentation for more information.
+
 =item LC_CTYPE
 
 In the absence of C<LC_ALL>, C<LC_CTYPE> chooses the character type
@@ -819,7 +875,7 @@ always in force, even if the program environment suggested otherwise
 (see L<The setlocale function>).  By default, Perl still behaves this
 way for backward compatibility.  If you want a Perl application to pay
 attention to locale information, you B<must> use the S<C<use locale>>
-pragma (see L<The use locale Pragma>) to instruct it to do so.
+pragma (see L<The use locale pragma>) to instruct it to do so.
 
 Versions of Perl from 5.002 to 5.003 did use the C<LC_CTYPE>
 information if available; that is, C<\w> did understand what