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