Commit | Line | Data |
---|---|---|
4bbcc6e8 JH |
1 | package I18N::Langinfo; |
2 | ||
3 | use 5.006; | |
4 | use strict; | |
5 | use warnings; | |
6 | use Carp; | |
7 | ||
8 | require Exporter; | |
568e2140 | 9 | require XSLoader; |
4bbcc6e8 | 10 | |
568e2140 | 11 | our @ISA = qw(Exporter); |
4bbcc6e8 | 12 | |
74c76037 JH |
13 | our @EXPORT = qw(langinfo); |
14 | ||
4bbcc6e8 | 15 | our @EXPORT_OK = qw( |
4bbcc6e8 JH |
16 | ABDAY_1 |
17 | ABDAY_2 | |
18 | ABDAY_3 | |
19 | ABDAY_4 | |
20 | ABDAY_5 | |
21 | ABDAY_6 | |
22 | ABDAY_7 | |
23 | ABMON_1 | |
24 | ABMON_10 | |
25 | ABMON_11 | |
26 | ABMON_12 | |
27 | ABMON_2 | |
28 | ABMON_3 | |
29 | ABMON_4 | |
30 | ABMON_5 | |
31 | ABMON_6 | |
32 | ABMON_7 | |
33 | ABMON_8 | |
34 | ABMON_9 | |
35 | ALT_DIGITS | |
36 | AM_STR | |
37 | CODESET | |
38 | CRNCYSTR | |
39 | DAY_1 | |
40 | DAY_2 | |
41 | DAY_3 | |
42 | DAY_4 | |
43 | DAY_5 | |
44 | DAY_6 | |
45 | DAY_7 | |
46 | D_FMT | |
47 | D_T_FMT | |
48 | ERA | |
49 | ERA_D_FMT | |
50 | ERA_D_T_FMT | |
51 | ERA_T_FMT | |
52 | MON_1 | |
53 | MON_10 | |
54 | MON_11 | |
55 | MON_12 | |
56 | MON_2 | |
57 | MON_3 | |
58 | MON_4 | |
59 | MON_5 | |
60 | MON_6 | |
61 | MON_7 | |
62 | MON_8 | |
63 | MON_9 | |
64 | NOEXPR | |
65 | NOSTR | |
66 | PM_STR | |
67 | RADIXCHAR | |
68 | THOUSEP | |
69 | T_FMT | |
70 | T_FMT_AMPM | |
71 | YESEXPR | |
72 | YESSTR | |
73 | ); | |
74 | ||
5e298965 | 75 | our $VERSION = '0.08_02'; |
4bbcc6e8 | 76 | |
568e2140 | 77 | XSLoader::load(); |
4bbcc6e8 JH |
78 | |
79 | 1; | |
80 | __END__ | |
81 | ||
82 | =head1 NAME | |
83 | ||
84 | I18N::Langinfo - query locale information | |
85 | ||
86 | =head1 SYNOPSIS | |
87 | ||
88 | use I18N::Langinfo; | |
89 | ||
90 | =head1 DESCRIPTION | |
91 | ||
74c76037 JH |
92 | The langinfo() function queries various locale information that can be |
93 | used to localize output and user interfaces. The langinfo() requires | |
94 | one numeric argument that identifies the locale constant to query: | |
95 | if no argument is supplied, C<$_> is used. The numeric constants | |
96 | appropriate to be used as arguments are exportable from I18N::Langinfo. | |
4bbcc6e8 | 97 | |
74c76037 JH |
98 | The following example will import the langinfo() function itself and |
99 | three constants to be used as arguments to langinfo(): a constant for | |
100 | the abbreviated first day of the week (the numbering starts from | |
101 | Sunday = 1) and two more constants for the affirmative and negative | |
102 | answers for a yes/no question in the current locale. | |
4bbcc6e8 JH |
103 | |
104 | use I18N::Langinfo qw(langinfo ABDAY_1 YESSTR NOSTR); | |
105 | ||
106 | my ($abday_1, $yesstr, $nostr) = map { langinfo } qw(ABDAY_1 YESSTR NOSTR); | |
107 | ||
108 | print "$abday_1? [$yesstr/$nostr] "; | |
109 | ||
74c76037 JH |
110 | In other words, in the "C" (or English) locale the above will probably |
111 | print something like: | |
4bbcc6e8 | 112 | |
74c76037 | 113 | Sun? [yes/no] |
4bbcc6e8 | 114 | |
b5a1df5a JH |
115 | but under a French locale |
116 | ||
117 | dim? [oui/non] | |
118 | ||
4bbcc6e8 JH |
119 | The usually available constants are |
120 | ||
121 | ABDAY_1 ABDAY_2 ABDAY_3 ABDAY_4 ABDAY_5 ABDAY_6 ABDAY_7 | |
122 | ABMON_1 ABMON_2 ABMON_3 ABMON_4 ABMON_5 ABMON_6 | |
123 | ABMON_7 ABMON_8 ABMON_9 ABMON_10 ABMON_11 ABMON_12 | |
124 | DAY_1 DAY_2 DAY_3 DAY_4 DAY_5 DAY_6 DAY_7 | |
125 | MON_1 MON_2 MON_3 MON_4 MON_5 MON_6 | |
126 | MON_7 MON_8 MON_9 MON_10 MON_11 MON_12 | |
127 | ||
128 | for abbreviated and full length days of the week and months of the year, | |
129 | ||
130 | D_T_FMT D_FMT T_FMT | |
131 | ||
132 | for the date-time, date, and time formats used by the strftime() function | |
b5a1df5a | 133 | (see L<POSIX>) |
4bbcc6e8 JH |
134 | |
135 | AM_STR PM_STR T_FMT_AMPM | |
136 | ||
137 | for the locales for which it makes sense to have ante meridiem and post | |
138 | meridiem time formats, | |
139 | ||
140 | CODESET CRNCYSTR RADIXCHAR | |
141 | ||
142 | for the character code set being used (such as "ISO8859-1", "cp850", | |
143 | "koi8-r", "sjis", "utf8", etc.), for the currency string, for the | |
758f564b JH |
144 | radix character used between the integer and the fractional part |
145 | of decimal numbers (yes, this is redundant with POSIX::localeconv()) | |
4bbcc6e8 JH |
146 | |
147 | YESSTR YESEXPR NOSTR NOEXPR | |
148 | ||
149 | for the affirmative and negative responses and expressions, and | |
150 | ||
74c76037 | 151 | ERA ERA_D_FMT ERA_D_T_FMT ERA_T_FMT |
4bbcc6e8 JH |
152 | |
153 | for the Japanese Emperor eras (naturally only defined under Japanese locales). | |
154 | ||
155 | See your L<langinfo(3)> for more information about the available | |
156 | constants. (Often this means having to look directly at the | |
157 | F<langinfo.h> C header file.) | |
158 | ||
758f564b JH |
159 | Note that unfortunately none of the above constants are guaranteed |
160 | to be available on a particular platform. To be on the safe side | |
161 | you can wrap the import in an eval like this: | |
162 | ||
163 | eval { | |
164 | require I18N::Langinfo; | |
165 | I18N::Langinfo->import(qw(langinfo CODESET)); | |
166 | $codeset = langinfo(CODESET()); # note the () | |
167 | }; | |
168 | if (!$@) { ... failed ... } | |
169 | ||
4bbcc6e8 JH |
170 | =head2 EXPORT |
171 | ||
c893053f | 172 | By default only the C<langinfo()> function is exported. |
4bbcc6e8 JH |
173 | |
174 | =head1 SEE ALSO | |
175 | ||
176 | L<perllocale>, L<POSIX/localeconv>, L<POSIX/setlocale>, L<nl_langinfo(3)>. | |
177 | ||
178 | The langinfo() is just a wrapper for the C nl_langinfo() interface. | |
179 | ||
180 | =head1 AUTHOR | |
181 | ||
182 | Jarkko Hietaniemi, E<lt>jhi@hut.fiE<gt> | |
183 | ||
184 | =head1 COPYRIGHT AND LICENSE | |
185 | ||
186 | Copyright 2001 by Jarkko Hietaniemi | |
187 | ||
188 | This library is free software; you can redistribute it and/or modify | |
189 | it under the same terms as Perl itself. | |
190 | ||
191 | =cut |