1 package I18N::Langinfo;
11 our @ISA = qw(Exporter);
13 our @EXPORT = qw(langinfo);
75 our $VERSION = '0.15';
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() 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
124 ABDAY_1 ABDAY_2 ABDAY_3 ABDAY_4 ABDAY_5 ABDAY_6 ABDAY_7
125 ABMON_1 ABMON_2 ABMON_3 ABMON_4 ABMON_5 ABMON_6
126 ABMON_7 ABMON_8 ABMON_9 ABMON_10 ABMON_11 ABMON_12
127 DAY_1 DAY_2 DAY_3 DAY_4 DAY_5 DAY_6 DAY_7
128 MON_1 MON_2 MON_3 MON_4 MON_5 MON_6
129 MON_7 MON_8 MON_9 MON_10 MON_11 MON_12
131 for abbreviated and full length days of the week and months of the year,
135 for the date-time, date, and time formats used by the strftime() function
138 AM_STR PM_STR T_FMT_AMPM
140 for the locales for which it makes sense to have ante meridiem and post
141 meridiem time formats,
143 CODESET CRNCYSTR RADIXCHAR
145 for the character code set being used (such as "ISO8859-1", "cp850",
146 "koi8-r", "sjis", "utf8", etc.), for the currency string, for the
147 radix character used between the integer and the fractional part
148 of decimal numbers (yes, this is redundant with POSIX::localeconv())
150 YESSTR YESEXPR NOSTR NOEXPR
152 for the affirmative and negative responses and expressions, and
154 ERA ERA_D_FMT ERA_D_T_FMT ERA_T_FMT
156 for the Japanese Emperor eras (naturally only defined under Japanese locales).
158 See your L<langinfo(3)> for more information about the available
159 constants. (Often this means having to look directly at the
160 F<langinfo.h> C header file.)
162 Note that unfortunately none of the above constants are guaranteed
163 to be available on a particular platform. To be on the safe side
164 you can wrap the import in an eval like this:
167 require I18N::Langinfo;
168 I18N::Langinfo->import(qw(langinfo CODESET));
169 $codeset = langinfo(CODESET()); # note the ()
171 if ($@) { ... failed ... }
175 By default only the C<langinfo()> function is exported.
179 Before Perl 5.28, the returned values are unreliable for the C<RADIXCHAR> and
180 C<THOUSEP> locale constants.
184 L<perllocale>, L<POSIX/localeconv>, L<POSIX/setlocale>, L<nl_langinfo(3)>.
186 The langinfo() is just a wrapper for the C nl_langinfo() interface.
190 Jarkko Hietaniemi, E<lt>jhi@hut.fiE<gt>
192 =head1 COPYRIGHT AND LICENSE
194 Copyright 2001 by Jarkko Hietaniemi
196 This library is free software; you can redistribute it and/or modify
197 it under the same terms as Perl itself.