1 package I18N::Langinfo;
12 our @ISA = qw(Exporter DynaLoader);
14 our @EXPORT = qw(langinfo);
76 our $VERSION = '0.02';
79 # This AUTOLOAD is used to 'autoload' constants from the constant()
84 ($constname = $AUTOLOAD) =~ s/.*:://;
85 croak "&I18N::Langinfo::constant not defined" if $constname eq 'constant';
86 my ($error, $val) = constant($constname);
87 if ($error) { croak $error; }
90 # Fixed between 5.005_53 and 5.005_61
91 #XXX if ($] >= 5.00561) {
92 #XXX *$AUTOLOAD = sub () { $val };
95 *$AUTOLOAD = sub { $val };
101 bootstrap I18N::Langinfo $VERSION;
108 I18N::Langinfo - query locale information
116 The langinfo() function queries various locale information that can be
117 used to localize output and user interfaces. The langinfo() requires
118 one numeric argument that identifies the locale constant to query:
119 if no argument is supplied, C<$_> is used. The numeric constants
120 appropriate to be used as arguments are exportable from I18N::Langinfo.
122 The following example will import the langinfo() function itself and
123 three constants to be used as arguments to langinfo(): a constant for
124 the abbreviated first day of the week (the numbering starts from
125 Sunday = 1) and two more constants for the affirmative and negative
126 answers for a yes/no question in the current locale.
128 use I18N::Langinfo qw(langinfo ABDAY_1 YESSTR NOSTR);
130 my ($abday_1, $yesstr, $nostr) = map { langinfo } qw(ABDAY_1 YESSTR NOSTR);
132 print "$abday_1? [$yesstr/$nostr] ";
134 In other words, in the "C" (or English) locale the above will probably
135 print something like:
139 but under a French locale
143 The usually available constants are
145 ABDAY_1 ABDAY_2 ABDAY_3 ABDAY_4 ABDAY_5 ABDAY_6 ABDAY_7
146 ABMON_1 ABMON_2 ABMON_3 ABMON_4 ABMON_5 ABMON_6
147 ABMON_7 ABMON_8 ABMON_9 ABMON_10 ABMON_11 ABMON_12
148 DAY_1 DAY_2 DAY_3 DAY_4 DAY_5 DAY_6 DAY_7
149 MON_1 MON_2 MON_3 MON_4 MON_5 MON_6
150 MON_7 MON_8 MON_9 MON_10 MON_11 MON_12
152 for abbreviated and full length days of the week and months of the year,
156 for the date-time, date, and time formats used by the strftime() function
159 AM_STR PM_STR T_FMT_AMPM
161 for the locales for which it makes sense to have ante meridiem and post
162 meridiem time formats,
164 CODESET CRNCYSTR RADIXCHAR
166 for the character code set being used (such as "ISO8859-1", "cp850",
167 "koi8-r", "sjis", "utf8", etc.), for the currency string, for the
168 radix character used between the integer and the fractional part
169 of decimal numbers (yes, this is redundant with POSIX::localeconv())
171 YESSTR YESEXPR NOSTR NOEXPR
173 for the affirmative and negative responses and expressions, and
175 ERA ERA_D_FMT ERA_D_T_FMT ERA_T_FMT
177 for the Japanese Emperor eras (naturally only defined under Japanese locales).
179 See your L<langinfo(3)> for more information about the available
180 constants. (Often this means having to look directly at the
181 F<langinfo.h> C header file.)
183 Note that unfortunately none of the above constants are guaranteed
184 to be available on a particular platform. To be on the safe side
185 you can wrap the import in an eval like this:
188 require I18N::Langinfo;
189 I18N::Langinfo->import(qw(langinfo CODESET));
190 $codeset = langinfo(CODESET()); # note the ()
192 if (!$@) { ... failed ... }
196 Nothing is exported by default.
200 L<perllocale>, L<POSIX/localeconv>, L<POSIX/setlocale>, L<nl_langinfo(3)>.
202 The langinfo() is just a wrapper for the C nl_langinfo() interface.
206 Jarkko Hietaniemi, E<lt>jhi@hut.fiE<gt>
208 =head1 COPYRIGHT AND LICENSE
210 Copyright 2001 by Jarkko Hietaniemi
212 This library is free software; you can redistribute it and/or modify
213 it under the same terms as Perl itself.