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 Starting in Perl 5.28, this module is available even on systems that
89 lack a native "nl_langinfo". On such systems, it uses various methods
90 to construct what that function, if present, would return. But there
91 are potential glitches. These are the items that could be different:
92
93 "ERA"
94 Unimplemented, so returns "".
95
96 "CODESET"
97 Unimplemented, except on Windows, due to the vagaries of vendor
98 locale names, returning "" on non-Windows.
99
100 "YESEXPR"
101 "YESSTR"
102 "NOEXPR"
103 "NOSTR"
104 Only the values for English are returned. "YESSTR" and "NOSTR"
105 have been removed from POSIX 2008, and are retained here for
106 backwards compatibility. Your platform's "nl_langinfo" may not
107 support them.
108
109 "D_FMT"
110 Always evaluates to %x, the locale's appropriate date
111 representation.
112
113 "T_FMT"
114 Always evaluates to %X, the locale's appropriate time
115 representation.
116
117 "D_T_FMT"
118 Always evaluates to %c, the locale's appropriate date and time
119 representation.
120
121 "CRNCYSTR"
122 The return may be incorrect for those rare locales where the
123 currency symbol replaces the radix character. If you have examples
124 of it needing to work differently, please file a report at
125 <https://github.com/Perl/perl5/issues>.
126
127 "ALT_DIGITS"
128 Currently this gives the same results as Linux does. If you have
129 examples of it needing to work differently, please file a report at
130 <https://github.com/Perl/perl5/issues>.
131
132 "ERA_D_FMT"
133 "ERA_T_FMT"
134 "ERA_D_T_FMT"
135 "T_FMT_AMPM"
136 These are derived by using "strftime()", and not all versions of
137 that function know about them. "" is returned for these on such
138 systems.
139
140 See your nl_langinfo(3) for more information about the available
141 constants. (Often this means having to look directly at the langinfo.h
142 C header file.)
143
144 EXPORT
145 By default only the "langinfo()" function is exported.
146
148 Before Perl 5.28, the returned values are unreliable for the
149 "RADIXCHAR" and "THOUSEP" locale constants.
150
151 Starting in 5.28, changing locales on threaded builds is supported on
152 systems that offer thread-safe locale functions. These include POSIX
153 2008 systems and Windows starting with Visual Studio 2005, and this
154 module will work properly in such situations. However, on threaded
155 builds on Windows prior to Visual Studio 2015, retrieving the items
156 "CRNCYSTR" and "THOUSEP" can result in a race with a thread that has
157 converted to use the global locale. It is quite uncommon for a thread
158 to have done this. It would be possible to construct a workaround for
159 this; patches welcome: see "switch_to_global_locale" in perlapi.
160
162 perllocale, "localeconv" in POSIX, "setlocale" in POSIX,
163 nl_langinfo(3).
164
165 The langinfo() function is just a wrapper for the C nl_langinfo()
166 interface.
167
169 Jarkko Hietaniemi, <jhi@hut.fi>. Now maintained by Perl 5 porters.
170
172 Copyright 2001 by Jarkko Hietaniemi
173
174 This library is free software; you can redistribute it and/or modify it
175 under the same terms as Perl itself.
176
177
178
179perl v5.36.0 2022-08-30 I18N::Langinfo(3pm)