1 package I18N::Langinfo;
11 our @ISA = qw(Exporter);
13 our @EXPORT = qw(langinfo);
75 our $VERSION = '0.19';
84 I18N::Langinfo - query locale information
92 The langinfo() function queries various locale information that can be
93 used to localize output and user interfaces. It uses the current underlying
94 locale, regardless of whether or not it was called from within the scope of
95 S<C<use locale>>. The langinfo() function requires
96 one numeric argument that identifies the locale constant to query:
97 if no argument is supplied, C<$_> is used. The numeric constants
98 appropriate to be used as arguments are exportable from I18N::Langinfo.
100 The following example will import the langinfo() function itself and
101 three constants to be used as arguments to langinfo(): a constant for
102 the abbreviated first day of the week (the numbering starts from
103 Sunday = 1) and two more constants for the affirmative and negative
104 answers for a yes/no question in the current locale.
106 use I18N::Langinfo qw(langinfo ABDAY_1 YESSTR NOSTR);
108 my ($abday_1, $yesstr, $nostr) =
109 map { langinfo($_) } (ABDAY_1, YESSTR, NOSTR);
111 print "$abday_1? [$yesstr/$nostr] ";
113 In other words, in the "C" (or English) locale the above will probably
114 print something like:
118 but under a French locale
122 The usually available constants are as follows.
128 For abbreviated and full length days of the week and months of the year:
130 ABDAY_1 ABDAY_2 ABDAY_3 ABDAY_4 ABDAY_5 ABDAY_6 ABDAY_7
131 ABMON_1 ABMON_2 ABMON_3 ABMON_4 ABMON_5 ABMON_6
132 ABMON_7 ABMON_8 ABMON_9 ABMON_10 ABMON_11 ABMON_12
133 DAY_1 DAY_2 DAY_3 DAY_4 DAY_5 DAY_6 DAY_7
134 MON_1 MON_2 MON_3 MON_4 MON_5 MON_6
135 MON_7 MON_8 MON_9 MON_10 MON_11 MON_12
139 For the date-time, date, and time formats used by the strftime() function
146 For the locales for which it makes sense to have ante meridiem and post
147 meridiem time formats:
149 AM_STR PM_STR T_FMT_AMPM
153 For the character code set being used (such as "ISO8859-1", "cp850",
154 "koi8-r", "sjis", "utf8", etc.), and for the currency string:
160 For an alternate representation of digits, for the
161 radix character used between the integer and the fractional part
162 of decimal numbers, the group separator string for large-ish floating point
163 numbers (yes, the final two are redundant with
164 L<POSIX::localeconv()|POSIX/localeconv>):
166 ALT_DIGITS RADIXCHAR THOUSEP
170 For the affirmative and negative responses and expressions:
172 YESSTR YESEXPR NOSTR NOEXPR
176 For the eras based on typically some ruler, such as the Japanese Emperor
177 (naturally only defined in the appropriate locales):
179 ERA ERA_D_FMT ERA_D_T_FMT ERA_T_FMT
183 =head2 For systems without C<nl_langinfo>
185 Starting in Perl 5.28, this module is available even on systems that lack a
186 native C<nl_langinfo>. On such systems, it uses various methods to construct
187 what that function, if present, would return. But there are potential
188 glitches. These are the items that could be different:
194 Unimplemented, so returns C<"">.
198 Unimplemented, except on Windows, due to the vagaries of vendor locale names,
199 returning C<""> on non-Windows.
209 Only the values for English are returned. C<YESSTR> and C<NOSTR> have been
210 removed from POSIX 2008, and are retained here for backwards compatibility.
211 Your platform's C<nl_langinfo> may not support them.
215 Always evaluates to C<%x>, the locale's appropriate date representation.
219 Always evaluates to C<%X>, the locale's appropriate time representation.
223 Always evaluates to C<%c>, the locale's appropriate date and time
228 The return may be incorrect for those rare locales where the currency symbol
229 replaces the radix character.
230 Send email to L<mailto:perlbug@perl.org> if you have examples of it needing
235 Currently this gives the same results as Linux does.
236 Send email to L<mailto:perlbug@perl.org> if you have examples of it needing
247 These are derived by using C<strftime()>, and not all versions of that function
248 know about them. C<""> is returned for these on such systems.
252 See your L<nl_langinfo(3)> for more information about the available
253 constants. (Often this means having to look directly at the
254 F<langinfo.h> C header file.)
258 By default only the C<langinfo()> function is exported.
262 Before Perl 5.28, the returned values are unreliable for the C<RADIXCHAR> and
263 C<THOUSEP> locale constants.
265 Starting in 5.28, changing locales on threaded builds is supported on systems
266 that offer thread-safe locale functions. These include POSIX 2008 systems and
267 Windows starting with Visual Studio 2005, and this module will work properly
268 in such situations. However, on threaded builds on Windows prior to Visual
269 Studio 2015, retrieving the items C<CRNCYSTR> and C<THOUSEP> can result in a
270 race with a thread that has converted to use the global locale. It is quite
271 uncommon for a thread to have done this. It would be possible to construct a
272 workaround for this; patches welcome: see L<perlapi/switch_to_global_locale>.
276 L<perllocale>, L<POSIX/localeconv>, L<POSIX/setlocale>, L<nl_langinfo(3)>.
278 The langinfo() function is just a wrapper for the C nl_langinfo() interface.
282 Jarkko Hietaniemi, E<lt>jhi@hut.fiE<gt>. Now maintained by Perl 5 porters.
284 =head1 COPYRIGHT AND LICENSE
286 Copyright 2001 by Jarkko Hietaniemi
288 This library is free software; you can redistribute it and/or modify
289 it under the same terms as Perl itself.