Edit INSTALL to describe new binary compat setup
[p5sagit/p5-mst-13.2.git] / pod / perllocale.pod
CommitLineData
5f05dabc 1=head1 NAME
2
14280422 3perllocale - Perl locale handling (internationlization and localization)
5f05dabc 4
5=head1 DESCRIPTION
6
7Perl supports language-specific notions of data such as "is this a
14280422 8letter", "what is the upper-case equivalent of this letter", and "which
9of these letters comes first". These are important issues, especially
10for languages other than English - but also for English: it would be
11very naE<iuml>ve to think that C<A-Za-z> defines all the "letters". Perl
12is also aware that some character other than '.' may be preferred as a
13decimal point, and that output date representations may be
14language-specific. The process of making an application take account of
15its users' preferences in such matters is called B<internationalization>
16(often abbreviated as B<i18n>); telling such an application about a
17particular set of preferences is known as B<localization> (B<l10n>).
18
19Perl can understand language-specific data via the standardized (ISO C,
20XPG4, POSIX 1.c) method called "the locale system". The locale system is
21controlled per application using a pragma, one function call, and
22several environment variables.
23
24B<NOTE>: This feature is new in Perl 5.004, and does not apply unless an
25application specifically requests it - see L<Backward compatibility>.
5f05dabc 26
27=head1 PREPARING TO USE LOCALES
28
14280422 29If Perl applications are to be able to understand and present your data
30correctly according a locale of your choice, B<all> of the following
5f05dabc 31must be true:
32
33=over 4
34
35=item *
36
37B<Your operating system must support the locale system>. If it does,
14280422 38you should find that the setlocale() function is a documented part of
5f05dabc 39its C library.
40
41=item *
42
14280422 43B<Definitions for the locales which you use must be installed>. You, or
44your system administrator, must make sure that this is the case. The
45available locales, the location in which they are kept, and the manner
46in which they are installed, vary from system to system. Some systems
47provide only a few, hard-wired, locales, and do not allow more to be
48added; others allow you to add "canned" locales provided by the system
49supplier; still others allow you or the system administrator to define
50and add arbitrary locales. (You may have to ask your supplier to
51provide canned locales which are not delivered with your operating
52system.) Read your system documentation for further illumination.
5f05dabc 53
54=item *
55
56B<Perl must believe that the locale system is supported>. If it does,
57C<perl -V:d_setlocale> will say that the value for C<d_setlocale> is
58C<define>.
59
60=back
61
62If you want a Perl application to process and present your data
63according to a particular locale, the application code should include
14280422 64the S<C<use locale>> pragma (see L<The use locale Pragma>) where
5f05dabc 65appropriate, and B<at least one> of the following must be true:
66
67=over 4
68
69=item *
70
14280422 71B<The locale-determining environment variables (see L<"ENVIRONMENT">)
72must be correctly set up>, either by yourself, or by the person who set
73up your system account, at the time the application is started.
5f05dabc 74
75=item *
76
14280422 77B<The application must set its own locale> using the method described in
78L<The setlocale function>.
5f05dabc 79
80=back
81
82=head1 USING LOCALES
83
84=head2 The use locale pragma
85
14280422 86By default, Perl ignores the current locale. The S<C<use locale>>
87pragma tells Perl to use the current locale for some operations:
5f05dabc 88
89=over 4
90
91=item *
92
14280422 93B<The comparison operators> (C<lt>, C<le>, C<cmp>, C<ge>, and C<gt>) and
94the POSIX string collation functions strcoll() and strxfrm() use
95C<LC_COLLATE>. sort() is also affected if it is used without an
96explicit comparison function because it uses C<cmp> by default.
97
98B<Note:> C<eq> and C<ne> are unaffected by the locale: they always
99perform a byte-by-byte comparison of their scalar operands. What's
100more, if C<cmp> finds that its operands are equal according to the
101collation sequence specified by the current locale, it goes on to
102perform a byte-by-byte comparison, and only returns I<0> (equal) if the
103operands are bit-for-bit identical. If you really want to know whether
104two strings - which C<eq> and C<cmp> may consider different - are equal
105as far as collation in the locale is concerned, see the discussion in
106L<Category LC_COLLATE: Collation>.
5f05dabc 107
108=item *
109
14280422 110B<Regular expressions and case-modification functions> (uc(), lc(),
111ucfirst(), and lcfirst()) use C<LC_CTYPE>
5f05dabc 112
113=item *
114
14280422 115B<The formatting functions> (printf(), sprintf() and write()) use
5f05dabc 116C<LC_NUMERIC>
117
118=item *
119
14280422 120B<The POSIX date formatting function> (strftime()) uses C<LC_TIME>.
5f05dabc 121
122=back
123
14280422 124C<LC_COLLATE>, C<LC_CTYPE>, and so on, are discussed further in L<LOCALE
125CATEGORIES>.
5f05dabc 126
14280422 127The default behaviour returns with S<C<no locale>> or on reaching the
128end of the enclosing block.
5f05dabc 129
14280422 130Note that the string result of any operation that uses locale
131information is tainted, as it is possible for a locale to be
132untrustworthy. See L<"SECURITY">.
5f05dabc 133
134=head2 The setlocale function
135
14280422 136You can switch locales as often as you wish at run time with the
137POSIX::setlocale() function:
5f05dabc 138
139 # This functionality not usable prior to Perl 5.004
140 require 5.004;
141
142 # Import locale-handling tool set from POSIX module.
143 # This example uses: setlocale -- the function call
144 # LC_CTYPE -- explained below
145 use POSIX qw(locale_h);
146
14280422 147 # query and save the old locale
5f05dabc 148 $old_locale = setlocale(LC_CTYPE);
149
150 setlocale(LC_CTYPE, "fr_CA.ISO8859-1");
151 # LC_CTYPE now in locale "French, Canada, codeset ISO 8859-1"
152
153 setlocale(LC_CTYPE, "");
154 # LC_CTYPE now reset to default defined by LC_ALL/LC_CTYPE/LANG
155 # environment variables. See below for documentation.
156
157 # restore the old locale
158 setlocale(LC_CTYPE, $old_locale);
159
14280422 160The first argument of setlocale() gives the B<category>, the second the
161B<locale>. The category tells in what aspect of data processing you
162want to apply locale-specific rules. Category names are discussed in
163L<LOCALE CATEGORIES> and L<"ENVIRONMENT">. The locale is the name of a
164collection of customization information corresponding to a particular
165combination of language, country or territory, and codeset. Read on for
166hints on the naming of locales: not all systems name locales as in the
167example.
168
169If no second argument is provided, the function returns a string naming
170the current locale for the category. You can use this value as the
171second argument in a subsequent call to setlocale(). If a second
5f05dabc 172argument is given and it corresponds to a valid locale, the locale for
173the category is set to that value, and the function returns the
174now-current locale value. You can use this in a subsequent call to
14280422 175setlocale(). (In some implementations, the return value may sometimes
5f05dabc 176differ from the value you gave as the second argument - think of it as
177an alias for the value that you gave.)
178
179As the example shows, if the second argument is an empty string, the
180category's locale is returned to the default specified by the
181corresponding environment variables. Generally, this results in a
182return to the default which was in force when Perl started up: changes
14280422 183to the environment made by the application after start-up may or may not
184be noticed, depending on the implementation of your system's C library.
5f05dabc 185
14280422 186If the second argument does not correspond to a valid locale, the locale
187for the category is not changed, and the function returns I<undef>.
5f05dabc 188
14280422 189For further information about the categories, consult L<setlocale(3)>.
190For the locales available in your system, also consult L<setlocale(3)>
191and see whether it leads you to the list of the available locales
192(search for the I<SEE ALSO> section). If that fails, try the following
193command lines:
5f05dabc 194
195 locale -a
196
197 nlsinfo
198
199 ls /usr/lib/nls/loc
200
201 ls /usr/lib/locale
202
203 ls /usr/lib/nls
204
205and see whether they list something resembling these
206
14280422 207 en de ru
208 english de_DE russian
209 english.iso88591 de_DE.ISO8859-1 russian.iso88595
210 en_US german ru_RU
211 en_US.ISO8859-1 german.iso88591 ru_RU.ISO8859-5
5f05dabc 212
14280422 213Sadly, even though the calling interface for setlocale() has been
5f05dabc 214standardized, the names of the locales have not. The form of the name
215is usually I<language_country>B</>I<territory>B<.>I<codeset>, but the
216latter parts are not always present.
217
14280422 218Two special locales are worth particular mention: "C" and "POSIX".
219Currently these are effectively the same locale: the difference is
220mainly that the first one is defined by the C standard and the second by
221the POSIX standard. What they define is the B<default locale> in which
222every program starts in the absence of locale information in its
223environment. (The default default locale, if you will.) Its language
224is (American) English and its character codeset ASCII.
5f05dabc 225
14280422 226B<NOTE>: Not all systems have the "POSIX" locale (not all systems are
227POSIX-conformant), so use "C" when you need explicitly to specify this
228default locale.
5f05dabc 229
230=head2 The localeconv function
231
14280422 232The POSIX::localeconv() function allows you to get particulars of the
233locale-dependent numeric formatting information specified by the current
234C<LC_NUMERIC> and C<LC_MONETARY> locales. (If you just want the name of
235the current locale for a particular category, use POSIX::setlocale()
236with a single parameter - see L<The setlocale function>.)
5f05dabc 237
238 use POSIX qw(locale_h);
5f05dabc 239
240 # Get a reference to a hash of locale-dependent info
241 $locale_values = localeconv();
242
243 # Output sorted list of the values
244 for (sort keys %$locale_values) {
14280422 245 printf "%-20s = %s\n", $_, $locale_values->{$_}
5f05dabc 246 }
247
14280422 248localeconv() takes no arguments, and returns B<a reference to> a hash.
249The keys of this hash are formatting variable names such as
250C<decimal_point> and C<thousands_sep>; the values are the corresponding
251values. See L<POSIX (3)/localeconv> for a longer example, which lists
252all the categories an implementation might be expected to provide; some
253provide more and others fewer, however. Note that you don't need C<use
254locale>: as a function with the job of querying the locale, localeconv()
255always observes the current locale.
5f05dabc 256
257Here's a simple-minded example program which rewrites its command line
258parameters as integers formatted correctly in the current locale:
259
260 # See comments in previous example
261 require 5.004;
262 use POSIX qw(locale_h);
5f05dabc 263
264 # Get some of locale's numeric formatting parameters
265 my ($thousands_sep, $grouping) =
14280422 266 @{localeconv()}{'thousands_sep', 'grouping'};
5f05dabc 267
268 # Apply defaults if values are missing
269 $thousands_sep = ',' unless $thousands_sep;
270 $grouping = 3 unless $grouping;
271
272 # Format command line params for current locale
14280422 273 for (@ARGV) {
274 $_ = int; # Chop non-integer part
5f05dabc 275 1 while
14280422 276 s/(\d)(\d{$grouping}($|$thousands_sep))/$1$thousands_sep$2/;
277 print "$_";
5f05dabc 278 }
279 print "\n";
280
5f05dabc 281=head1 LOCALE CATEGORIES
282
14280422 283The subsections which follow describe basic locale categories. As well
5f05dabc 284as these, there are some combination categories which allow the
14280422 285manipulation of more than one basic category at a time. See
286L<"ENVIRONMENT"> for a discussion of these.
5f05dabc 287
288=head2 Category LC_COLLATE: Collation
289
14280422 290When in the scope of S<C<use locale>>, Perl looks to the C<LC_COLLATE>
5f05dabc 291environment variable to determine the application's notions on the
14280422 292collation (ordering) of characters. ('b' follows 'a' in Latin
293alphabets, but where do 'E<aacute>' and 'E<aring>' belong?)
5f05dabc 294
295Here is a code snippet that will tell you what are the alphanumeric
296characters in the current locale, in the locale order:
297
298 use locale;
299 print +(sort grep /\w/, map { chr() } 0..255), "\n";
300
14280422 301Compare this with the characters that you see and their order if you
302state explicitly that the locale should be ignored:
5f05dabc 303
304 no locale;
305 print +(sort grep /\w/, map { chr() } 0..255), "\n";
306
307This machine-native collation (which is what you get unless S<C<use
308locale>> has appeared earlier in the same block) must be used for
309sorting raw binary data, whereas the locale-dependent collation of the
310first example is useful for written text.
311
14280422 312As noted in L<USING LOCALES>, C<cmp> compares according to the current
313collation locale when C<use locale> is in effect, but falls back to a
314byte-by-byte comparison for strings which the locale says are equal. You
315can use POSIX::strcoll() if you don't want this fall-back:
316
317 use POSIX qw(strcoll);
318 $equal_in_locale =
319 !strcoll("space and case ignored", "SpaceAndCaseIgnored");
320
321$equal_in_locale will be true if the collation locale specifies a
322dictionary-like ordering which ignores space characters completely, and
323which folds case. Alternatively, you can use this idiom:
324
325 use locale;
326 $s_a = "space and case ignored";
327 $s_b = "SpaceAndCaseIgnored";
328 $equal_in_locale = $s_a ge $s_b && $s_a le $s_b;
329
330which works because neither C<ne> nor C<ge> falls back to doing a
331byte-by-byte comparison when the operands are equal according to the
332locale. The idiom may be less efficient than using strcoll(), but,
333unlike that function, it is not confused by strings containing embedded
334nulls.
335
336If you have a single string which you want to check for "equality in
337locale" against several others, you might think you could gain a little
338efficiency by using POSIX::strxfrm() in conjunction with C<eq>:
339
340 use POSIX qw(strxfrm);
341 $xfrm_string = strxfrm("Mixed-case string");
342 print "locale collation ignores spaces\n"
343 if $xfrm_string eq strxfrm("Mixed-casestring");
344 print "locale collation ignores hyphens\n"
345 if $xfrm_string eq strxfrm("Mixedcase string");
346 print "locale collation ignores case\n"
347 if $xfrm_string eq strxfrm("mixed-case string");
348
349strxfrm() takes a string and maps it into a transformed string for use
350in byte-by-byte comparisons against other transformed strings during
351collation. "Under the hood", locale-affected Perl comparison operators
352call strxfrm() for both their operands, then do a byte-by-byte
353comparison of the transformed strings. By calling strxfrm() explicitly,
354and using a non locale-affected comparison, the example attempts to save
355a couple of transformations. In fact, it doesn't save anything: Perl
356magic (see L<perlguts/Magic>) creates the transformed version of a
357string the first time it's needed in a comparison, then keeps it around
358in case it's needed again. An example rewritten the easy way with
359C<cmp> runs just about as fast. It also copes with null characters
360embedded in strings; if you call strxfrm() directly, it treats the first
361null it finds as a terminator. In short, don't call strxfrm() directly:
362let Perl do it for you.
363
364Note: C<use locale> isn't shown in some of these examples, as it isn't
365needed: strcoll() and strxfrm() exist only to generate locale-dependent
366results, and so always obey the current C<LC_COLLATE> locale.
5f05dabc 367
368=head2 Category LC_CTYPE: Character Types
369
370When in the scope of S<C<use locale>>, Perl obeys the C<LC_CTYPE> locale
14280422 371setting. This controls the application's notion of which characters are
372alphabetic. This affects Perl's C<\w> regular expression metanotation,
373which stands for alphanumeric characters - that is, alphabetic and
374numeric characters. (Consult L<perlre> for more information about
375regular expressions.) Thanks to C<LC_CTYPE>, depending on your locale
376setting, characters like 'E<aelig>', 'E<eth>', 'E<szlig>', and
377'E<oslash>' may be understood as C<\w> characters.
5f05dabc 378
379C<LC_CTYPE> also affects the POSIX character-class test functions -
14280422 380isalpha(), islower() and so on. For example, if you move from the "C"
381locale to a 7-bit Scandinavian one, you may find - possibly to your
382surprise - that "|" moves from the ispunct() class to isalpha().
5f05dabc 383
14280422 384B<Note:> A broken or malicious C<LC_CTYPE> locale definition may result
385in clearly ineligible characters being considered to be alphanumeric by
386your application. For strict matching of (unaccented) letters and
387digits - for example, in command strings - locale-aware applications
388should use C<\w> inside a C<no locale> block. See L<"SECURITY">.
5f05dabc 389
390=head2 Category LC_NUMERIC: Numeric Formatting
391
392When in the scope of S<C<use locale>>, Perl obeys the C<LC_NUMERIC>
14280422 393locale information, which controls application's idea of how numbers
394should be formatted for human readability by the printf(), sprintf(),
395and write() functions. String to numeric conversion by the
396POSIX::strtod() function is also affected. In most implementations the
397only effect is to change the character used for the decimal point -
398perhaps from '.' to ',': these functions aren't aware of such niceties
399as thousands separation and so on. (See L<The localeconv function> if
400you care about these things.)
401
402Note that output produced by print() is B<never> affected by the
5f05dabc 403current locale: it is independent of whether C<use locale> or C<no
14280422 404locale> is in effect, and corresponds to what you'd get from printf()
5f05dabc 405in the "C" locale. The same is true for Perl's internal conversions
406between numeric and string formats:
407
408 use POSIX qw(strtod);
409 use locale;
14280422 410
5f05dabc 411 $n = 5/2; # Assign numeric 2.5 to $n
412
413 $a = " $n"; # Locale-independent conversion to string
414
415 print "half five is $n\n"; # Locale-independent output
416
417 printf "half five is %g\n", $n; # Locale-dependent output
418
14280422 419 print "DECIMAL POINT IS COMMA\n"
420 if $n == (strtod("2,5"))[0]; # Locale-dependent conversion
5f05dabc 421
422=head2 Category LC_MONETARY: Formatting of monetary amounts
423
14280422 424The C standard defines the C<LC_MONETARY> category, but no function that
425is affected by its contents. (Those with experience of standards
426committees will recognise that the working group decided to punt on the
427issue.) Consequently, Perl takes no notice of it. If you really want
428to use C<LC_MONETARY>, you can query its contents - see L<The localeconv
429function> - and use the information that it returns in your
430application's own formating of currency amounts. However, you may well
431find that the information, though voluminous and complex, does not quite
432meet your requirements: currency formatting is a hard nut to crack.
5f05dabc 433
434=head2 LC_TIME
435
14280422 436The output produced by POSIX::strftime(), which builds a formatted
5f05dabc 437human-readable date/time string, is affected by the current C<LC_TIME>
438locale. Thus, in a French locale, the output produced by the C<%B>
439format element (full month name) for the first month of the year would
440be "janvier". Here's how to get a list of the long month names in the
441current locale:
442
443 use POSIX qw(strftime);
14280422 444 for (0..11) {
445 $long_month_name[$_] =
446 strftime("%B", 0, 0, 0, 1, $_, 96);
5f05dabc 447 }
448
14280422 449Note: C<use locale> isn't needed in this example: as a function which
450exists only to generate locale-dependent results, strftime() always
451obeys the current C<LC_TIME> locale.
5f05dabc 452
453=head2 Other categories
454
455The remaining locale category, C<LC_MESSAGES> (possibly supplemented by
456others in particular implementations) is not currently used by Perl -
14280422 457except possibly to affect the behaviour of library functions called by
458extensions which are not part of the standard Perl distribution.
459
460=head1 SECURITY
461
462While the main discussion of Perl security issues can be found in
463L<perlsec>, a discussion of Perl's locale handling would be incomplete
464if it did not draw your attention to locale-dependent security issues.
465Locales - particularly on systems which allow unprivileged users to
466build their own locales - are untrustworthy. A malicious (or just plain
467broken) locale can make a locale-aware application give unexpected
468results. Here are a few possibilities:
469
470=over 4
471
472=item *
473
474Regular expression checks for safe file names or mail addresses using
475C<\w> may be spoofed by an C<LC_CTYPE> locale which claims that
476characters such as "E<gt>" and "|" are alphanumeric.
477
478=item *
479
480If the decimal point character in the C<LC_NUMERIC> locale is
481surreptitiously changed from a dot to a comma, C<sprintf("%g",
4820.123456e3)> produces a string result of "123,456". Many people would
483interpret this as one hundred and twenty-three thousand, four hundred
484and fifty-six.
485
486=item *
487
488A sneaky C<LC_COLLATE> locale could result in the names of students with
489"D" grades appearing ahead of those with "A"s.
490
491=item *
492
493An application which takes the trouble to use the information in
494C<LC_MONETARY> may format debits as if they were credits and vice versa
495if that locale has been subverted. Or it make may make payments in US
496dollars instead of Hong Kong dollars.
497
498=item *
499
500The date and day names in dates formatted by strftime() could be
501manipulated to advantage by a malicious user able to subvert the
502C<LC_DATE> locale. ("Look - it says I wasn't in the building on
503Sunday.")
504
505=back
506
507Such dangers are not peculiar to the locale system: any aspect of an
508application's environment which may maliciously be modified presents
509similar challenges. Similarly, they are not specific to Perl: any
510programming language which allows you to write programs which take
511account of their environment exposes you to these issues.
512
513Perl cannot protect you from all of the possibilities shown in the
514examples - there is no substitute for your own vigilance - but, when
515C<use locale> is in effect, Perl uses the tainting mechanism (see
516L<perlsec>) to mark string results which become locale-dependent, and
517which may be untrustworthy in consequence. Here is a summary of the
518tainting behaviour of operators and functions which may be affected by
519the locale:
520
521=over 4
522
523=item B<Comparison operators> (C<lt>, C<le>, C<ge>, C<gt> and C<cmp>):
524
525Scalar true/false (or less/equal/greater) result is never tainted.
526
527=item B<Matching operator> (C<m//>):
528
529Scalar true/false result never tainted.
530
531Subpatterns, either delivered as an array-context result, or as $1 etc.
532are tainted if C<use locale> is in effect, and the subpattern regular
533expression contains C<\w> (to match an alphanumeric character). The
534matched pattern variable, $&, is also tainted if C<use locale> is in
535effect, and the regular expression contains C<\w>.
536
537=item B<Substitution operator> (C<s///>):
538
539Has the same behaviour as the match operator. When C<use locale> is
540in effect, he left operand of C<=~> will become tainted if it is
541modified as a result of a substitution based on a regular expression
542match involving C<\w>.
543
544=item B<In-memory formatting function> (sprintf()):
545
546Result is tainted if "use locale" is in effect.
547
548=item B<Output formatting functions> (printf() and write()):
549
550Success/failure result is never tainted.
551
552=item B<Case-mapping functions> (lc(), lcfirst(), uc(), ucfirst()):
553
554Results are tainted if C<use locale> is in effect.
555
556=item B<POSIX locale-dependent functions> (localeconv(), strcoll(),
557strftime(), strxfrm()):
558
559Results are never tainted.
560
561=item B<POSIX character class tests> (isalnum(), isalpha(), isdigit(),
562isgraph(), islower(), isprint(), ispunct(), isspace(), isupper(),
563isxdigit()):
564
565True/false results are never tainted.
566
567=back
568
569Three examples illustrate locale-dependent tainting.
570The first program, which ignores its locale, won't run: a value taken
571directly from the command-line may not be used to name an output file
572when taint checks are enabled.
573
574 #/usr/local/bin/perl -T
575 # Run with taint checking
576
577 # Command-line sanity check omitted...
578 $tainted_output_file = shift;
579
580 open(F, ">$tainted_output_file")
581 or warn "Open of $untainted_output_file failed: $!\n";
582
583The program can be made to run by "laundering" the tainted value through
584a regular expression: the second example - which still ignores locale
585information - runs, creating the file named on its command-line
586if it can.
587
588 #/usr/local/bin/perl -T
589
590 $tainted_output_file = shift;
591 $tainted_output_file =~ m%[\w/]+%;
592 $untainted_output_file = $&;
593
594 open(F, ">$untainted_output_file")
595 or warn "Open of $untainted_output_file failed: $!\n";
596
597Compare this with a very similar program which is locale-aware:
598
599 #/usr/local/bin/perl -T
600
601 $tainted_output_file = shift;
602 use locale;
603 $tainted_output_file =~ m%[\w/]+%;
604 $localized_output_file = $&;
605
606 open(F, ">$localized_output_file")
607 or warn "Open of $localized_output_file failed: $!\n";
608
609This third program fails to run because $& is tainted: it is the result
610of a match involving C<\w> when C<use locale> is in effect.
5f05dabc 611
612=head1 ENVIRONMENT
613
614=over 12
615
616=item PERL_BADLANG
617
14280422 618A string that can suppress Perl's warning about failed locale settings
619at start-up. Failure can occur if the locale support in the operating
620system is lacking (broken) is some way - or if you mistyped the name of
621a locale when you set up your environment. If this environment variable
622is absent, or has a value which does not evaluate to integer zero - that
623is "0" or "" - Perl will complain about locale setting failures.
5f05dabc 624
14280422 625B<NOTE>: PERL_BADLANG only gives you a way to hide the warning message.
626The message tells about some problem in your system's locale support,
627and you should investigate what the problem is.
5f05dabc 628
629=back
630
631The following environment variables are not specific to Perl: They are
14280422 632part of the standardized (ISO C, XPG4, POSIX 1.c) setlocale() method
633for controlling an application's opinion on data.
5f05dabc 634
635=over 12
636
637=item LC_ALL
638
639C<LC_ALL> is the "override-all" locale environment variable. If it is
640set, it overrides all the rest of the locale environment variables.
641
642=item LC_CTYPE
643
644In the absence of C<LC_ALL>, C<LC_CTYPE> chooses the character type
645locale. In the absence of both C<LC_ALL> and C<LC_CTYPE>, C<LANG>
646chooses the character type locale.
647
648=item LC_COLLATE
649
14280422 650In the absence of C<LC_ALL>, C<LC_COLLATE> chooses the collation
651(sorting) locale. In the absence of both C<LC_ALL> and C<LC_COLLATE>,
652C<LANG> chooses the collation locale.
5f05dabc 653
654=item LC_MONETARY
655
14280422 656In the absence of C<LC_ALL>, C<LC_MONETARY> chooses the monetary
657formatting locale. In the absence of both C<LC_ALL> and C<LC_MONETARY>,
658C<LANG> chooses the monetary formatting locale.
5f05dabc 659
660=item LC_NUMERIC
661
662In the absence of C<LC_ALL>, C<LC_NUMERIC> chooses the numeric format
663locale. In the absence of both C<LC_ALL> and C<LC_NUMERIC>, C<LANG>
664chooses the numeric format.
665
666=item LC_TIME
667
14280422 668In the absence of C<LC_ALL>, C<LC_TIME> chooses the date and time
669formatting locale. In the absence of both C<LC_ALL> and C<LC_TIME>,
670C<LANG> chooses the date and time formatting locale.
5f05dabc 671
672=item LANG
673
14280422 674C<LANG> is the "catch-all" locale environment variable. If it is set, it
675is used as the last resort after the overall C<LC_ALL> and the
5f05dabc 676category-specific C<LC_...>.
677
678=back
679
680=head1 NOTES
681
682=head2 Backward compatibility
683
684Versions of Perl prior to 5.004 ignored locale information, generally
685behaving as if something similar to the C<"C"> locale (see L<The
686setlocale function>) was always in force, even if the program
687environment suggested otherwise. By default, Perl still behaves this
688way so as to maintain backward compatibility. If you want a Perl
14280422 689application to pay attention to locale information, you B<must> use the
690S<C<use locale>> pragma (see L<The S<C<use locale>> Pragma>) to instruct
691it to do so.
5f05dabc 692
14280422 693=head2 Sort speed and memory use impacts
5f05dabc 694
695Comparing and sorting by locale is usually slower than the default
14280422 696sorting; slow-downs of two to four times have been observed. It will
697also consume more memory: once a Perl scalar variable has participated
698in any string comparison or sorting operation obeying the locale
699collation rules, it will take 3-15 times more memory than before. (The
700exact multiplier depends on the string's contents, the operating system
701and the locale.) These downsides are dictated more by the operating
702system's implementation of the locale system than by Perl.
5f05dabc 703
704=head2 I18N:Collate
705
706In Perl 5.003 (and later development releases prior to 5.003_06),
707per-locale collation was possible using the C<I18N::Collate> library
708module. This is now mildly obsolete and should be avoided in new
14280422 709applications. The C<LC_COLLATE> functionality is now integrated into
710the Perl core language and one can use locale-specific scalar data
5f05dabc 711completely normally - there is no need to juggle with the scalar
712references of C<I18N::Collate>.
713
5f05dabc 714=head2 Freely available locale definitions
715
716There is a large collection of locale definitions at
14280422 717C<ftp://dkuug.dk/i18n/WG15-collection>. You should be aware that it is
718unsupported, and is not claimed to be fit for any purpose. If your
719system allows the installation of arbitrary locales, you may find the
720definitions useful as they are, or as a basis for the development of
721your own locales.
5f05dabc 722
14280422 723=head2 I18n and l10n
5f05dabc 724
725Internationalization is often abbreviated as B<i18n> because its first
14280422 726and last letters are separated by eighteen others. In the same way, you
727abbreviate localization to B<l10n>.
728
729=head2 An imperfect standard
730
731Internationalization, as defined in the C and POSIX standards, can be
732criticized as incomplete, ungainly, and having too large a granularity.
733(Locales apply to a whole process, when it would arguably be more useful
734to have them apply to a single thread, window group, or whatever.) They
735also have a tendency, like standards groups, to divide the world into
736nations, when we all know that the world can equally well be divided
737into bankers, bikers, gamers, and so on. But, for now, it's the only
738standard we've got. This may be construed as a bug.
5f05dabc 739
740=head1 BUGS
741
742=head2 Broken systems
743
14280422 744In certain system environments the operating system's locale support is
745broken and cannot be fixed or used by Perl. Such deficiencies can and
746will result in mysterious hangs and/or Perl core dumps. One example is
747IRIX before release 6.2, in which the C<LC_COLLATE> support simply does
748not work. When confronted with such a system, please report in
749excruciating detail to C<perlbug@perl.com>, and complain to your vendor:
750maybe some bug fixes exist for these problems in your operating system.
751Sometimes such bug fixes are called an operating system upgrade.
5f05dabc 752
753=head1 SEE ALSO
754
755L<POSIX (3)/isalnum>, L<POSIX (3)/isalpha>, L<POSIX (3)/isdigit>,
756L<POSIX (3)/isgraph>, L<POSIX (3)/islower>, L<POSIX (3)/isprint>,
757L<POSIX (3)/ispunct>, L<POSIX (3)/isspace>, L<POSIX (3)/isupper>,
758L<POSIX (3)/isxdigit>, L<POSIX (3)/localeconv>, L<POSIX (3)/setlocale>,
14280422 759L<POSIX (3)/strcoll>, L<POSIX (3)/strftime>, L<POSIX (3)/strtod>,
760L<POSIX (3)/strxfrm>
5f05dabc 761
762=head1 HISTORY
763
14280422 764Jarrko Hietaniemi's original F<perli18n.pod> heavily hacked by Dominic
765Dunlop, assisted by the perl5-porters.
5f05dabc 766
14280422 767Last update: Mon Dec 23 10:44:08 EST 1996