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