Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | package I18N::Langinfo; |
2 | ||
3 | use 5.006; | |
4 | use strict; | |
5 | use warnings; | |
6 | use Carp; | |
7 | ||
8 | require Exporter; | |
9 | require DynaLoader; | |
10 | use AutoLoader; | |
11 | ||
12 | our @ISA = qw(Exporter DynaLoader); | |
13 | ||
14 | our @EXPORT = qw(langinfo); | |
15 | ||
16 | our @EXPORT_OK = qw( | |
17 | ABDAY_1 | |
18 | ABDAY_2 | |
19 | ABDAY_3 | |
20 | ABDAY_4 | |
21 | ABDAY_5 | |
22 | ABDAY_6 | |
23 | ABDAY_7 | |
24 | ABMON_1 | |
25 | ABMON_10 | |
26 | ABMON_11 | |
27 | ABMON_12 | |
28 | ABMON_2 | |
29 | ABMON_3 | |
30 | ABMON_4 | |
31 | ABMON_5 | |
32 | ABMON_6 | |
33 | ABMON_7 | |
34 | ABMON_8 | |
35 | ABMON_9 | |
36 | ALT_DIGITS | |
37 | AM_STR | |
38 | CODESET | |
39 | CRNCYSTR | |
40 | DAY_1 | |
41 | DAY_2 | |
42 | DAY_3 | |
43 | DAY_4 | |
44 | DAY_5 | |
45 | DAY_6 | |
46 | DAY_7 | |
47 | D_FMT | |
48 | D_T_FMT | |
49 | ERA | |
50 | ERA_D_FMT | |
51 | ERA_D_T_FMT | |
52 | ERA_T_FMT | |
53 | MON_1 | |
54 | MON_10 | |
55 | MON_11 | |
56 | MON_12 | |
57 | MON_2 | |
58 | MON_3 | |
59 | MON_4 | |
60 | MON_5 | |
61 | MON_6 | |
62 | MON_7 | |
63 | MON_8 | |
64 | MON_9 | |
65 | NOEXPR | |
66 | NOSTR | |
67 | PM_STR | |
68 | RADIXCHAR | |
69 | THOUSEP | |
70 | T_FMT | |
71 | T_FMT_AMPM | |
72 | YESEXPR | |
73 | YESSTR | |
74 | ); | |
75 | ||
76 | our $VERSION = '0.02'; | |
77 | ||
78 | sub AUTOLOAD { | |
79 | # This AUTOLOAD is used to 'autoload' constants from the constant() | |
80 | # XS function. | |
81 | ||
82 | my $constname; | |
83 | our $AUTOLOAD; | |
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; } | |
88 | { | |
89 | no strict 'refs'; | |
90 | # Fixed between 5.005_53 and 5.005_61 | |
91 | #XXX if ($] >= 5.00561) { | |
92 | #XXX *$AUTOLOAD = sub () { $val }; | |
93 | #XXX } | |
94 | #XXX else { | |
95 | *$AUTOLOAD = sub { $val }; | |
96 | #XXX } | |
97 | } | |
98 | goto &$AUTOLOAD; | |
99 | } | |
100 | ||
101 | bootstrap I18N::Langinfo $VERSION; | |
102 | ||
103 | 1; | |
104 | __END__ | |
105 | ||
106 | =head1 NAME | |
107 | ||
108 | I18N::Langinfo - query locale information | |
109 | ||
110 | =head1 SYNOPSIS | |
111 | ||
112 | use I18N::Langinfo; | |
113 | ||
114 | =head1 DESCRIPTION | |
115 | ||
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. | |
121 | ||
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. | |
127 | ||
128 | use I18N::Langinfo qw(langinfo ABDAY_1 YESSTR NOSTR); | |
129 | ||
130 | my ($abday_1, $yesstr, $nostr) = map { langinfo } qw(ABDAY_1 YESSTR NOSTR); | |
131 | ||
132 | print "$abday_1? [$yesstr/$nostr] "; | |
133 | ||
134 | In other words, in the "C" (or English) locale the above will probably | |
135 | print something like: | |
136 | ||
137 | Sun? [yes/no] | |
138 | ||
139 | but under a French locale | |
140 | ||
141 | dim? [oui/non] | |
142 | ||
143 | The usually available constants are | |
144 | ||
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 | |
151 | ||
152 | for abbreviated and full length days of the week and months of the year, | |
153 | ||
154 | D_T_FMT D_FMT T_FMT | |
155 | ||
156 | for the date-time, date, and time formats used by the strftime() function | |
157 | (see L<POSIX>) | |
158 | ||
159 | AM_STR PM_STR T_FMT_AMPM | |
160 | ||
161 | for the locales for which it makes sense to have ante meridiem and post | |
162 | meridiem time formats, | |
163 | ||
164 | CODESET CRNCYSTR RADIXCHAR | |
165 | ||
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()) | |
170 | ||
171 | YESSTR YESEXPR NOSTR NOEXPR | |
172 | ||
173 | for the affirmative and negative responses and expressions, and | |
174 | ||
175 | ERA ERA_D_FMT ERA_D_T_FMT ERA_T_FMT | |
176 | ||
177 | for the Japanese Emperor eras (naturally only defined under Japanese locales). | |
178 | ||
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.) | |
182 | ||
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: | |
186 | ||
187 | eval { | |
188 | require I18N::Langinfo; | |
189 | I18N::Langinfo->import(qw(langinfo CODESET)); | |
190 | $codeset = langinfo(CODESET()); # note the () | |
191 | }; | |
192 | if (!$@) { ... failed ... } | |
193 | ||
194 | =head2 EXPORT | |
195 | ||
196 | Nothing is exported by default. | |
197 | ||
198 | =head1 SEE ALSO | |
199 | ||
200 | L<perllocale>, L<POSIX/localeconv>, L<POSIX/setlocale>, L<nl_langinfo(3)>. | |
201 | ||
202 | The langinfo() is just a wrapper for the C nl_langinfo() interface. | |
203 | ||
204 | =head1 AUTHOR | |
205 | ||
206 | Jarkko Hietaniemi, E<lt>jhi@hut.fiE<gt> | |
207 | ||
208 | =head1 COPYRIGHT AND LICENSE | |
209 | ||
210 | Copyright 2001 by Jarkko Hietaniemi | |
211 | ||
212 | This library is free software; you can redistribute it and/or modify | |
213 | it under the same terms as Perl itself. | |
214 | ||
215 | =cut |