1I18N::Langinfo(3pm) Perl Programmers Reference Guide I18N::Langinfo(3pm)
2
3
4
6 I18N::Langinfo - query locale information
7
9 use I18N::Langinfo;
10
12 The langinfo() function queries various locale information that can be
13 used to localize output and user interfaces. It uses the current
14 underlying locale, regardless of whether or not it was called from
15 within the scope of "use locale". The langinfo() function requires one
16 numeric argument that identifies the locale constant to query: if no
17 argument is supplied, $_ is used. The numeric constants appropriate to
18 be used as arguments are exportable from I18N::Langinfo.
19
20 The following example will import the langinfo() function itself and
21 three constants to be used as arguments to langinfo(): a constant for
22 the abbreviated first day of the week (the numbering starts from Sunday
23 = 1) and two more constants for the affirmative and negative answers
24 for a yes/no question in the current locale.
25
26 use I18N::Langinfo qw(langinfo ABDAY_1 YESSTR NOSTR);
27
28 my ($abday_1, $yesstr, $nostr) =
29 map { langinfo($_) } (ABDAY_1, YESSTR, NOSTR);
30
31 print "$abday_1? [$yesstr/$nostr] ";
32
33 In other words, in the "C" (or English) locale the above will probably
34 print something like:
35
36 Sun? [yes/no]
37
38 but under a French locale
39
40 dim? [oui/non]
41
42 The usually available constants are as follows.
43
44 • For abbreviated and full length days of the week and months of the
45 year:
46
47 ABDAY_1 ABDAY_2 ABDAY_3 ABDAY_4 ABDAY_5 ABDAY_6 ABDAY_7
48 ABMON_1 ABMON_2 ABMON_3 ABMON_4 ABMON_5 ABMON_6
49 ABMON_7 ABMON_8 ABMON_9 ABMON_10 ABMON_11 ABMON_12
50 DAY_1 DAY_2 DAY_3 DAY_4 DAY_5 DAY_6 DAY_7
51 MON_1 MON_2 MON_3 MON_4 MON_5 MON_6
52 MON_7 MON_8 MON_9 MON_10 MON_11 MON_12
53
54 • For the date-time, date, and time formats used by the strftime()
55 function (see POSIX):
56
57 D_T_FMT D_FMT T_FMT
58
59 • For the locales for which it makes sense to have ante meridiem and
60 post meridiem time formats:
61
62 AM_STR PM_STR T_FMT_AMPM
63
64 • For the character code set being used (such as "ISO8859-1",
65 "cp850", "koi8-r", "sjis", "utf8", etc.), and for the currency
66 string:
67
68 CODESET CRNCYSTR
69
70 • For an alternate representation of digits, for the radix character
71 used between the integer and the fractional part of decimal
72 numbers, the group separator string for large-ish floating point
73 numbers (yes, the final two are redundant with
74 POSIX::localeconv()):
75
76 ALT_DIGITS RADIXCHAR THOUSEP
77
78 • For the affirmative and negative responses and expressions:
79
80 YESSTR YESEXPR NOSTR NOEXPR
81
82 • For the eras based on typically some ruler, such as the Japanese
83 Emperor (naturally only defined in the appropriate locales):
84
85 ERA ERA_D_FMT ERA_D_T_FMT ERA_T_FMT
86
87 For systems without "nl_langinfo"
88 This module originally was just a wrapper for the libc "nl_langinfo"
89 function, and did not work on systems lacking it, such as Windows.
90
91 Starting in Perl 5.28, this module works on all platforms. When
92 "nl_langinfo" is not available, it uses various methods to construct
93 what that function, if present, would return. But there are potential
94 glitches. These are the items that could be different:
95
96 "ERA"
97 Unimplemented, so returns "".
98
99 "CODESET"
100 This should work properly for Windows platforms. On almost all
101 other modern platforms, it will reliably return "UTF-8" if that is
102 the code set. Otherwise, it depends on the locale's name. If that
103 is of the form "foo.bar", it will assume "bar" is the code set; and
104 it also knows about the two locales "C" and "POSIX". If none of
105 those apply it returns "".
106
107 "YESEXPR"
108 "YESSTR"
109 "NOEXPR"
110 "NOSTR"
111 Only the values for English are returned. "YESSTR" and "NOSTR"
112 have been removed from POSIX 2008, and are retained here for
113 backwards compatibility. Your platform's "nl_langinfo" may not
114 support them.
115
116 "D_FMT"
117 Always evaluates to %x, the locale's appropriate date
118 representation.
119
120 "T_FMT"
121 Always evaluates to %X, the locale's appropriate time
122 representation.
123
124 "D_T_FMT"
125 Always evaluates to %c, the locale's appropriate date and time
126 representation.
127
128 "CRNCYSTR"
129 The return may be incorrect for those rare locales where the
130 currency symbol replaces the radix character. If you have examples
131 of it needing to work differently, please file a report at
132 <https://github.com/Perl/perl5/issues>.
133
134 "ALT_DIGITS"
135 Currently this gives the same results as Linux does. If you have
136 examples of it needing to work differently, please file a report at
137 <https://github.com/Perl/perl5/issues>.
138
139 "ERA_D_FMT"
140 "ERA_T_FMT"
141 "ERA_D_T_FMT"
142 "T_FMT_AMPM"
143 These are derived by using strftime(), and not all versions of that
144 function know about them. "" is returned for these on such
145 systems.
146
147 See your nl_langinfo(3) for more information about the available
148 constants. (Often this means having to look directly at the langinfo.h
149 C header file.)
150
151 EXPORT
152 By default only the langinfo() function is exported.
153
155 Before Perl 5.28, the returned values are unreliable for the
156 "RADIXCHAR" and "THOUSEP" locale constants.
157
158 Starting in 5.28, changing locales on threaded builds is supported on
159 systems that offer thread-safe locale functions. These include POSIX
160 2008 systems and Windows starting with Visual Studio 2005, and this
161 module will work properly in such situations. However, on threaded
162 builds on Windows prior to Visual Studio 2015, retrieving the items
163 "CRNCYSTR" and "THOUSEP" can result in a race with a thread that has
164 converted to use the global locale. It is quite uncommon for a thread
165 to have done this. It would be possible to construct a workaround for
166 this; patches welcome: see "switch_to_global_locale" in perlapi.
167
169 perllocale, "localeconv" in POSIX, "setlocale" in POSIX,
170 nl_langinfo(3).
171
173 Jarkko Hietaniemi, <jhi@hut.fi>. Now maintained by Perl 5 porters.
174
176 Copyright 2001 by Jarkko Hietaniemi
177
178 This library is free software; you can redistribute it and/or modify it
179 under the same terms as Perl itself.
180
181
182
183perl v5.38.2 2023-11-30 I18N::Langinfo(3pm)