1package I18N::Langinfo;
2
3use 5.006;
4use strict;
5use warnings;
6use Carp;
7
8require Exporter;
9require XSLoader;
10
11our @ISA = qw(Exporter);
12
13our @EXPORT = qw(langinfo);
14
15our @EXPORT_OK = qw(
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
75our $VERSION = '0.19';
76
77XSLoader::load();
78
791;
80__END__
81
82=head1 NAME
83
84I18N::Langinfo - query locale information
85
86=head1 SYNOPSIS
87
88  use I18N::Langinfo;
89
90=head1 DESCRIPTION
91
92The langinfo() function queries various locale information that can be
93used to localize output and user interfaces.  It uses the current underlying
94locale, regardless of whether or not it was called from within the scope of
95S<C<use locale>>.  The langinfo() function requires
96one numeric argument that identifies the locale constant to query:
97if no argument is supplied, C<$_> is used.  The numeric constants
98appropriate to be used as arguments are exportable from I18N::Langinfo.
99
100The following example will import the langinfo() function itself and
101three constants to be used as arguments to langinfo(): a constant for
102the abbreviated first day of the week (the numbering starts from
103Sunday = 1) and two more constants for the affirmative and negative
104answers for a yes/no question in the current locale.
105
106    use I18N::Langinfo qw(langinfo ABDAY_1 YESSTR NOSTR);
107
108    my ($abday_1, $yesstr, $nostr) =
109        map { langinfo($_) } (ABDAY_1, YESSTR, NOSTR);
110
111    print "$abday_1? [$yesstr/$nostr] ";
112
113In other words, in the "C" (or English) locale the above will probably
114print something like:
115
116    Sun? [yes/no]
117
118but under a French locale
119
120    dim? [oui/non]
121
122The usually available constants are as follows.
123
124=over 4
125
126=item *
127
128For abbreviated and full length days of the week and months of the year:
129
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
136
137=item *
138
139For the date-time, date, and time formats used by the strftime() function
140(see L<POSIX>):
141
142    D_T_FMT D_FMT T_FMT
143
144=item *
145
146For the locales for which it makes sense to have ante meridiem and post
147meridiem time formats:
148
149    AM_STR PM_STR T_FMT_AMPM
150
151=item *
152
153For the character code set being used (such as "ISO8859-1", "cp850",
154"koi8-r", "sjis", "utf8", etc.), and for the currency string:
155
156    CODESET CRNCYSTR
157
158=item *
159
160For an alternate representation of digits, for the
161radix character used between the integer and the fractional part
162of decimal numbers, the group separator string for large-ish floating point
163numbers (yes, the final two are redundant with
164L<POSIX::localeconv()|POSIX/localeconv>):
165
166    ALT_DIGITS RADIXCHAR THOUSEP
167
168=item *
169
170For the affirmative and negative responses and expressions:
171
172    YESSTR YESEXPR NOSTR NOEXPR
173
174=item *
175
176For the eras based on typically some ruler, such as the Japanese Emperor
177(naturally only defined in the appropriate locales):
178
179    ERA ERA_D_FMT ERA_D_T_FMT ERA_T_FMT
180
181=back
182
183=head2 For systems without C<nl_langinfo>
184
185Starting in Perl 5.28, this module is available even on systems that lack a
186native C<nl_langinfo>.  On such systems, it uses various methods to construct
187what that function, if present, would return.  But there are potential
188glitches.  These are the items that could be different:
189
190=over
191
192=item C<ERA>
193
194Unimplemented, so returns C<"">.
195
196=item C<CODESET>
197
198Unimplemented, except on Windows, due to the vagaries of vendor locale names,
199returning C<""> on non-Windows.
200
201=item C<YESEXPR>
202
203=item C<YESSTR>
204
205=item C<NOEXPR>
206
207=item C<NOSTR>
208
209Only the values for English are returned.  C<YESSTR> and C<NOSTR> have been
210removed from POSIX 2008, and are retained here for backwards compatibility.
211Your platform's C<nl_langinfo> may not support them.
212
213=item C<D_FMT>
214
215Always evaluates to C<%x>, the locale's appropriate date representation.
216
217=item C<T_FMT>
218
219Always evaluates to C<%X>, the locale's appropriate time representation.
220
221=item C<D_T_FMT>
222
223Always evaluates to C<%c>, the locale's appropriate date and time
224representation.
225
226=item C<CRNCYSTR>
227
228The return may be incorrect for those rare locales where the currency symbol
229replaces the radix character.
230Send email to L<mailto:perlbug@perl.org> if you have examples of it needing
231to work differently.
232
233=item C<ALT_DIGITS>
234
235Currently this gives the same results as Linux does.
236Send email to L<mailto:perlbug@perl.org> if you have examples of it needing
237to work differently.
238
239=item C<ERA_D_FMT>
240
241=item C<ERA_T_FMT>
242
243=item C<ERA_D_T_FMT>
244
245=item C<T_FMT_AMPM>
246
247These are derived by using C<strftime()>, and not all versions of that function
248know about them.  C<""> is returned for these on such systems.
249
250=back
251
252See your L<nl_langinfo(3)> for more information about the available
253constants.  (Often this means having to look directly at the
254F<langinfo.h> C header file.)
255
256=head2 EXPORT
257
258By default only the C<langinfo()> function is exported.
259
260=head1 BUGS
261
262Before Perl 5.28, the returned values are unreliable for the C<RADIXCHAR> and
263C<THOUSEP> locale constants.
264
265Starting in 5.28, changing locales on threaded builds is supported on systems
266that offer thread-safe locale functions.  These include POSIX 2008 systems and
267Windows starting with Visual Studio 2005, and this module will work properly
268in such situations.  However, on threaded builds on Windows prior to Visual
269Studio 2015, retrieving the items C<CRNCYSTR> and C<THOUSEP> can result in a
270race with a thread that has converted to use the global locale.  It is quite
271uncommon for a thread to have done this.  It would be possible to construct a
272workaround for this; patches welcome: see L<perlapi/switch_to_global_locale>.
273
274=head1 SEE ALSO
275
276L<perllocale>, L<POSIX/localeconv>, L<POSIX/setlocale>, L<nl_langinfo(3)>.
277
278The langinfo() function is just a wrapper for the C nl_langinfo() interface.
279
280=head1 AUTHOR
281
282Jarkko Hietaniemi, E<lt>jhi@hut.fiE<gt>.  Now maintained by Perl 5 porters.
283
284=head1 COPYRIGHT AND LICENSE
285
286Copyright 2001 by Jarkko Hietaniemi
287
288This library is free software; you can redistribute it and/or modify
289it under the same terms as Perl itself.
290
291=cut
292