1 # Common tools for test files files to find the locales which exist on the
4 # Note that it's okay that some languages have their native names
5 # capitalized here even though that's not "right". They are lowercased
6 # anyway later during the scanning process (and besides, some clueless
7 # vendor might have them capitalized erroneously anyway).
10 sub _trylocale { # Adds the locale given by the first parameter to the list
11 # given by the 2nd iff the platform supports the locale,
12 # and it is not already on the list
15 return if grep { $locale eq $_ } @$list;
16 return unless setlocale(&POSIX::LC_ALL, $locale);
19 local $SIG{__WARN__} = sub {
20 $badutf8 = $_[0] =~ /Malformed UTF-8/;
25 ok(0, "Verify locale name doesn't contain malformed utf8");
31 sub _decode_encodings {
34 foreach (split(/ /, shift)) {
36 push @enc, "ISO8859-$1";
37 push @enc, "iso8859$1"; # HP
39 push @enc, "roman8"; # HP
42 push @enc, "$_.UTF-8";
46 push @enc, qw(IBM-037 IBM-819 IBM-1047);
53 sub find_locales { # Returns an array of all the locales we found on the
57 my $have_setlocale = 0;
60 import POSIX ':locale_h';
64 # Visual C's CRT goes silly on strings of the form "en_US.ISO8859-1"
65 # and mingw32 uses said silly CRT
66 # This doesn't seem to be an issue any more, at least on Windows XP,
67 # so re-enable the tests for Windows XP onwards.
68 my $winxp = ($^O eq 'MSWin32' && defined &Win32::GetOSVersion &&
69 join('.', (Win32::GetOSVersion())[1..2]) >= 5.1);
70 $have_setlocale = 0 if ((($^O eq 'MSWin32' && !$winxp) || $^O eq 'NetWare') &&
71 $Config{cc} =~ /^(cl|gcc|g\+\+|ici)/i);
73 # UWIN seems to loop after taint tests, just skip for now
74 $have_setlocale = 0 if ($^O =~ /^uwin/);
76 return unless $have_setlocale;
78 _trylocale("C", \@Locale);
79 _trylocale("POSIX", \@Locale);
81 _trylocale("ISO8859-$_", \@Locale);
82 _trylocale("iso8859$_", \@Locale);
83 _trylocale("iso8859-$_", \@Locale);
84 _trylocale("iso_8859_$_", \@Locale);
85 _trylocale("isolatin$_", \@Locale);
86 _trylocale("isolatin-$_", \@Locale);
87 _trylocale("iso_latin_$_", \@Locale);
90 # Sanitize the environment so that we can run the external 'locale'
91 # program without the taint mode getting grumpy.
93 # $ENV{PATH} is special in VMS.
94 delete $ENV{PATH} if $^O ne 'VMS' or $Config{d_setenv};
96 # Other subversive stuff.
97 delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
99 if (-x "/usr/bin/locale"
100 && open(LOCALES, "/usr/bin/locale -a 2>/dev/null|"))
103 # It seems that /usr/bin/locale steadfastly outputs 8 bit data, which
104 # ain't great when we're running this testPERL_UNICODE= so that utf8
105 # locales will cause all IO hadles to default to (assume) utf8
106 next unless utf8::valid($_);
108 _trylocale($_, \@Locale);
111 } elsif ($^O eq 'VMS'
112 && defined($ENV{'SYS$I18N_LOCALE'})
113 && -d 'SYS$I18N_LOCALE')
115 # The SYS$I18N_LOCALE logical name search list was not present on
116 # VAX VMS V5.5-12, but was on AXP && VAX VMS V6.2 as well as later versions.
117 opendir(LOCALES, "SYS\$I18N_LOCALE:");
118 while ($_ = readdir(LOCALES)) {
120 _trylocale($_, \@Locale);
123 } elsif (($^O eq 'openbsd' || $^O eq 'bitrig' ) && -e '/usr/share/locale') {
125 # OpenBSD doesn't have a locale executable, so reading /usr/share/locale
126 # is much easier and faster than the last resort method.
128 opendir(LOCALES, '/usr/share/locale');
129 while ($_ = readdir(LOCALES)) {
131 _trylocale($_, \@Locale);
134 } else { # Final fallback. Try our list of locales hard-coded here
136 # This is going to be slow.
140 # Locales whose name differs if the utf8 bit is on are stored in these two
141 # files with appropriate encodings.
142 if ($^H & 0x08 || (${^OPEN} || "") =~ /:utf8/) {
143 @Data = do "lib/locale/utf8";
145 @Data = do "lib/locale/latin1";
148 # The rest of the locales are in this file.
151 foreach my $line (@Data) {
152 my ($locale_name, $language_codes, $country_codes, $encodings) =
154 my @enc = _decode_encodings($encodings);
155 foreach my $loc (split(/ /, $locale_name)) {
156 _trylocale($loc, \@Locale);
157 foreach my $enc (@enc) {
158 _trylocale("$loc.$enc", \@Locale);
161 foreach my $enc (@enc) {
162 _trylocale("$loc.$enc", \@Locale);
165 foreach my $lang (split(/ /, $language_codes)) {
166 _trylocale($lang, \@Locale);
167 foreach my $country (split(/ /, $country_codes)) {
168 my $lc = "${lang}_${country}";
169 _trylocale($lc, \@Locale);
170 foreach my $enc (@enc) {
171 _trylocale("$lc.$enc", \@Locale);
173 my $lC = "${lang}_\U${country}";
174 _trylocale($lC, \@Locale);
175 foreach my $enc (@enc) {
176 _trylocale("$lC.$enc", \@Locale);
183 @Locale = sort @Locale;
192 # Format of data is: locale_name, language_codes, country_codes, encodings
195 Arabic:ar:dz eg sa:6 arabic8
196 Brezhoneg Breton:br:fr:1 15
197 Bulgarski Bulgarian:bg:bg:5
198 Chinese:zh:cn tw:cn.EUC eucCN eucTW euc.CN euc.TW Big5 GB2312 tw.EUC
199 Hrvatski Croatian:hr:hr:2
200 Cymraeg Welsh:cy:cy:1 14 15
202 Dansk Danish:da:dk:1 15
203 Nederlands Dutch:nl:be nl:1 15
204 English American British:en:au ca gb ie nz us uk zw:1 15 cp850
206 Eesti Estonian:et:ee:4 6 13
207 Suomi Finnish:fi:fi:1 15
209 Deutsch German:de:at be ch de lu:1 15
210 Euskaraz Basque:eu:es fr:1 15
211 Galego Galician:gl:es:1 15
212 Ellada Greek:el:gr:7 g8
214 Greenlandic:kl:gl:4 6
215 Hebrew:iw:il:8 hebrew8
217 Indonesian:id:id:1 15
218 Gaeilge Irish:ga:IE:1 14 15
219 Italiano Italian:it:ch it:1 15
220 Nihongo Japanese:ja:jp:euc eucJP jp.EUC sjis
222 Latine Latin:la:va:1 15
224 Lithuanian:lt:lt:4 6 13
225 Macedonian:mk:mk:1 15
228 Norsk Norwegian:no no\@nynorsk nb nn:no:1 15
230 Polski Polish:pl:pl:2
232 Russki Russian:ru:ru su ua:5 koi8 koi8r KOI8-R koi8u cp1251 cp866
233 Serbski Serbian:sr:yu:5
235 Slovene Slovenian:sl:si:2
236 Sqhip Albanian:sq:sq:1 15
237 Svenska Swedish:sv:fi se:1 15
239 Turkish:tr:tr:9 turkish8