1 |
|
2 |
=encoding euc-jp |
3 |
|
4 |
=head1 NAME |
5 |
|
6 |
=begin original |
7 |
|
8 |
perllocale - Perl locale handling (internationalization and localization) |
9 |
|
10 |
=end original |
11 |
|
12 |
perllocale - Perl のロケール操作 (国際化と地域化) |
13 |
|
14 |
=head1 DESCRIPTION |
15 |
|
16 |
=begin original |
17 |
|
18 |
In the beginning there was ASCII, the "American Standard Code for |
19 |
Information Interchange", which works quite well for Americans with |
20 |
their English alphabet and dollar-denominated currency. But it doesn't |
21 |
work so well even for other English speakers, who may use different |
22 |
currencies, such as the pound sterling (as the symbol for that currency |
23 |
is not in ASCII); and it's hopelessly inadequate for many of the |
24 |
thousands of the world's other languages. |
25 |
|
26 |
=end original |
27 |
|
28 |
In the beginning there was ASCII, the "American Standard Code for |
29 |
Information Interchange", which works quite well for Americans with |
30 |
their English alphabet and dollar-denominated currency. But it doesn't |
31 |
work so well even for other English speakers, who may use different |
32 |
currencies, such as the pound sterling (as the symbol for that currency |
33 |
is not in ASCII); and it's hopelessly inadequate for many of the |
34 |
thousands of the world's other languages. |
35 |
(TBT) |
36 |
|
37 |
=begin original |
38 |
|
39 |
To address these deficiencies, the concept of locales was invented |
40 |
(formally the ISO C, XPG4, POSIX 1.c "locale system"). And applications |
41 |
were and are being written that use the locale mechanism. The process of |
42 |
making such an application take account of its users' preferences in |
43 |
these kinds of matters is called B<internationalization> (often |
44 |
abbreviated as B<i18n>); telling such an application about a particular |
45 |
set of preferences is known as B<localization> (B<l10n>). |
46 |
|
47 |
=end original |
48 |
|
49 |
To address these deficiencies, the concept of locales was invented |
50 |
(formally the ISO C, XPG4, POSIX 1.c "locale system"). And applications |
51 |
were and are being written that use the locale mechanism. |
52 |
アプリケーションにそういったユーザーの選択を考慮させるためのプロセスは、 |
53 |
国際化(B<internationalization>)と呼ばれます(これはしばしば B<i18n> と |
54 |
省略されます); アプリケーションを特定の選択に対応させることは |
55 |
地域化(B<localization>、B<l10n>)として知られています。 |
56 |
(TBT) |
57 |
|
58 |
=begin original |
59 |
|
60 |
Perl was extended, starting in 5.004, to support the locale system. This |
61 |
is controlled per application by using one pragma, one function call, |
62 |
and several environment variables. |
63 |
|
64 |
=end original |
65 |
|
66 |
Perl was extended, starting in 5.004, to support the locale system. |
67 |
これは一つのプラグマ、一つの関数呼び出し、幾つかの |
68 |
環境変数を使って、アプリケーション毎に制御します。 |
69 |
(TBT) |
70 |
|
71 |
=begin original |
72 |
|
73 |
Unfortunately, there are quite a few deficiencies with the design (and |
74 |
often, the implementations) of locales, and their use for character sets |
75 |
has mostly been supplanted by Unicode (see L<perlunitut> for an |
76 |
introduction to that, and keep on reading here for how Unicode interacts |
77 |
with locales in Perl). |
78 |
|
79 |
=end original |
80 |
|
81 |
Unfortunately, there are quite a few deficiencies with the design (and |
82 |
often, the implementations) of locales, and their use for character sets |
83 |
has mostly been supplanted by Unicode (see L<perlunitut> for an |
84 |
introduction to that, and keep on reading here for how Unicode interacts |
85 |
with locales in Perl). |
86 |
(TBT) |
87 |
|
88 |
=begin original |
89 |
|
90 |
Perl continues to support the old locale system, and starting in v5.16, |
91 |
provides a hybrid way to use the Unicode character set, along with the |
92 |
other portions of locales that may not be so problematic. |
93 |
(Unicode is also creating C<CLDR>, the "Common Locale Data Repository", |
94 |
L<http://cldr.unicode.org/> which includes more types of information than |
95 |
are available in the POSIX locale system. At the time of this writing, |
96 |
there was no CPAN module that provides access to this XML-encoded data. |
97 |
However, many of its locales have the POSIX-only data extracted, and are |
98 |
available at L<http://unicode.org/Public/cldr/latest/>.) |
99 |
|
100 |
=end original |
101 |
|
102 |
Perl continues to support the old locale system, and starting in v5.16, |
103 |
provides a hybrid way to use the Unicode character set, along with the |
104 |
other portions of locales that may not be so problematic. |
105 |
(Unicode is also creating C<CLDR>, the "Common Locale Data Repository", |
106 |
L<http://cldr.unicode.org/> which includes more types of information than |
107 |
are available in the POSIX locale system. At the time of this writing, |
108 |
there was no CPAN module that provides access to this XML-encoded data. |
109 |
However, many of its locales have the POSIX-only data extracted, and are |
110 |
available at L<http://unicode.org/Public/cldr/latest/>.) |
111 |
(TBT) |
112 |
|
113 |
=head1 WHAT IS A LOCALE |
114 |
|
115 |
=begin original |
116 |
|
117 |
A locale is a set of data that describes various aspects of how various |
118 |
communities in the world categorize their world. These categories are |
119 |
broken down into the following types (some of which include a brief |
120 |
note here): |
121 |
|
122 |
=end original |
123 |
|
124 |
A locale is a set of data that describes various aspects of how various |
125 |
communities in the world categorize their world. These categories are |
126 |
broken down into the following types (some of which include a brief |
127 |
note here): |
128 |
(TBT) |
129 |
|
130 |
=over |
131 |
|
132 |
=item Category LC_NUMERIC: Numeric formatting |
133 |
|
134 |
=begin original |
135 |
|
136 |
This indicates how numbers should be formatted for human readability, |
137 |
for example the character used as the decimal point. |
138 |
|
139 |
=end original |
140 |
|
141 |
This indicates how numbers should be formatted for human readability, |
142 |
for example the character used as the decimal point. |
143 |
(TBT) |
144 |
|
145 |
=item Category LC_MONETARY: Formatting of monetary amounts |
146 |
|
147 |
=for comment |
148 |
The nbsp below makes this look better |
149 |
|
150 |
=begin original |
151 |
|
152 |
E<160> |
153 |
|
154 |
=end original |
155 |
|
156 |
E<160> |
157 |
(TBT) |
158 |
|
159 |
=item Category LC_TIME: Date/Time formatting |
160 |
|
161 |
=for comment |
162 |
The nbsp below makes this look better |
163 |
|
164 |
=begin original |
165 |
|
166 |
E<160> |
167 |
|
168 |
=end original |
169 |
|
170 |
E<160> |
171 |
(TBT) |
172 |
|
173 |
=item Category LC_MESSAGES: Error and other messages |
174 |
|
175 |
=begin original |
176 |
|
177 |
This for the most part is beyond the scope of Perl |
178 |
|
179 |
=end original |
180 |
|
181 |
This for the most part is beyond the scope of Perl |
182 |
(TBT) |
183 |
|
184 |
=item Category LC_COLLATE: Collation |
185 |
|
186 |
=begin original |
187 |
|
188 |
This indicates the ordering of letters for comparision and sorting. |
189 |
In Latin alphabets, for example, "b", generally follows "a". |
190 |
|
191 |
=end original |
192 |
|
193 |
This indicates the ordering of letters for comparision and sorting. |
194 |
In Latin alphabets, for example, "b", generally follows "a". |
195 |
(TBT) |
196 |
|
197 |
=item Category LC_CTYPE: Character Types |
198 |
|
199 |
=begin original |
200 |
|
201 |
This indicates, for example if a character is an uppercase letter. |
202 |
|
203 |
=end original |
204 |
|
205 |
This indicates, for example if a character is an uppercase letter. |
206 |
(TBT) |
207 |
|
208 |
=back |
209 |
|
210 |
=begin original |
211 |
|
212 |
More details on the categories are given below in L</LOCALE CATEGORIES>. |
213 |
|
214 |
=end original |
215 |
|
216 |
More details on the categories are given below in L</LOCALE CATEGORIES>. |
217 |
(TBT) |
218 |
|
219 |
=begin original |
220 |
|
221 |
Together, these categories go a long way towards being able to customize |
222 |
a single program to run in many different locations. But there are |
223 |
deficiencies, so keep reading. |
224 |
|
225 |
=end original |
226 |
|
227 |
Together, these categories go a long way towards being able to customize |
228 |
a single program to run in many different locations. But there are |
229 |
deficiencies, so keep reading. |
230 |
(TBT) |
231 |
|
232 |
=head1 PREPARING TO USE LOCALES |
233 |
|
234 |
(ロケールの使う前の準備) |
235 |
|
236 |
=begin original |
237 |
|
238 |
Perl will not use locales unless specifically requested to (see L</NOTES> below |
239 |
for the partial exception of C<write()>). But even if there is such a |
240 |
request, B<all> of the following must be true for it to work properly: |
241 |
|
242 |
=end original |
243 |
|
244 |
Perl は、特に要求されない限りロケールを使いません |
245 |
(see L</NOTES> below |
246 |
for the partial exception of C<write()>)。 |
247 |
しかしそのような要求があっても、正しく動作するには |
248 |
以下の B<すべて> が真になっていなければなりません: |
249 |
(TB) |
250 |
|
251 |
=over 4 |
252 |
|
253 |
=item * |
254 |
|
255 |
=begin original |
256 |
|
257 |
B<Your operating system must support the locale system>. If it does, |
258 |
you should find that the setlocale() function is a documented part of |
259 |
its C library. |
260 |
|
261 |
=end original |
262 |
|
263 |
B<あなたの使っているオペレーティングシステムがロケールシステムに |
264 |
対応していなければなりません>。 |
265 |
これに対応していれば、setlocale() という関数が C ライブラリの中に |
266 |
あるはずです。 |
267 |
|
268 |
=item * |
269 |
|
270 |
=begin original |
271 |
|
272 |
B<Definitions for locales that you use must be installed>. You, or |
273 |
your system administrator, must make sure that this is the case. The |
274 |
available locales, the location in which they are kept, and the manner |
275 |
in which they are installed all vary from system to system. Some systems |
276 |
provide only a few, hard-wired locales and do not allow more to be |
277 |
added. Others allow you to add "canned" locales provided by the system |
278 |
supplier. Still others allow you or the system administrator to define |
279 |
and add arbitrary locales. (You may have to ask your supplier to |
280 |
provide canned locales that are not delivered with your operating |
281 |
system.) Read your system documentation for further illumination. |
282 |
|
283 |
=end original |
284 |
|
285 |
B<あなたの使うロケールの定義がインストールされていなければなりません>。 |
286 |
あなた、もしくは管理者はこれを正しく取り扱わねばなりません。 |
287 |
使うことのできるロケール、それらが置かれている場所、インストールされる |
288 |
規則といったものシステム毎に変わります。 |
289 |
一部のシステムでは、固定のほんの少しのロケールだけを提供し、ユーザーが |
290 |
新たに追加することを許していません。 |
291 |
別のシステムでは、システムのサプライヤーが提供した「準備された」ロケールを |
292 |
追加することができます。 |
293 |
Still others allow you or the system administrator to define |
294 |
and add arbitrary locales. |
295 |
(あなたのサプライヤーに使っているオペレーティング |
296 |
システムと一緒に渡されていない準備されたロケールを提供するよう |
297 |
依頼する必要があります。) |
298 |
詳細はシステムのドキュメントを読んでください。 |
299 |
(TBT) |
300 |
|
301 |
=item * |
302 |
|
303 |
=begin original |
304 |
|
305 |
B<Perl must believe that the locale system is supported>. If it does, |
306 |
C<perl -V:d_setlocale> will say that the value for C<d_setlocale> is |
307 |
C<define>. |
308 |
|
309 |
=end original |
310 |
|
311 |
B<Perl が、ロケールシステムがサポートされていると信じていなければ |
312 |
なりません>。 |
313 |
もしそうなっていれば、C<perl -V:d_setlocale> は |
314 |
C<d_setlocale> の値が定義されているように報告するでしょう。 |
315 |
|
316 |
=back |
317 |
|
318 |
=begin original |
319 |
|
320 |
If you want a Perl application to process and present your data |
321 |
according to a particular locale, the application code should include |
322 |
the S<C<use locale>> pragma (see L<The use locale pragma>) where |
323 |
appropriate, and B<at least one> of the following must be true: |
324 |
|
325 |
=end original |
326 |
|
327 |
Perl アプリケーションをあなたの使うデータを特定のロケールで処理したり |
328 |
するようにしたいのであれば、そのアプリケーションコードはプラグマ |
329 |
S<C<use locale>> を適切な場所に、そして以下に挙げる項目の |
330 |
B<少なくとも一つ> が真でなければなりません。 |
331 |
|
332 |
=over 4 |
333 |
|
334 |
=item 1 |
335 |
|
336 |
=begin original |
337 |
|
338 |
B<The locale-determining environment variables (see L</"ENVIRONMENT">) |
339 |
must be correctly set up> at the time the application is started, either |
340 |
by yourself or by whomever set up your system account; or |
341 |
|
342 |
=end original |
343 |
|
344 |
あなた自身でやるにしろ、あなたの使うシステムの管理者がするにしろ、 |
345 |
アプリケーションの実行開始時には B<ロケールを決定する環境変数 |
346 |
(L</"ENVIRONMENT"> を参照)が正しく設定されていなければなりません>; |
347 |
または |
348 |
|
349 |
=item 2 |
350 |
|
351 |
=begin original |
352 |
|
353 |
B<The application must set its own locale> using the method described in |
354 |
L<The setlocale function>. |
355 |
|
356 |
=end original |
357 |
|
358 |
アプリケーションは、L<The setlocale function> に記述されている |
359 |
メソッドを使う、B<自分用のロケールを設定しておかねばなりません>。 |
360 |
|
361 |
=back |
362 |
|
363 |
=head1 USING LOCALES |
364 |
|
365 |
(ロケールを使う) |
366 |
|
367 |
=head2 The use locale pragma |
368 |
|
369 |
(use locale プラグマ) |
370 |
|
371 |
=begin original |
372 |
|
373 |
By default, Perl ignores the current locale. The S<C<use locale>> |
374 |
pragma tells Perl to use the current locale for some operations. |
375 |
Starting in v5.16, there is an optional parameter to this pragma: |
376 |
|
377 |
=end original |
378 |
|
379 |
デフォルトでは、Perl はカレントのロケールを無視します。 |
380 |
S<C<use locale>> プラグマは Perl に、幾つかの操作においてカレントのロケールを |
381 |
使うよう指示します。 |
382 |
Starting in v5.16, there is an optional parameter to this pragma: |
383 |
(TBT) |
384 |
|
385 |
use locale ':not_characters'; |
386 |
|
387 |
=begin original |
388 |
|
389 |
This parameter allows better mixing of locales and Unicode, and is |
390 |
described fully in L</Unicode and UTF-8>, but briefly, it tells Perl to |
391 |
not use the character portions of the locale definition, that is |
392 |
the C<LC_CTYPE> and C<LC_COLLATE> categories. Instead it will use the |
393 |
native (extended by Unicode) character set. When using this parameter, |
394 |
you are responsible for getting the external character set translated |
395 |
into the native/Unicode one (which it already will be if it is one of |
396 |
the increasingly popular UTF-8 locales). There are convenient ways of |
397 |
doing this, as described in L</Unicode and UTF-8>. |
398 |
|
399 |
=end original |
400 |
|
401 |
This parameter allows better mixing of locales and Unicode, and is |
402 |
described fully in L</Unicode and UTF-8>, but briefly, it tells Perl to |
403 |
not use the character portions of the locale definition, that is |
404 |
the C<LC_CTYPE> and C<LC_COLLATE> categories. Instead it will use the |
405 |
native (extended by Unicode) character set. When using this parameter, |
406 |
you are responsible for getting the external character set translated |
407 |
into the native/Unicode one (which it already will be if it is one of |
408 |
the increasingly popular UTF-8 locales). There are convenient ways of |
409 |
doing this, as described in L</Unicode and UTF-8>. |
410 |
(TBT) |
411 |
|
412 |
=begin original |
413 |
|
414 |
The current locale is set at execution time by |
415 |
L<setlocale()|/The setlocale function> described below. If that function |
416 |
hasn't yet been called in the course of the program's execution, the |
417 |
current locale is that which was determined by the L</"ENVIRONMENT"> in |
418 |
effect at the start of the program, except that |
419 |
C<L<LC_NUMERIC|/Category LC_NUMERIC: Numeric Formatting>> is always |
420 |
initialized to the C locale (mentioned under L<Finding locales>). |
421 |
If there is no valid environment, the current locale is undefined. It |
422 |
is likely, but not necessarily, the "C" locale. |
423 |
|
424 |
=end original |
425 |
|
426 |
現在のロケールは、後述する |
427 |
L<setlocale()|/The setlocale function> 関数によって実行時に設定されます。 |
428 |
プログラム実行の過程でこの関数がまだ呼び出されていないとき、現在の |
429 |
ロケールはプログラムの開始時に有効な L</"ENVIRONMENT"> によって |
430 |
決定されますが、 |
431 |
C<L<LC_NUMERIC|/Category LC_NUMERIC: Numeric Formatting>> は |
432 |
常に C ロケールに初期化されます (L<Finding locales> で言及しています)。 |
433 |
有効な環境がない場合、現在のロケールは未定義となります。 |
434 |
これは、おそらく "C" ロケールになりますが、かならずそうとは限りません。 |
435 |
|
436 |
=begin original |
437 |
|
438 |
The operations that are affected by locale are: |
439 |
|
440 |
=end original |
441 |
|
442 |
ロケールによって影響を受ける処理は: |
443 |
|
444 |
=over 4 |
445 |
|
446 |
=item B<Under C<use locale ':not_characters';>> |
447 |
|
448 |
=over 4 |
449 |
|
450 |
=item * |
451 |
|
452 |
=begin original |
453 |
|
454 |
B<Format declarations> (format()) use C<LC_NUMERIC> |
455 |
|
456 |
=end original |
457 |
|
458 |
B<書式宣言> (format()) は C<LC_NUMERIC> を使用します。 |
459 |
|
460 |
=item * |
461 |
|
462 |
=begin original |
463 |
|
464 |
B<The POSIX date formatting function> (strftime()) uses C<LC_TIME>. |
465 |
|
466 |
=end original |
467 |
|
468 |
B<POSIX の日付書式関数> (strfime()) は C<LC_TIME> を使用します。 |
469 |
|
470 |
=back |
471 |
|
472 |
=for comment |
473 |
The nbsp below makes this look better |
474 |
|
475 |
=begin original |
476 |
|
477 |
E<160> |
478 |
|
479 |
=end original |
480 |
|
481 |
E<160> |
482 |
(TBT) |
483 |
|
484 |
=item B<Under just plain C<use locale;>> |
485 |
|
486 |
=begin original |
487 |
|
488 |
The above operations are affected, as well as the following: |
489 |
|
490 |
=end original |
491 |
|
492 |
The above operations are affected, as well as the following: |
493 |
(TBT) |
494 |
|
495 |
=over 4 |
496 |
|
497 |
=item * |
498 |
|
499 |
=begin original |
500 |
|
501 |
B<The comparison operators> (C<lt>, C<le>, C<cmp>, C<ge>, and C<gt>) and |
502 |
the POSIX string collation functions strcoll() and strxfrm() use |
503 |
C<LC_COLLATE>. sort() is also affected if used without an |
504 |
explicit comparison function, because it uses C<cmp> by default. |
505 |
|
506 |
=end original |
507 |
|
508 |
B<比較演算子> (C<lt>, C<le>, C<cmp>, C<ge>, C<gt>) と、POSIX の文字列比較 |
509 |
関数 strcoll() および strxfrm() は C<LC_COLLATE> を使用します。 |
510 |
sort() は比較関数が陽に指定されなかった場合に影響を受けます; これは、 |
511 |
デフォルトでは C<cmp> を使うからです。 |
512 |
|
513 |
=begin original |
514 |
|
515 |
B<Note:> C<eq> and C<ne> are unaffected by locale: they always |
516 |
perform a char-by-char comparison of their scalar operands. What's |
517 |
more, if C<cmp> finds that its operands are equal according to the |
518 |
collation sequence specified by the current locale, it goes on to |
519 |
perform a char-by-char comparison, and only returns I<0> (equal) if the |
520 |
operands are char-for-char identical. If you really want to know whether |
521 |
two strings--which C<eq> and C<cmp> may consider different--are equal |
522 |
as far as collation in the locale is concerned, see the discussion in |
523 |
L<Category LC_COLLATE: Collation>. |
524 |
|
525 |
=end original |
526 |
|
527 |
B<注意:> C<eq> および C<ne> はロケールの影響を受けません: これらの関数は常に |
528 |
文字毎の比較をそのスカラオペランドに対して実行します。 |
529 |
それに加えて、C<cmp>はそのオペランドがカレントのロケールで |
530 |
指定される照合シーケンスで等しいものであった場合、さらに文字毎の |
531 |
照合を行おうします; そして、オペランドの全部の文字が等しい場合にのみ |
532 |
C<cmp> は I<0>(等しい)を返します。 |
533 |
C<eq> と C<cmp> が異なると判定する可能性のある二つの文字列がロケールを |
534 |
考慮した照合で等しいかどうかを本当に知りたいのなら、 |
535 |
L<Category LC_COLLATE: Collation> の記述を参照してください。 |
536 |
|
537 |
=item * |
538 |
|
539 |
=begin original |
540 |
|
541 |
B<Regular expressions and case-modification functions> (uc(), lc(), |
542 |
ucfirst(), and lcfirst()) use C<LC_CTYPE> |
543 |
|
544 |
=end original |
545 |
|
546 |
B<正規表現と大小文字変換関数> (uc(), lc(), ucfirst(), lcfirst()) は |
547 |
C<LC_CTYPE> を使用します。 |
548 |
|
549 |
=back |
550 |
|
551 |
=back |
552 |
|
553 |
=begin original |
554 |
|
555 |
The default behavior is restored with the S<C<no locale>> pragma, or |
556 |
upon reaching the end of the block enclosing C<use locale>. |
557 |
Note that C<use locale> and C<use locale ':not_characters'> may be |
558 |
nested, and that what is in effect within an inner scope will revert to |
559 |
the outer scope's rules at the end of the inner scope. |
560 |
|
561 |
=end original |
562 |
|
563 |
S<C<no locale>> に出会うか、(S<C<use locale>> を囲む)ブロックの終端に |
564 |
達するとデフォルトの動作に戻ります。 |
565 |
Note that C<use locale> and C<use locale ':not_characters'> may be |
566 |
nested, and that what is in effect within an inner scope will revert to |
567 |
the outer scope's rules at the end of the inner scope. |
568 |
(TBT) |
569 |
|
570 |
=begin original |
571 |
|
572 |
The string result of any operation that uses locale |
573 |
information is tainted, as it is possible for a locale to be |
574 |
untrustworthy. See L<"SECURITY">. |
575 |
|
576 |
=end original |
577 |
|
578 |
ロケール情報を使っている操作の結果である文字列は、ロケールが信頼できない |
579 |
可能性があるかのように、汚染されていることに注意してください。 |
580 |
L<"SECURITY"> を参照してください。 |
581 |
|
582 |
=head2 The setlocale function |
583 |
|
584 |
(setlocale 関数) |
585 |
|
586 |
=begin original |
587 |
|
588 |
You can switch locales as often as you wish at run time with the |
589 |
POSIX::setlocale() function: |
590 |
|
591 |
=end original |
592 |
|
593 |
POSIX::setlocale() 関数を使って、実行時に好きな回数だけロケールを |
594 |
切り替えることができます。 |
595 |
|
596 |
# This functionality not usable prior to Perl 5.004 |
597 |
require 5.004; |
598 |
|
599 |
# Import locale-handling tool set from POSIX module. |
600 |
# This example uses: setlocale -- the function call |
601 |
# LC_CTYPE -- explained below |
602 |
use POSIX qw(locale_h); |
603 |
|
604 |
# query and save the old locale |
605 |
$old_locale = setlocale(LC_CTYPE); |
606 |
|
607 |
setlocale(LC_CTYPE, "fr_CA.ISO8859-1"); |
608 |
# LC_CTYPE now in locale "French, Canada, codeset ISO 8859-1" |
609 |
|
610 |
setlocale(LC_CTYPE, ""); |
611 |
# LC_CTYPE now reset to default defined by LC_ALL/LC_CTYPE/LANG |
612 |
# environment variables. See below for documentation. |
613 |
|
614 |
# restore the old locale |
615 |
setlocale(LC_CTYPE, $old_locale); |
616 |
|
617 |
=begin original |
618 |
|
619 |
The first argument of setlocale() gives the B<category>, the second the |
620 |
B<locale>. The category tells in what aspect of data processing you |
621 |
want to apply locale-specific rules. Category names are discussed in |
622 |
L</LOCALE CATEGORIES> and L</"ENVIRONMENT">. The locale is the name of a |
623 |
collection of customization information corresponding to a particular |
624 |
combination of language, country or territory, and codeset. Read on for |
625 |
hints on the naming of locales: not all systems name locales as in the |
626 |
example. |
627 |
|
628 |
=end original |
629 |
|
630 |
setlocale() の第一引数には B<カテゴリー> を、第二引数には |
631 |
B<ロケール> を与えます。 |
632 |
カテゴリーはロケール特有の規則を適用したいデータ処理の状況を指示します。 |
633 |
カテゴリー名は L</LOCALE CATEGORIES> と L</"ENVIRONMENT"> に記述されています。 |
634 |
ロケールはカスタマイズを行うための、特定の言語の組み合わせ、国や地域、 |
635 |
コードセットに関する情報の集合の名前です。 |
636 |
ヒントとしてロケールの名前付けに注目してください: すべてのシステムが |
637 |
この例のようにロケールに名前を付けているわけではありません。 |
638 |
|
639 |
=begin original |
640 |
|
641 |
If no second argument is provided and the category is something else |
642 |
than LC_ALL, the function returns a string naming the current locale |
643 |
for the category. You can use this value as the second argument in a |
644 |
subsequent call to setlocale(). |
645 |
|
646 |
=end original |
647 |
|
648 |
第二引数が省略されていて、さらにカテゴリーが LC_ALL 以外の場合、この関数は |
649 |
カテゴリーに対するカレントロケールの名前からなる文字列を返します。 |
650 |
この値を、後で行う setlocale() の呼び出しでの第二引数として |
651 |
使うこともできます。 |
652 |
|
653 |
=begin original |
654 |
|
655 |
If no second argument is provided and the category is LC_ALL, the |
656 |
result is implementation-dependent. It may be a string of |
657 |
concatenated locale names (separator also implementation-dependent) |
658 |
or a single locale name. Please consult your setlocale(3) man page for |
659 |
details. |
660 |
|
661 |
=end original |
662 |
|
663 |
カテゴリーが LC_ALL で、第二引数が与えられなかった場合には |
664 |
その結果は処理系に依存するものとなります。 |
665 |
ロケールの名前を連結したものか(セパレーターはこれまた処理系依存のもの)、 |
666 |
単一のロケール名となります。 |
667 |
詳しくは setlocale(3) man ページをあたってください。 |
668 |
|
669 |
=begin original |
670 |
|
671 |
If a second argument is given and it corresponds to a valid locale, |
672 |
the locale for the category is set to that value, and the function |
673 |
returns the now-current locale value. You can then use this in yet |
674 |
another call to setlocale(). (In some implementations, the return |
675 |
value may sometimes differ from the value you gave as the second |
676 |
argument--think of it as an alias for the value you gave.) |
677 |
|
678 |
=end original |
679 |
|
680 |
第二引数が与えられていて、かつそれが正当なものであれば、カテゴリの |
681 |
ロケールが設定され、この関数は現在のロケール値を返します。 |
682 |
この値は次の setlocale() に呼び出しで使えます。 |
683 |
(一部の実装では、この返り値は第二引数を与えたときと異なる場合があります |
684 |
-- これは与えた引数のエイリアスと考えられます。) |
685 |
|
686 |
=begin original |
687 |
|
688 |
As the example shows, if the second argument is an empty string, the |
689 |
category's locale is returned to the default specified by the |
690 |
corresponding environment variables. Generally, this results in a |
691 |
return to the default that was in force when Perl started up: changes |
692 |
to the environment made by the application after startup may or may not |
693 |
be noticed, depending on your system's C library. |
694 |
|
695 |
=end original |
696 |
|
697 |
例に示したように、第二引数が空文字列であった場合にはカテゴリーの、 |
698 |
対応する環境変数によりデフォルト指定されるロケールが返されます。 |
699 |
一般的にはこの結果は、Perl が起動したときに強制的にデフォルトとして |
700 |
設定された値です: アプリケーションが起動した後での環境変数の変更が |
701 |
認識される/されないは、使用している C ライブラリに依存します。 |
702 |
|
703 |
=begin original |
704 |
|
705 |
If the second argument does not correspond to a valid locale, the locale |
706 |
for the category is not changed, and the function returns I<undef>. |
707 |
|
708 |
=end original |
709 |
|
710 |
第二引数が正しいロケールを表わしていない場合、 |
711 |
カテゴリーに対するロケールは変更されず、関数は I<undef> を返します。 |
712 |
|
713 |
=begin original |
714 |
|
715 |
Note that Perl ignores the current C<LC_CTYPE> and C<LC_COLLATE> locales |
716 |
within the scope of a C<use locale ':not_characters'>. |
717 |
|
718 |
=end original |
719 |
|
720 |
Note that Perl ignores the current C<LC_CTYPE> and C<LC_COLLATE> locales |
721 |
within the scope of a C<use locale ':not_characters'>. |
722 |
(TBT) |
723 |
|
724 |
=begin original |
725 |
|
726 |
For further information about the categories, consult setlocale(3). |
727 |
|
728 |
=end original |
729 |
|
730 |
カテゴリーに対する詳細な情報は、setlocale(3) を参照してください。 |
731 |
|
732 |
=head2 Finding locales |
733 |
|
734 |
(ロケールを見つける) |
735 |
|
736 |
=begin original |
737 |
|
738 |
For locales available in your system, consult also setlocale(3) to |
739 |
see whether it leads to the list of available locales (search for the |
740 |
I<SEE ALSO> section). If that fails, try the following command lines: |
741 |
|
742 |
=end original |
743 |
|
744 |
ロケールが使えるシステムであれば、使用可能なロケールがどういったもので |
745 |
あるかどうかを setlocale(3) で調べてみてください |
746 |
(I<SEE ALSO> の章を探してください)。 |
747 |
それがダメだったら、以下のコマンドを試してみてください。 |
748 |
|
749 |
locale -a |
750 |
|
751 |
nlsinfo |
752 |
|
753 |
ls /usr/lib/nls/loc |
754 |
|
755 |
ls /usr/lib/locale |
756 |
|
757 |
ls /usr/lib/nls |
758 |
|
759 |
ls /usr/share/locale |
760 |
|
761 |
=begin original |
762 |
|
763 |
and see whether they list something resembling these |
764 |
|
765 |
=end original |
766 |
|
767 |
そして、そこに以下に挙げたものと似たものがあるかどうかを |
768 |
確かめてください。 |
769 |
|
770 |
en_US.ISO8859-1 de_DE.ISO8859-1 ru_RU.ISO8859-5 |
771 |
en_US.iso88591 de_DE.iso88591 ru_RU.iso88595 |
772 |
en_US de_DE ru_RU |
773 |
en de ru |
774 |
english german russian |
775 |
english.iso88591 german.iso88591 russian.iso88595 |
776 |
english.roman8 russian.koi8r |
777 |
|
778 |
=begin original |
779 |
|
780 |
Sadly, even though the calling interface for setlocale() has been |
781 |
standardized, names of locales and the directories where the |
782 |
configuration resides have not been. The basic form of the name is |
783 |
I<language_territory>B<.>I<codeset>, but the latter parts after |
784 |
I<language> are not always present. The I<language> and I<country> |
785 |
are usually from the standards B<ISO 3166> and B<ISO 639>, the |
786 |
two-letter abbreviations for the countries and the languages of the |
787 |
world, respectively. The I<codeset> part often mentions some B<ISO |
788 |
8859> character set, the Latin codesets. For example, C<ISO 8859-1> |
789 |
is the so-called "Western European codeset" that can be used to encode |
790 |
most Western European languages adequately. Again, there are several |
791 |
ways to write even the name of that one standard. Lamentably. |
792 |
|
793 |
=end original |
794 |
|
795 |
残念ながら、setlocale() を呼び出すインターフェースが既に |
796 |
標準化されているのにも関らず、ロケールの名前や、それが設定される |
797 |
ディレクトリはまだなのです。 |
798 |
名前の基本形式は I<language_territory>B<.>I<codeset> ですが、末尾の部分は |
799 |
常にある訳ではありません。 |
800 |
I<language> と I<country> は通常は B<ISO 3166> や B<ISO 639> という |
801 |
標準による、言語や国を二文字に略したものになります。 |
802 |
I<codeset> の部分はしばしば文字集合 B<ISO 8859> の |
803 |
バリエーションとなります。 |
804 |
たとえば、"Western codeset" と呼ばれる C<ISO 8859-1> は西欧における |
805 |
エンコーディングとして用いることができます。 |
806 |
繰り返しますが、一つの標準の名前であってさえ、記述するには複数の方法が |
807 |
存在するのです。 |
808 |
嘆かわしいことです。 |
809 |
|
810 |
=begin original |
811 |
|
812 |
Two special locales are worth particular mention: "C" and "POSIX". |
813 |
Currently these are effectively the same locale: the difference is |
814 |
mainly that the first one is defined by the C standard, the second by |
815 |
the POSIX standard. They define the B<default locale> in which |
816 |
every program starts in the absence of locale information in its |
817 |
environment. (The I<default> default locale, if you will.) Its language |
818 |
is (American) English and its character codeset ASCII. |
819 |
B<Warning>. The C locale delivered by some vendors may not |
820 |
actually exactly match what the C standard calls for. So beware. |
821 |
|
822 |
=end original |
823 |
|
824 |
“C”と“POSIX”という二つの特殊なロケールがあります。 |
825 |
現時点では、これら二つは同じロケールとなります。 |
826 |
その違いは主に、前者が C の標準により決められたものであるのに対して、 |
827 |
後者が POSIX の標準で決められているものであるという点にあります。 |
828 |
これらの規格が決めていることは、環境変数にあるロケール情報がない状態での |
829 |
プログラム起動時の B<デフォルトのロケール> です |
830 |
(I<デフォルトの> デフォルトロケールです)。 |
831 |
その言語は (アメリカ)英語であり、そのキャラクターセットは ASCII となります。 |
832 |
B<警告>。 |
833 |
一部のベンダによって提供されている C ロケールは実際には C 標準が要求している |
834 |
ものに正確に一致していないかもしれません。 |
835 |
注意してください。 |
836 |
|
837 |
=begin original |
838 |
|
839 |
B<NOTE>: Not all systems have the "POSIX" locale (not all systems are |
840 |
POSIX-conformant), so use "C" when you need explicitly to specify this |
841 |
default locale. |
842 |
|
843 |
=end original |
844 |
|
845 |
B<注意>:すべてのシステムが "POSIX" ロケールを持っているわけでは |
846 |
ありません(すべてのシステムが POSIX に準拠しているわけではありません)ので、 |
847 |
明示的にこのデフォルトロケールを指定するのが必要なときには |
848 |
"C" を使います。 |
849 |
|
850 |
=head2 LOCALE PROBLEMS |
851 |
|
852 |
(ロケールの問題) |
853 |
|
854 |
=begin original |
855 |
|
856 |
You may encounter the following warning message at Perl startup: |
857 |
|
858 |
=end original |
859 |
|
860 |
Perl を実行したときに以下のようなメッセージを見たことがあるかもしれません: |
861 |
|
862 |
perl: warning: Setting locale failed. |
863 |
perl: warning: Please check that your locale settings: |
864 |
LC_ALL = "En_US", |
865 |
LANG = (unset) |
866 |
are supported and installed on your system. |
867 |
perl: warning: Falling back to the standard locale ("C"). |
868 |
|
869 |
=begin original |
870 |
|
871 |
This means that your locale settings had LC_ALL set to "En_US" and |
872 |
LANG exists but has no value. Perl tried to believe you but could not. |
873 |
Instead, Perl gave up and fell back to the "C" locale, the default locale |
874 |
that is supposed to work no matter what. This usually means your locale |
875 |
settings were wrong, they mention locales your system has never heard |
876 |
of, or the locale installation in your system has problems (for example, |
877 |
some system files are broken or missing). There are quick and temporary |
878 |
fixes to these problems, as well as more thorough and lasting fixes. |
879 |
|
880 |
=end original |
881 |
|
882 |
これは、あなたのロケールの設定が、LC_ALL が“En_US”であり LANG が |
883 |
存在しているが値を持っていないということを意味します。 |
884 |
Perlはあなたを信じようとしたのですができなかったのです。 |
885 |
その代わりに、Perl はロケール設定をあきらめて、デフォルトである |
886 |
"C" ロケールに戻ったのです。 |
887 |
これは通常はあなたのロケール設定が間違っているせいであり、聞いたことのない |
888 |
ロケールであったり、あるいはあなたのインストールに問題があったのだろう |
889 |
(例えば、一部のシステムファイルが壊れていたとか、なかったとか)と |
890 |
いうことです。 |
891 |
以下で述べるのは、この問題を手っ取り早く一時的に修復するものです。 |
892 |
|
893 |
=head2 Temporarily fixing locale problems |
894 |
|
895 |
(一時的にロケールの問題を修正する) |
896 |
|
897 |
=begin original |
898 |
|
899 |
The two quickest fixes are either to render Perl silent about any |
900 |
locale inconsistencies or to run Perl under the default locale "C". |
901 |
|
902 |
=end original |
903 |
|
904 |
二つの(一時的な)対応策とは、ロケールに関する矛盾を無視するように |
905 |
するというものと、Perl をデフォルトロケール "C" で実行するというものです。 |
906 |
|
907 |
=begin original |
908 |
|
909 |
Perl's moaning about locale problems can be silenced by setting the |
910 |
environment variable PERL_BADLANG to a zero value, for example "0". |
911 |
This method really just sweeps the problem under the carpet: you tell |
912 |
Perl to shut up even when Perl sees that something is wrong. Do not |
913 |
be surprised if later something locale-dependent misbehaves. |
914 |
|
915 |
=end original |
916 |
|
917 |
Perl 起動時の問題は、環境変数 PERL_BADLANG にゼロ、たとえば |
918 |
"0" を設定することによって回避できます。 |
919 |
この方法は問題をカーペットの下に押し込むだけのことです: |
920 |
つまり、Perl が何か間違ったことを見つけたとしても Perl を |
921 |
黙らせておくというものです。 |
922 |
もし後でロケールに依存した変な振る舞いがあったとしても |
923 |
驚かないでください。 |
924 |
|
925 |
=begin original |
926 |
|
927 |
Perl can be run under the "C" locale by setting the environment |
928 |
variable LC_ALL to "C". This method is perhaps a bit more civilized |
929 |
than the PERL_BADLANG approach, but setting LC_ALL (or |
930 |
other locale variables) may affect other programs as well, not just |
931 |
Perl. In particular, external programs run from within Perl will see |
932 |
these changes. If you make the new settings permanent (read on), all |
933 |
programs you run see the changes. See L<"ENVIRONMENT"> for |
934 |
the full list of relevant environment variables and L<USING LOCALES> |
935 |
for their effects in Perl. Effects in other programs are |
936 |
easily deducible. For example, the variable LC_COLLATE may well affect |
937 |
your B<sort> program (or whatever the program that arranges "records" |
938 |
alphabetically in your system is called). |
939 |
|
940 |
=end original |
941 |
|
942 |
環境変数 LC_ALL に "C" を設定することにより、Perl はロケール "C" の下でも |
943 |
実行することができます。 |
944 |
このやり方は PERL_BADLANG よりは多少まともなものですが、それでも |
945 |
LC_ALL (もしくは他のロケール変数)を設定するということは Perl 以外の |
946 |
プログラムにも影響を及ぼします。 |
947 |
特に、Perl の内側で実行される外部プログラムはこの変更に影響を |
948 |
受けることになります。 |
949 |
新しい設定を恒久的なものにしたいというのであれば、あなたが実行する |
950 |
プログラム全てがこの変更に影響を受けることになります。 |
951 |
関係する環境変数の完全なリストは L<"ENVIRONMENT"> を参照してください; |
952 |
また、Perl におけるそれらの効果については L<USING LOCALES> を |
953 |
参照してください。 |
954 |
他のプログラムに対する影響は簡単に避けられます。 |
955 |
たとえば、変数 LC_COLLATE はあなたの B<sort> プログラム |
956 |
(もしくは「レコード」をアルファベット順に並べ替えるプログラム)に |
957 |
影響を及ぼします。 |
958 |
|
959 |
=begin original |
960 |
|
961 |
You can test out changing these variables temporarily, and if the |
962 |
new settings seem to help, put those settings into your shell startup |
963 |
files. Consult your local documentation for the exact details. For in |
964 |
Bourne-like shells (B<sh>, B<ksh>, B<bash>, B<zsh>): |
965 |
|
966 |
=end original |
967 |
|
968 |
これらの変数に対する変更を一時的に行ってテストすることができます; そして |
969 |
新しい設定が助けになるものであればその設定をシェルのスタートアップ |
970 |
ファイルに追加するのです。 |
971 |
詳細はあなたの使っているシステムのドキュメントを調べてみてください。 |
972 |
Bourne シェルに似たシェル(B<sh>, B<ksh>, B<bash>, B<zsh>)であれば |
973 |
以下のようになります: |
974 |
|
975 |
LC_ALL=en_US.ISO8859-1 |
976 |
export LC_ALL |
977 |
|
978 |
=begin original |
979 |
|
980 |
This assumes that we saw the locale "en_US.ISO8859-1" using the commands |
981 |
discussed above. We decided to try that instead of the above faulty |
982 |
locale "En_US"--and in Cshish shells (B<csh>, B<tcsh>) |
983 |
|
984 |
=end original |
985 |
|
986 |
これは、コマンドが参照するロケールを "en_US.ISO8859-1" にしています。 |
987 |
Cシェルライクなもの(B<csh>, B<tcsh>)の場合には以下のようになります: |
988 |
|
989 |
setenv LC_ALL en_US.ISO8859-1 |
990 |
|
991 |
=begin original |
992 |
|
993 |
or if you have the "env" application you can do in any shell |
994 |
|
995 |
=end original |
996 |
|
997 |
あるいは、"env" プログラムがあるなら、どのようなシェルでも、以下のように |
998 |
書けます: |
999 |
|
1000 |
env LC_ALL=en_US.ISO8859-1 perl ... |
1001 |
|
1002 |
=begin original |
1003 |
|
1004 |
If you do not know what shell you have, consult your local |
1005 |
helpdesk or the equivalent. |
1006 |
|
1007 |
=end original |
1008 |
|
1009 |
あなたがシェルについて良く知らないというのであれば、 |
1010 |
あなたのおそばのヘルプデスク等に訊ねてみてください。 |
1011 |
|
1012 |
=head2 Permanently fixing locale problems |
1013 |
|
1014 |
(ロケールの問題を恒久的に修正する) |
1015 |
|
1016 |
=begin original |
1017 |
|
1018 |
The slower but superior fixes are when you may be able to yourself |
1019 |
fix the misconfiguration of your own environment variables. The |
1020 |
mis(sing)configuration of the whole system's locales usually requires |
1021 |
the help of your friendly system administrator. |
1022 |
|
1023 |
=end original |
1024 |
|
1025 |
時間はかかるけれども優れた修正方法は、あなたの環境の間違っている部分を |
1026 |
正しくするというものです。 |
1027 |
システム全体での間違いはあなたの使っているシステムの、フレンドリーな |
1028 |
管理者の助けを必要とするでしょう。 |
1029 |
|
1030 |
=begin original |
1031 |
|
1032 |
First, see earlier in this document about L<Finding locales>. That tells |
1033 |
how to find which locales are really supported--and more importantly, |
1034 |
installed--on your system. In our example error message, environment |
1035 |
variables affecting the locale are listed in the order of decreasing |
1036 |
importance (and unset variables do not matter). Therefore, having |
1037 |
LC_ALL set to "En_US" must have been the bad choice, as shown by the |
1038 |
error message. First try fixing locale settings listed first. |
1039 |
|
1040 |
=end original |
1041 |
|
1042 |
まず最初にこのドキュメントの L<Finding locales> を参照してください。 |
1043 |
そこにはあなたの使うシステムで実際にサポートされているロケール、 |
1044 |
そしてもっと重要なインストールされているロケールを見つけだす方法が |
1045 |
解説されています。 |
1046 |
私たちが使ったエラーメッセージの例では、環境変数は重要度の高いものから |
1047 |
低いものへという順になっています。 |
1048 |
したがって、LC_ALL を "En_US" に設定することは良くない選択であり、 |
1049 |
これはエラーメッセージにも現れています。 |
1050 |
まず最初にリストの最初にあるロケール設定を修正します。 |
1051 |
|
1052 |
=begin original |
1053 |
|
1054 |
Second, if using the listed commands you see something B<exactly> |
1055 |
(prefix matches do not count and case usually counts) like "En_US" |
1056 |
without the quotes, then you should be okay because you are using a |
1057 |
locale name that should be installed and available in your system. |
1058 |
In this case, see L<Permanently fixing your system's locale configuration>. |
1059 |
|
1060 |
=end original |
1061 |
|
1062 |
次に、もしあなたがリストアップのコマンドを使って得たものが |
1063 |
B<正確に> "En_US" のようなもの(接頭辞の一致は考慮せず、大小文字の違いは |
1064 |
考慮します)であれば、あなたが使っているロケール名に対応するものが |
1065 |
システムに正しくインストールされていれば OK です。 |
1066 |
この場合、L<Permanently fixing your system's locale configuration> を |
1067 |
参照してください。 |
1068 |
|
1069 |
=head2 Permanently fixing your system's locale configuration |
1070 |
|
1071 |
(あなたのシステムのロケール設定を恒久的に修正する) |
1072 |
|
1073 |
=begin original |
1074 |
|
1075 |
This is when you see something like: |
1076 |
|
1077 |
=end original |
1078 |
|
1079 |
これは以下のようなメッセージが出たけれども: |
1080 |
|
1081 |
perl: warning: Please check that your locale settings: |
1082 |
LC_ALL = "En_US", |
1083 |
LANG = (unset) |
1084 |
are supported and installed on your system. |
1085 |
|
1086 |
=begin original |
1087 |
|
1088 |
but then cannot see that "En_US" listed by the above-mentioned |
1089 |
commands. You may see things like "en_US.ISO8859-1", but that isn't |
1090 |
the same. In this case, try running under a locale |
1091 |
that you can list and which somehow matches what you tried. The |
1092 |
rules for matching locale names are a bit vague because |
1093 |
standardization is weak in this area. See again the |
1094 |
L<Finding locales> about general rules. |
1095 |
|
1096 |
=end original |
1097 |
|
1098 |
"En_US" が先に挙げたコマンドによってリスト中になかった場合です。 |
1099 |
"en_US.ISO8859-1" のようなものを見たかも知れませんが、まったく |
1100 |
同一のものではなかったのでしょう。 |
1101 |
この場合、コマンドで挙げられたもの一致するロケールで |
1102 |
実行してみてください。 |
1103 |
ロケール名のマッチングルールは少々はっきりしないものです; それは、この分野に |
1104 |
関する標準が弱いものであるからです。 |
1105 |
一般的なルールについては L<Finding locales> をもう一度見てください。 |
1106 |
|
1107 |
=head2 Fixing system locale configuration |
1108 |
|
1109 |
(システムのロケール設定を修正する) |
1110 |
|
1111 |
=begin original |
1112 |
|
1113 |
Contact a system administrator (preferably your own) and report the exact |
1114 |
error message you get, and ask them to read this same documentation you |
1115 |
are now reading. They should be able to check whether there is something |
1116 |
wrong with the locale configuration of the system. The L<Finding locales> |
1117 |
section is unfortunately a bit vague about the exact commands and places |
1118 |
because these things are not that standardized. |
1119 |
|
1120 |
=end original |
1121 |
|
1122 |
システム管理者にコンタクトをとって、あなたの得たエラーメッセージそのままを |
1123 |
レポートして、今ここまで読んできたことを説明してください。 |
1124 |
システム管理者はシステムのロケール設定についてどこがどう間違っているかを |
1125 |
理解できるはずです。 |
1126 |
標準化がなされていないので、コマンド名などに関して L<Finding locales> の |
1127 |
章は残念ながら少々あやふやなものになっています。 |
1128 |
|
1129 |
=head2 The localeconv function |
1130 |
|
1131 |
(localeconv 関数) |
1132 |
|
1133 |
=begin original |
1134 |
|
1135 |
The POSIX::localeconv() function allows you to get particulars of the |
1136 |
locale-dependent numeric formatting information specified by the current |
1137 |
C<LC_NUMERIC> and C<LC_MONETARY> locales. (If you just want the name of |
1138 |
the current locale for a particular category, use POSIX::setlocale() |
1139 |
with a single parameter--see L<The setlocale function>.) |
1140 |
|
1141 |
=end original |
1142 |
|
1143 |
POSIX::localeconv() 関数は、カレントの C<LC_NUMERIC> や C<LC_MONETARY> で |
1144 |
指定されるロケール依存の数値書式の情報を取り出します。 |
1145 |
(ある特定のカテゴリーのカレントロケールを知りたいだけなのなら、 |
1146 |
POSIX::setlocale() を引数一つで使います--L<The setlocale function> を |
1147 |
参照してください。) |
1148 |
|
1149 |
use POSIX qw(locale_h); |
1150 |
|
1151 |
# Get a reference to a hash of locale-dependent info |
1152 |
$locale_values = localeconv(); |
1153 |
|
1154 |
# Output sorted list of the values |
1155 |
for (sort keys %$locale_values) { |
1156 |
printf "%-20s = %s\n", $_, $locale_values->{$_} |
1157 |
} |
1158 |
|
1159 |
=begin original |
1160 |
|
1161 |
localeconv() takes no arguments, and returns B<a reference to> a hash. |
1162 |
The keys of this hash are variable names for formatting, such as |
1163 |
C<decimal_point> and C<thousands_sep>. The values are the |
1164 |
corresponding, er, values. See L<POSIX/localeconv> for a longer |
1165 |
example listing the categories an implementation might be expected to |
1166 |
provide; some provide more and others fewer. You don't need an |
1167 |
explicit C<use locale>, because localeconv() always observes the |
1168 |
current locale. |
1169 |
|
1170 |
=end original |
1171 |
|
1172 |
localeconv() は引数を取らず、戻り値としてハッシュに対する |
1173 |
B<リファレンス> を返します。 |
1174 |
このハッシュのキーは C<decimal_point> や C<thousands_sep> のように |
1175 |
整形された変数名です。 |
1176 |
格納されている値はそのキーに対応する値です。 |
1177 |
ある実装が提供しているであろうすべてのカテゴリーをリストアップしている |
1178 |
長いサンプルは L<POSIX/localeconv> を参照してください; |
1179 |
しかしながら、一部のものが多かったり少なかったするかもしれません。 |
1180 |
ロケールを問い合わせるジョブの関数のように C<use locale> する必要が |
1181 |
ないことに注意してください; localeconv() は常にカレントのロケールを |
1182 |
監視しています。 |
1183 |
|
1184 |
=begin original |
1185 |
|
1186 |
Here's a simple-minded example program that rewrites its command-line |
1187 |
parameters as integers correctly formatted in the current locale: |
1188 |
|
1189 |
=end original |
1190 |
|
1191 |
以下の例は、コマンドラインで渡されたパラメーターをカレントのロケールにおける |
1192 |
正しい書式に書きなおすというものです。 |
1193 |
|
1194 |
# See comments in previous example |
1195 |
require 5.004; |
1196 |
use POSIX qw(locale_h); |
1197 |
|
1198 |
# Get some of locale's numeric formatting parameters |
1199 |
my ($thousands_sep, $grouping) = |
1200 |
@{localeconv()}{'thousands_sep', 'grouping'}; |
1201 |
|
1202 |
# Apply defaults if values are missing |
1203 |
$thousands_sep = ',' unless $thousands_sep; |
1204 |
|
1205 |
=begin original |
1206 |
|
1207 |
# grouping and mon_grouping are packed lists |
1208 |
# of small integers (characters) telling the |
1209 |
# grouping (thousand_seps and mon_thousand_seps |
1210 |
# being the group dividers) of numbers and |
1211 |
# monetary quantities. The integers' meanings: |
1212 |
# 255 means no more grouping, 0 means repeat |
1213 |
# the previous grouping, 1-254 means use that |
1214 |
# as the current grouping. Grouping goes from |
1215 |
# right to left (low to high digits). In the |
1216 |
# below we cheat slightly by never using anything |
1217 |
# else than the first grouping (whatever that is). |
1218 |
if ($grouping) { |
1219 |
@grouping = unpack("C*", $grouping); |
1220 |
} else { |
1221 |
@grouping = (3); |
1222 |
} |
1223 |
|
1224 |
=end original |
1225 |
|
1226 |
# grouping と mon_grouping は小整数のパック済みリストになって |
1227 |
# います; これはgrouping (thousand_seps と mon_thousand_seps |
1228 |
# はグループを分けるものです)の数と金銭に関するものの指定を |
1229 |
# 行っています。その整数の意味はこうです: 255はグルーピング |
1230 |
# しないことを意味します; 1から254はカレントのグルーピングで |
1231 |
# 使用する数値を意味します;。グルーピングは右から左へ(下位桁から |
1232 |
# 上位桁)と適用されます。下の例では最初のグルーピング以外は |
1233 |
# (それが何でも)使わないことによってこれを避けています。 |
1234 |
if ($grouping) { |
1235 |
@grouping = unpack("C*", $grouping); |
1236 |
} else { |
1237 |
@grouping = (3); |
1238 |
} |
1239 |
|
1240 |
# Format command line params for current locale |
1241 |
for (@ARGV) { |
1242 |
$_ = int; # Chop non-integer part |
1243 |
1 while |
1244 |
s/(\d)(\d{$grouping[0]}($|$thousands_sep))/$1$thousands_sep$2/; |
1245 |
print "$_"; |
1246 |
} |
1247 |
print "\n"; |
1248 |
|
1249 |
=head2 I18N::Langinfo |
1250 |
|
1251 |
=begin original |
1252 |
|
1253 |
Another interface for querying locale-dependent information is the |
1254 |
I18N::Langinfo::langinfo() function, available at least in Unix-like |
1255 |
systems and VMS. |
1256 |
|
1257 |
=end original |
1258 |
|
1259 |
ロケール依存の情報を問い合わせるその他のインターフェースとしては |
1260 |
I18N::Langinfo::langinfo() 関数があり、少なくとも Unix 風のシステムと |
1261 |
VMS で利用可能です。 |
1262 |
|
1263 |
=begin original |
1264 |
|
1265 |
The following example will import the langinfo() function itself and |
1266 |
three constants to be used as arguments to langinfo(): a constant for |
1267 |
the abbreviated first day of the week (the numbering starts from |
1268 |
Sunday = 1) and two more constants for the affirmative and negative |
1269 |
answers for a yes/no question in the current locale. |
1270 |
|
1271 |
=end original |
1272 |
|
1273 |
以下の例は langinfo() 関数自身と、 langinfo() の引数として使う 3 つの |
1274 |
定数をインポートします: 1 つは現在のロケールでの週の最初の日の省略形 |
1275 |
(番号は日曜日=1として振られています)、後の 2 つははい/いいえの質問に |
1276 |
対しての肯定および否定を現在のロケールで表すものです。 |
1277 |
|
1278 |
use I18N::Langinfo qw(langinfo ABDAY_1 YESSTR NOSTR); |
1279 |
|
1280 |
my ($abday_1, $yesstr, $nostr) |
1281 |
= map { langinfo } qw(ABDAY_1 YESSTR NOSTR); |
1282 |
|
1283 |
print "$abday_1? [$yesstr/$nostr] "; |
1284 |
|
1285 |
=begin original |
1286 |
|
1287 |
In other words, in the "C" (or English) locale the above will probably |
1288 |
print something like: |
1289 |
|
1290 |
=end original |
1291 |
|
1292 |
言い換えると、"C" (または English) ロケールでは上記のものはおそらく |
1293 |
以下のようなものが表示されます: |
1294 |
|
1295 |
Sun? [yes/no] |
1296 |
|
1297 |
=begin original |
1298 |
|
1299 |
See L<I18N::Langinfo> for more information. |
1300 |
|
1301 |
=end original |
1302 |
|
1303 |
さらなる情報については L<I18N::Langinfo> を参照してください。 |
1304 |
|
1305 |
=head1 LOCALE CATEGORIES |
1306 |
|
1307 |
(ロケールカテゴリー) |
1308 |
|
1309 |
=begin original |
1310 |
|
1311 |
The following subsections describe basic locale categories. Beyond these, |
1312 |
some combination categories allow manipulation of more than one |
1313 |
basic category at a time. See L<"ENVIRONMENT"> for a discussion of these. |
1314 |
|
1315 |
=end original |
1316 |
|
1317 |
以下のセクションでは、基本的なロケールカテゴリーの説明をします。 |
1318 |
先の例のように、複数の基本カテゴリーを扱うことができる幾つかの |
1319 |
組み合わせカテゴリー(combination categories)があります。 |
1320 |
この事に関する詳細は、L<"ENVIRONMENT"> を参照してください。 |
1321 |
|
1322 |
=head2 Category LC_COLLATE: Collation |
1323 |
|
1324 |
(カテゴリー LC_COLLATE: 照合) |
1325 |
|
1326 |
=begin original |
1327 |
|
1328 |
In the scope of S<C<use locale>> (but not a |
1329 |
C<use locale ':not_characters'>), Perl looks to the C<LC_COLLATE> |
1330 |
environment variable to determine the application's notions on collation |
1331 |
(ordering) of characters. For example, "b" follows "a" in Latin |
1332 |
alphabets, but where do "E<aacute>" and "E<aring>" belong? And while |
1333 |
"color" follows "chocolate" in English, what about in Spanish? |
1334 |
|
1335 |
=end original |
1336 |
|
1337 |
S<C<use locale>> のスコープの内側にある(そして |
1338 |
C<use locale ':not_characters'> の内側でない)とき、Perl はアプリケーションで |
1339 |
使用する文字の照合(順番)を決定するために環境変数 C<LC_COLLATE> を |
1340 |
参照します(ラテンアルファベットでは "b" は "a" に続くものですが、 |
1341 |
"E<aacute>" や "E<aring>" はどこに置かれるのでしょう?)。 |
1342 |
また、英語では "color" は "chocolate" よりも後になりますが、スペイン語では |
1343 |
どうでしょう? |
1344 |
|
1345 |
=begin original |
1346 |
|
1347 |
The following collations all make sense and you may meet any of them |
1348 |
if you "use locale". |
1349 |
|
1350 |
=end original |
1351 |
|
1352 |
以下の照合は全て意味あるものであり、"use locale" をすれば直面することも |
1353 |
あるでしょう。 |
1354 |
|
1355 |
A B C D E a b c d e |
1356 |
A a B b C c D d E e |
1357 |
a A b B c C d D e E |
1358 |
a b c d e A B C D E |
1359 |
|
1360 |
=begin original |
1361 |
|
1362 |
Here is a code snippet to tell what "word" |
1363 |
characters are in the current locale, in that locale's order: |
1364 |
|
1365 |
=end original |
1366 |
|
1367 |
以下のコード片はカレントのロケールにおける英数文字をそのロケールでの |
1368 |
順序で出力するものです。 |
1369 |
|
1370 |
use locale; |
1371 |
print +(sort grep /\w/, map { chr } 0..255), "\n"; |
1372 |
|
1373 |
=begin original |
1374 |
|
1375 |
Compare this with the characters that you see and their order if you |
1376 |
state explicitly that the locale should be ignored: |
1377 |
|
1378 |
=end original |
1379 |
|
1380 |
これと、陽にロケールを無視するように指示したときのキャラクターとを |
1381 |
比較してみてください。 |
1382 |
|
1383 |
no locale; |
1384 |
print +(sort grep /\w/, map { chr } 0..255), "\n"; |
1385 |
|
1386 |
=begin original |
1387 |
|
1388 |
This machine-native collation (which is what you get unless S<C<use |
1389 |
locale>> has appeared earlier in the same block) must be used for |
1390 |
sorting raw binary data, whereas the locale-dependent collation of the |
1391 |
first example is useful for natural text. |
1392 |
|
1393 |
=end original |
1394 |
|
1395 |
この、マシン本来の照合(同じブロックの前のほうで S<C<use locale>> を |
1396 |
していない方)は生のバイナリデータのソートに用いるもので、 |
1397 |
最初の例で使ったロケール依存の照合は通常のテキストに使うのに便利です。 |
1398 |
|
1399 |
=begin original |
1400 |
|
1401 |
As noted in L<USING LOCALES>, C<cmp> compares according to the current |
1402 |
collation locale when C<use locale> is in effect, but falls back to a |
1403 |
char-by-char comparison for strings that the locale says are equal. You |
1404 |
can use POSIX::strcoll() if you don't want this fall-back: |
1405 |
|
1406 |
=end original |
1407 |
|
1408 |
L<USING LOCALES> で述べたように、C<cmp> は C<use locale> が有効なときには |
1409 |
カレントの照合ロケールに従って比較を行いますが、 |
1410 |
この結果が等しいと出た場合には文字毎の比較に逆戻りします。 |
1411 |
この逆戻りが嫌ならば、POSIX::strcoll() を使うことができます。 |
1412 |
|
1413 |
use POSIX qw(strcoll); |
1414 |
$equal_in_locale = |
1415 |
!strcoll("space and case ignored", "SpaceAndCaseIgnored"); |
1416 |
|
1417 |
=begin original |
1418 |
|
1419 |
$equal_in_locale will be true if the collation locale specifies a |
1420 |
dictionary-like ordering that ignores space characters completely and |
1421 |
which folds case. |
1422 |
|
1423 |
=end original |
1424 |
|
1425 |
$equal_in_locale は照合ロケールが空白キャラクタを完全に無視し、 |
1426 |
大小文字の区別を無視するような辞書に似た順序付けを |
1427 |
指定している場合には真になるでしょう。 |
1428 |
|
1429 |
=begin original |
1430 |
|
1431 |
If you have a single string that you want to check for "equality in |
1432 |
locale" against several others, you might think you could gain a little |
1433 |
efficiency by using POSIX::strxfrm() in conjunction with C<eq>: |
1434 |
|
1435 |
=end original |
1436 |
|
1437 |
「ロケールにおける等価性」の検査を他のものに対して行いたい(一つの) |
1438 |
文字列があるときにあなたは、POSIX::strxfrm() を C<eq> と一緒に |
1439 |
使うことによって多少の効率アップができると考えるかもしれません。 |
1440 |
|
1441 |
use POSIX qw(strxfrm); |
1442 |
$xfrm_string = strxfrm("Mixed-case string"); |
1443 |
print "locale collation ignores spaces\n" |
1444 |
if $xfrm_string eq strxfrm("Mixed-casestring"); |
1445 |
print "locale collation ignores hyphens\n" |
1446 |
if $xfrm_string eq strxfrm("Mixedcase string"); |
1447 |
print "locale collation ignores case\n" |
1448 |
if $xfrm_string eq strxfrm("mixed-case string"); |
1449 |
|
1450 |
=begin original |
1451 |
|
1452 |
strxfrm() takes a string and maps it into a transformed string for use |
1453 |
in char-by-char comparisons against other transformed strings during |
1454 |
collation. "Under the hood", locale-affected Perl comparison operators |
1455 |
call strxfrm() for both operands, then do a char-by-char |
1456 |
comparison of the transformed strings. By calling strxfrm() explicitly |
1457 |
and using a non locale-affected comparison, the example attempts to save |
1458 |
a couple of transformations. But in fact, it doesn't save anything: Perl |
1459 |
magic (see L<perlguts/Magic Variables>) creates the transformed version of a |
1460 |
string the first time it's needed in a comparison, then keeps this version around |
1461 |
in case it's needed again. An example rewritten the easy way with |
1462 |
C<cmp> runs just about as fast. It also copes with null characters |
1463 |
embedded in strings; if you call strxfrm() directly, it treats the first |
1464 |
null it finds as a terminator. don't expect the transformed strings |
1465 |
it produces to be portable across systems--or even from one revision |
1466 |
of your operating system to the next. In short, don't call strxfrm() |
1467 |
directly: let Perl do it for you. |
1468 |
|
1469 |
=end original |
1470 |
|
1471 |
strxfrm() は文字列を引数にとり、それを同様の変換を加えられた文字列との |
1472 |
文字毎の比較に使えるような文字列に変換します。 |
1473 |
「フードの中では」、ロケールに影響された Perl の比較演算子は |
1474 |
strxfrm() を両オペランドのために呼び出して、その後で文字毎の比較を、 |
1475 |
変換された文字列に対して行います。 |
1476 |
strxfrm() を陽に呼び出すこととロケールに影響されない比較を行うことで、 |
1477 |
上記の例は変換をセーブするようになります。 |
1478 |
実際にはこれは何もセーブしません: Perl の魔法(L<perlguts/Magic Variables> を |
1479 |
参照)は、比較の際に必要であれば最初に変換された文字列を生成し、それからそれが |
1480 |
再び必要になるまで取っておくのです。 |
1481 |
C<cmp> を使って書き直したサンプルは可能な限り早く実行されます。 |
1482 |
また、文字列に埋め込まれているナルキャラクターにも対処します; strxfrm() を |
1483 |
直接呼び出した場合、ナルは終端子としてみなされます。 |
1484 |
そして、変換後の文字列がシステムを越えて使えるようなものであると |
1485 |
期待してはいけません; また、あるオペレーティングシステムのバージョンで |
1486 |
作ったものが次の |
1487 |
バージョンでも同様であるということも期待してはいけません。 |
1488 |
一言でいうと、strxfrm() を直接呼び出してはいけない、ということです: |
1489 |
Perl に呼び出しをさせましょう。 |
1490 |
|
1491 |
=begin original |
1492 |
|
1493 |
Note: C<use locale> isn't shown in some of these examples because it isn't |
1494 |
needed: strcoll() and strxfrm() exist only to generate locale-dependent |
1495 |
results, and so always obey the current C<LC_COLLATE> locale. |
1496 |
|
1497 |
=end original |
1498 |
|
1499 |
注意: 幾つかのサンプルでは、必要がないので C<use locale> がありません: |
1500 |
strcoll() や strxfm() はロケール依存の結果しか生成しませんので、 |
1501 |
常に C<LC_COLLATE> ロケールを参照するのです。 |
1502 |
|
1503 |
=head2 Category LC_CTYPE: Character Types |
1504 |
|
1505 |
(カテゴリー LC_CTYPE: 文字タイプ) |
1506 |
|
1507 |
=begin original |
1508 |
|
1509 |
In the scope of S<C<use locale>> (but not a |
1510 |
C<use locale ':not_characters'>), Perl obeys the C<LC_CTYPE> locale |
1511 |
setting. This controls the application's notion of which characters are |
1512 |
alphabetic. This affects Perl's C<\w> regular expression metanotation, |
1513 |
which stands for alphanumeric characters--that is, alphabetic, |
1514 |
numeric, and including other special characters such as the underscore or |
1515 |
hyphen. (Consult L<perlre> for more information about |
1516 |
regular expressions.) Thanks to C<LC_CTYPE>, depending on your locale |
1517 |
setting, characters like "E<aelig>", "E<eth>", "E<szlig>", and |
1518 |
"E<oslash>" may be understood as C<\w> characters. |
1519 |
|
1520 |
=end original |
1521 |
|
1522 |
S<C<use locale>> のスコープにある(そして C<use locale ':not_characters'> の |
1523 |
内側でない)とき、Perl は C<LC_CTYPE> ロケールの設定に従います。 |
1524 |
これは、アプリケーションの英字かどうかの扱いを制御します。 |
1525 |
これは、英数字 -- つまり、英字、数字、および下線やハイフンと言った特別な |
1526 |
文字を含みます --に関わる正規表現のメタ表記 C<\w> に影響します。 |
1527 |
(正規表現に関するさらなる情報については L<perlre> を参照してください)。 |
1528 |
C<LC_CTYPE> のおかげで、ロケール設定に依存した "E<aelig>", "E<eth>", |
1529 |
"E<szlig>", "E<oslash>" のような文字が C<\w> 文字として認識できるのです。 |
1530 |
|
1531 |
=begin original |
1532 |
|
1533 |
The C<LC_CTYPE> locale also provides the map used in transliterating |
1534 |
characters between lower and uppercase. This affects the case-mapping |
1535 |
functions--lc(), lcfirst, uc(), and ucfirst(); case-mapping |
1536 |
interpolation with C<\l>, C<\L>, C<\u>, or C<\U> in double-quoted strings |
1537 |
and C<s///> substitutions; and case-independent regular expression |
1538 |
pattern matching using the C<i> modifier. |
1539 |
|
1540 |
=end original |
1541 |
|
1542 |
C<LC_CTYPE> ロケールはまた、小文字と大文字との間の相互変換に使われる |
1543 |
マッピングを提供します。 |
1544 |
これは大文字小文字変換関数 lc(), lcfirst, uc(), |
1545 |
ucfirst() とダブルクォートで囲まれた文字列の中での C<\l>, C<\L>, |
1546 |
C<\u>, <\U> による大文字小文字変換、そして C<s///> による置換、 |
1547 |
C<i> 修飾子を使った(大小文字を無視する)正規表現パターンマッチングに |
1548 |
影響を及ぼします。 |
1549 |
|
1550 |
=begin original |
1551 |
|
1552 |
Finally, C<LC_CTYPE> affects the POSIX character-class test |
1553 |
functions--isalpha(), islower(), and so on. For example, if you move |
1554 |
from the "C" locale to a 7-bit Scandinavian one, you may find--possibly |
1555 |
to your surprise--that "|" moves from the ispunct() class to isalpha(). |
1556 |
Unfortunately, this creates big problems for regular expressions. "|" still |
1557 |
means alternation even though it matches C<\w>. |
1558 |
|
1559 |
=end original |
1560 |
|
1561 |
さらに、C<LC_CTYPE> は POSIX のキャラクタクラステスト関数、isalpha(), |
1562 |
islower() などにも影響を及ぼします。 |
1563 |
たとえば、“C”ロケールを 7 ビットのスカンジナビアのものにしたとすると、 |
1564 |
多分あなたは驚くことになるでしょうが、"|" が ispunct() クラスから |
1565 |
isalpha() クラスに移動するのです。 |
1566 |
Unfortunately, this creates big problems for regular expressions. "|" still |
1567 |
means alternation even though it matches C<\w>. |
1568 |
(TBT) |
1569 |
|
1570 |
=begin original |
1571 |
|
1572 |
B<Note:> A broken or malicious C<LC_CTYPE> locale definition may result |
1573 |
in clearly ineligible characters being considered to be alphanumeric by |
1574 |
your application. For strict matching of (mundane) ASCII letters and |
1575 |
digits--for example, in command strings--locale-aware applications |
1576 |
should use C<\w> with the C</a> regular expression modifier. See L<"SECURITY">. |
1577 |
|
1578 |
=end original |
1579 |
|
1580 |
B<注意:> 壊れた、あるいは悪意のある C<LC_CTYPE> ロケールの定義は、 |
1581 |
不適切なキャラクターを英数字であるとみなしてしまう可能性があります。 |
1582 |
(アクセント記号のない)文字や数字の厳密なマッチング、例えばコマンド文字列の |
1583 |
ロケールを気にするアプリケーションは C</a> 正規表現修飾子付きで |
1584 |
C<\w> を使うべきです。 |
1585 |
L<"SECURITY"> を参照してください。 |
1586 |
|
1587 |
=head2 Category LC_NUMERIC: Numeric Formatting |
1588 |
|
1589 |
(カテゴリー LC_NUMERIC: 数値形式) |
1590 |
|
1591 |
=begin original |
1592 |
|
1593 |
After a proper POSIX::setlocale() call, Perl obeys the C<LC_NUMERIC> |
1594 |
locale information, which controls an application's idea of how numbers |
1595 |
should be formatted for human readability by the printf(), sprintf(), and |
1596 |
write() functions. String-to-numeric conversion by the POSIX::strtod() |
1597 |
function is also affected. In most implementations the only effect is to |
1598 |
change the character used for the decimal point--perhaps from "." to ",". |
1599 |
These functions aren't aware of such niceties as thousands separation and |
1600 |
so on. (See L<The localeconv function> if you care about these things.) |
1601 |
|
1602 |
=end original |
1603 |
|
1604 |
適切な POSIX::setlocale() 呼び出しの後、Perl は C<LC_NUMERIC> |
1605 |
ロケール情報を参照します; これはアプリケーションが printf(), sprintf(), |
1606 |
write() といった関数を使ったときに数値をどのように整形するかということを |
1607 |
制御するものです。 |
1608 |
文字列から数値への変換には、関数 POSIX::strtod() も影響を及ぼします。 |
1609 |
大部分の実装では、小数点を表わすキャラクターを "." から "," へと |
1610 |
変更するだけの効果しかありません。 |
1611 |
これらの関数は三桁毎の区切りなどについては考慮しません。 |
1612 |
(この事について心配があるのなら L<The localeconv function> を |
1613 |
参照してください。) |
1614 |
|
1615 |
=begin original |
1616 |
|
1617 |
Output produced by print() is also affected by the current locale: it |
1618 |
corresponds to what you'd get from printf() in the "C" locale. The |
1619 |
same is true for Perl's internal conversions between numeric and |
1620 |
string formats: |
1621 |
|
1622 |
=end original |
1623 |
|
1624 |
print() により生成された出力もカレントロケールの影響を受けます: |
1625 |
これは "C" ロケールで printf を使ったときの結果に対応します。 |
1626 |
Perl の、数値と文字列との間の内部的な変換はこれと同じです。 |
1627 |
|
1628 |
use POSIX qw(strtod setlocale LC_NUMERIC); |
1629 |
|
1630 |
setlocale LC_NUMERIC, ""; |
1631 |
|
1632 |
$n = 5/2; # Assign numeric 2.5 to $n |
1633 |
|
1634 |
$a = " $n"; # Locale-dependent conversion to string |
1635 |
|
1636 |
print "half five is $n\n"; # Locale-dependent output |
1637 |
|
1638 |
printf "half five is %g\n", $n; # Locale-dependent output |
1639 |
|
1640 |
print "DECIMAL POINT IS COMMA\n" |
1641 |
if $n == (strtod("2,5"))[0]; # Locale-dependent conversion |
1642 |
|
1643 |
=begin original |
1644 |
|
1645 |
See also L<I18N::Langinfo> and C<RADIXCHAR>. |
1646 |
|
1647 |
=end original |
1648 |
|
1649 |
L<I18N::Langinfo> と C<RADIXCHAR> も参照してください。 |
1650 |
|
1651 |
=head2 Category LC_MONETARY: Formatting of monetary amounts |
1652 |
|
1653 |
(カテゴリー LC_MONETARY: 金銭の書式) |
1654 |
|
1655 |
=begin original |
1656 |
|
1657 |
The C standard defines the C<LC_MONETARY> category, but not a function |
1658 |
that is affected by its contents. (Those with experience of standards |
1659 |
committees will recognize that the working group decided to punt on the |
1660 |
issue.) Consequently, Perl takes no notice of it. If you really want |
1661 |
to use C<LC_MONETARY>, you can query its contents--see |
1662 |
L<The localeconv function>--and use the information that it returns in your |
1663 |
application's own formatting of currency amounts. However, you may well |
1664 |
find that the information, voluminous and complex though it may be, still |
1665 |
does not quite meet your requirements: currency formatting is a hard nut |
1666 |
to crack. |
1667 |
|
1668 |
=end original |
1669 |
|
1670 |
標準 C では C<LC_MONETARY> カテゴリーを定義していますが、その内容に |
1671 |
影響される関数はありません。 |
1672 |
(規格委員会の経験によって、それらはワーキンググループがこの問題を |
1673 |
蹴り出すことに決めたことを認識したのでしょう。) |
1674 |
結果として、Perl はこれに注意を払いません。 |
1675 |
もし本当に C<LC_MONETARY> を使いたければ、自分でその内容を |
1676 |
問い合わせることができます(L<The localeconv function> を参照してください); |
1677 |
そして返ってきた情報をアプリケーションの通貨量の整形に使います。 |
1678 |
しかし、この情報を取得することはできるでしょうが、大量かつ複雑で、 |
1679 |
要求に対して本当にあったものではないでしょう: 金銭に関する書式は手に |
1680 |
おえない代物なのです。 |
1681 |
|
1682 |
=begin original |
1683 |
|
1684 |
See also L<I18N::Langinfo> and C<CRNCYSTR>. |
1685 |
|
1686 |
=end original |
1687 |
|
1688 |
L<I18N::Langinfo> と C<CRNCYSTR> も参照してください。 |
1689 |
|
1690 |
=head2 LC_TIME |
1691 |
|
1692 |
=begin original |
1693 |
|
1694 |
Output produced by POSIX::strftime(), which builds a formatted |
1695 |
human-readable date/time string, is affected by the current C<LC_TIME> |
1696 |
locale. Thus, in a French locale, the output produced by the C<%B> |
1697 |
format element (full month name) for the first month of the year would |
1698 |
be "janvier". Here's how to get a list of long month names in the |
1699 |
current locale: |
1700 |
|
1701 |
=end original |
1702 |
|
1703 |
人が読みやすい、整形された日付/時刻文字列を作り出す |
1704 |
POSIX::strftime() によって生成された出力はカレントの C<LC_TIME> ロケールに |
1705 |
影響を受けます。 |
1706 |
したがって、フランスのロケールでは、C<%B> 書式指定子(省略のない月の名前)を |
1707 |
一年の最初の月に対して使ったときの結果は、“janvier”となります。 |
1708 |
以下の例は、カレントロケールにおける長い月名のリストを得るものです。 |
1709 |
|
1710 |
use POSIX qw(strftime); |
1711 |
for (0..11) { |
1712 |
$long_month_name[$_] = |
1713 |
strftime("%B", 0, 0, 0, 1, $_, 96); |
1714 |
} |
1715 |
|
1716 |
=begin original |
1717 |
|
1718 |
Note: C<use locale> isn't needed in this example: as a function that |
1719 |
exists only to generate locale-dependent results, strftime() always |
1720 |
obeys the current C<LC_TIME> locale. |
1721 |
|
1722 |
=end original |
1723 |
|
1724 |
注意: C<use locale> はこの例では必要ではありません: strftime() は常に |
1725 |
カレントの C<LC_TIME> ロケールを参照し、ロケール依存の結果のみを生成します。 |
1726 |
|
1727 |
=begin original |
1728 |
|
1729 |
See also L<I18N::Langinfo> and C<ABDAY_1>..C<ABDAY_7>, C<DAY_1>..C<DAY_7>, |
1730 |
C<ABMON_1>..C<ABMON_12>, and C<ABMON_1>..C<ABMON_12>. |
1731 |
|
1732 |
=end original |
1733 |
|
1734 |
L<I18N::Langinfo> と C<ABDAY_1>..C<ABDAY_7>, C<DAY_1>..C<DAY_7> と |
1735 |
C<ABMON_1>..C<ABMON_12> と C<ABMON_1>..C<ABMON_12> も参照してください。 |
1736 |
|
1737 |
=head2 Other categories |
1738 |
|
1739 |
(その他のカテゴリー) |
1740 |
|
1741 |
=begin original |
1742 |
|
1743 |
The remaining locale category, C<LC_MESSAGES> (possibly supplemented |
1744 |
by others in particular implementations) is not currently used by |
1745 |
Perl--except possibly to affect the behavior of library functions |
1746 |
called by extensions outside the standard Perl distribution and by the |
1747 |
operating system and its utilities. Note especially that the string |
1748 |
value of C<$!> and the error messages given by external utilities may |
1749 |
be changed by C<LC_MESSAGES>. If you want to have portable error |
1750 |
codes, use C<%!>. See L<Errno>. |
1751 |
|
1752 |
=end original |
1753 |
|
1754 |
残ったロケールカテゴリー C<LC_MESSAGES> (別の特定の実装により |
1755 |
提供されていることもあるでしょう)は、現在の Perl では、標準の Perl 配布 |
1756 |
パッケージにはない拡張モジュールや OS やそのユーティリティから呼ばれる |
1757 |
ライブラリ関数が使っている可能性を除けば、使っていません。 |
1758 |
C<$!> の文字列値と、外部のユーティリティから与えられたエラーメッセージは |
1759 |
C<LC_MESSAGES> で変更されているかもしれないことに特に注意してください。 |
1760 |
移植性のあるエラーコードがほしい場合は、C<%!> を使ってください。 |
1761 |
L<Errno> を参照してください。 |
1762 |
|
1763 |
=head1 SECURITY |
1764 |
|
1765 |
(セキュリティ) |
1766 |
|
1767 |
=begin original |
1768 |
|
1769 |
Although the main discussion of Perl security issues can be found in |
1770 |
L<perlsec>, a discussion of Perl's locale handling would be incomplete |
1771 |
if it did not draw your attention to locale-dependent security issues. |
1772 |
Locales--particularly on systems that allow unprivileged users to |
1773 |
build their own locales--are untrustworthy. A malicious (or just plain |
1774 |
broken) locale can make a locale-aware application give unexpected |
1775 |
results. Here are a few possibilities: |
1776 |
|
1777 |
=end original |
1778 |
|
1779 |
Perl のセキュリティに関する事項の主な議論は L<perlsec> にありますが、 |
1780 |
Perl のロケールの扱いに関する議論はそれがあなたのロケール依存の |
1781 |
セキュリティ事項に対して注意していなければ不完全です。 |
1782 |
ロケールは(特に特権のないユーザーが自分のロケールを構築するのを許すような |
1783 |
システムでは)信用できないものなのです。 |
1784 |
悪意のある(もしくは単に壊れた)ロケールはロケールを使うアプリケーションを |
1785 |
予期できない結果にする可能性があります。 |
1786 |
以下に幾つかの可能性を挙げます。 |
1787 |
|
1788 |
=over 4 |
1789 |
|
1790 |
=item * |
1791 |
|
1792 |
=begin original |
1793 |
|
1794 |
Regular expression checks for safe file names or mail addresses using |
1795 |
C<\w> may be spoofed by an C<LC_CTYPE> locale that claims that |
1796 |
characters such as "E<gt>" and "|" are alphanumeric. |
1797 |
|
1798 |
=end original |
1799 |
|
1800 |
安全なファイル名やメイルアドレスを検索するための正規表現で C<\w> を使うと、 |
1801 |
“E<gt>”や“|”を英数字と主張するような C<LC_CTYPE> に |
1802 |
だまされてしまう可能性があります。 |
1803 |
|
1804 |
=item * |
1805 |
|
1806 |
=begin original |
1807 |
|
1808 |
String interpolation with case-mapping, as in, say, C<$dest = |
1809 |
"C:\U$name.$ext">, may produce dangerous results if a bogus LC_CTYPE |
1810 |
case-mapping table is in effect. |
1811 |
|
1812 |
=end original |
1813 |
|
1814 |
C<$dest = "C:\U$name.$ext"> のような、大文字小文字変換を伴った文字列の改変は、 |
1815 |
不正な LC_CTYPE の大文字小文字変換テーブルが有効であるときに |
1816 |
危険な結果を生成する可能性があります。 |
1817 |
|
1818 |
=item * |
1819 |
|
1820 |
=begin original |
1821 |
|
1822 |
A sneaky C<LC_COLLATE> locale could result in the names of students with |
1823 |
"D" grades appearing ahead of those with "A"s. |
1824 |
|
1825 |
=end original |
1826 |
|
1827 |
陰険な C<LC_COLLATE>ロケールは "D" 等級の生徒の名前を |
1828 |
"A" の前に置いてしまう結果にさせるかもしれません。 |
1829 |
|
1830 |
=item * |
1831 |
|
1832 |
=begin original |
1833 |
|
1834 |
An application that takes the trouble to use information in |
1835 |
C<LC_MONETARY> may format debits as if they were credits and vice versa |
1836 |
if that locale has been subverted. Or it might make payments in US |
1837 |
dollars instead of Hong Kong dollars. |
1838 |
|
1839 |
=end original |
1840 |
|
1841 |
手間を惜しまずに C<LC_MONETARY> にある情報を使うアプリケーションは、 |
1842 |
ロケールがおかしいと、負債を預金のように扱ったり、その逆にしたり |
1843 |
してしまうかもしれません。 |
1844 |
あるいは、香港ドルの代わりに US ドルで支払いをさせたりしてしまうかも |
1845 |
しれません。 |
1846 |
|
1847 |
=item * |
1848 |
|
1849 |
=begin original |
1850 |
|
1851 |
The date and day names in dates formatted by strftime() could be |
1852 |
manipulated to advantage by a malicious user able to subvert the |
1853 |
C<LC_DATE> locale. ("Look--it says I wasn't in the building on |
1854 |
Sunday.") |
1855 |
|
1856 |
=end original |
1857 |
|
1858 |
strftime() により整形された日付情報は、C<LC_DATE> をいじりまわすことの |
1859 |
できる悪意あるユーザーにより操作されてしまう可能性があります。 |
1860 |
(「見てくれよ、こいつ俺が日曜日にビルディングにいなかったって |
1861 |
言ってるよ。」) |
1862 |
|
1863 |
=back |
1864 |
|
1865 |
=begin original |
1866 |
|
1867 |
Such dangers are not peculiar to the locale system: any aspect of an |
1868 |
application's environment which may be modified maliciously presents |
1869 |
similar challenges. Similarly, they are not specific to Perl: any |
1870 |
programming language that allows you to write programs that take |
1871 |
account of their environment exposes you to these issues. |
1872 |
|
1873 |
=end original |
1874 |
|
1875 |
このような危険は、ロケールシステムに特有のものではありません: 意地の悪い |
1876 |
変更を通して同じような攻撃を受けるようなアプリケーション環境の |
1877 |
あらゆる状況が対象となります。 |
1878 |
同様に、これは Perl に固有なものでもありません: 環境を考慮するような |
1879 |
プログラムを書くことのできるあらゆるプログラミング言語で同様の危険性が |
1880 |
あるのです。 |
1881 |
|
1882 |
=begin original |
1883 |
|
1884 |
Perl cannot protect you from all possibilities shown in the |
1885 |
examples--there is no substitute for your own vigilance--but, when |
1886 |
C<use locale> is in effect, Perl uses the tainting mechanism (see |
1887 |
L<perlsec>) to mark string results that become locale-dependent, and |
1888 |
which may be untrustworthy in consequence. Here is a summary of the |
1889 |
tainting behavior of operators and functions that may be affected by |
1890 |
the locale: |
1891 |
|
1892 |
=end original |
1893 |
|
1894 |
perlは例示したようなすべての可能性からあなたを守ることはできません-- |
1895 |
あなた自身の用心に代り得るものはないのです--しかし、C<use locale> が |
1896 |
有効であるとき、Perl は汚染チェック機構(L<perlsec> を参照)を、ロケールに |
1897 |
依存した結果であり、信用できないかもしれない文字列に注意するために |
1898 |
使用します。 |
1899 |
以下は、ロケールにより影響を受ける可能性のある演算子や関数の汚染される |
1900 |
振る舞いのまとめです。 |
1901 |
|
1902 |
=over 4 |
1903 |
|
1904 |
=item * |
1905 |
|
1906 |
=begin original |
1907 |
|
1908 |
B<Comparison operators> (C<lt>, C<le>, C<ge>, C<gt> and C<cmp>): |
1909 |
|
1910 |
=end original |
1911 |
|
1912 |
B<比較演算子> (C<lt>, C<le>, C<ge>, C<gt>, C<cmp>): |
1913 |
|
1914 |
=begin original |
1915 |
|
1916 |
Scalar true/false (or less/equal/greater) result is never tainted. |
1917 |
|
1918 |
=end original |
1919 |
|
1920 |
スカラの真/偽(もしくは未満/等しい/越えている)の結果は |
1921 |
決して汚染されません。 |
1922 |
|
1923 |
=item * |
1924 |
|
1925 |
=begin original |
1926 |
|
1927 |
B<Case-mapping interpolation> (with C<\l>, C<\L>, C<\u> or C<\U>) |
1928 |
|
1929 |
=end original |
1930 |
|
1931 |
B<大文字小文字変換> (C<\l>, C<\L>, C<\u>, C<\U>) |
1932 |
|
1933 |
=begin original |
1934 |
|
1935 |
Result string containing interpolated material is tainted if |
1936 |
C<use locale> (but not S<C<use locale ':not_characters'>>) is in effect. |
1937 |
|
1938 |
=end original |
1939 |
|
1940 |
展開されたものが含まれる文字列は C<use locale> が有効な (そして |
1941 |
S<C<use locale ':not_characters'>> が有効でない) 場合には汚染されます。 |
1942 |
|
1943 |
=item * |
1944 |
|
1945 |
=begin original |
1946 |
|
1947 |
B<Matching operator> (C<m//>): |
1948 |
|
1949 |
=end original |
1950 |
|
1951 |
B<マッチング演算子> (C<m//>): |
1952 |
|
1953 |
=begin original |
1954 |
|
1955 |
Scalar true/false result never tainted. |
1956 |
|
1957 |
=end original |
1958 |
|
1959 |
スカラの真/偽の結果は決して汚染されません。 |
1960 |
|
1961 |
=begin original |
1962 |
|
1963 |
Subpatterns, either delivered as a list-context result or as $1 etc. |
1964 |
are tainted if C<use locale> (but not S<C<use locale ':not_characters'>>) |
1965 |
is in effect, and the subpattern regular |
1966 |
expression contains C<\w> (to match an alphanumeric character), C<\W> |
1967 |
(non-alphanumeric character), C<\s> (whitespace character), or C<\S> |
1968 |
(non whitespace character). The matched-pattern variable, $&, $` |
1969 |
(pre-match), $' (post-match), and $+ (last match) are also tainted if |
1970 |
C<use locale> is in effect and the regular expression contains C<\w>, |
1971 |
C<\W>, C<\s>, or C<\S>. |
1972 |
|
1973 |
=end original |
1974 |
|
1975 |
配列コンテキストの結果や、$1 などから派生したサブパターンは |
1976 |
C<use locale> が有効である (そして S<C<use locale ':not_characters'>> が |
1977 |
有効でない) ときには汚染されます; そして、C<\w> (英数字にマッチする)、C<\W> |
1978 |
(英数字以外にマッチする)、C<\s> (空白キャラクター)、 |
1979 |
C<\S> (空白でないキャラクター)を含む正規表現サブパターンも同様です。 |
1980 |
マッチした結果を保持する変数、$&、$`(マッチした部分より前)、$'(マッチした |
1981 |
部分より後)、$+ (最後にマッチしたもの)、そして C<\w>、C<\W>、 |
1982 |
C<\s>、C<\S> を含む正規表現も、C<use locale> が有効であるときには |
1983 |
汚染されます。 |
1984 |
|
1985 |
=item * |
1986 |
|
1987 |
=begin original |
1988 |
|
1989 |
B<Substitution operator> (C<s///>): |
1990 |
|
1991 |
=end original |
1992 |
|
1993 |
B<置換演算子> (C<s///>): |
1994 |
|
1995 |
=begin original |
1996 |
|
1997 |
Has the same behavior as the match operator. Also, the left |
1998 |
operand of C<=~> becomes tainted when C<use locale> |
1999 |
(but not S<C<use locale ':not_characters'>>) is in effect if modified as |
2000 |
a result of a substitution based on a regular |
2001 |
expression match involving C<\w>, C<\W>, C<\s>, or C<\S>; or of |
2002 |
case-mapping with C<\l>, C<\L>,C<\u> or C<\U>. |
2003 |
|
2004 |
=end original |
2005 |
|
2006 |
マッチング演算子と同じ振る舞いをします。 |
2007 |
また、C<=~> の左側のオペランドは、C<use locale> が有効の |
2008 |
(そして S<C<use locale ':not_characters'>> が |
2009 |
有効でない)とき、 |
2010 |
C<\w>, C<\W>, C<\s>, C<\S> の正規表現マッチングによる置換か、 |
2011 |
C<\l>, C<\L>,C<\u>, C<\U> の大文字小文字マッピングによって、 |
2012 |
値が変更された場合、汚染されます。 |
2013 |
|
2014 |
=item * |
2015 |
|
2016 |
=begin original |
2017 |
|
2018 |
B<Output formatting functions> (printf() and write()): |
2019 |
|
2020 |
=end original |
2021 |
|
2022 |
B<出力書式関数> (printf() と write()): |
2023 |
|
2024 |
=begin original |
2025 |
|
2026 |
Results are never tainted because otherwise even output from print, |
2027 |
for example C<print(1/7)>, should be tainted if C<use locale> is in |
2028 |
effect. |
2029 |
|
2030 |
=end original |
2031 |
|
2032 |
結果は決して汚染されません; なぜなら、もしそうでないなら、 |
2033 |
例えば C<print(1/7)> のような、print からの出力ですら |
2034 |
C<use locale> が有効のときは汚染されることになってしまいます。 |
2035 |
|
2036 |
=item * |
2037 |
|
2038 |
=begin original |
2039 |
|
2040 |
B<Case-mapping functions> (lc(), lcfirst(), uc(), ucfirst()): |
2041 |
|
2042 |
=end original |
2043 |
|
2044 |
B<大文字小文字変換関数> (lc(), lcfirst(), uc(), ucfirst()): |
2045 |
|
2046 |
=begin original |
2047 |
|
2048 |
Results are tainted if C<use locale> (but not |
2049 |
S<C<use locale ':not_characters'>>) is in effect. |
2050 |
|
2051 |
=end original |
2052 |
|
2053 |
C<use locale> が有効な(そして S<C<use locale ':not_characters'>> が |
2054 |
有効でない)ときに、結果が汚染されます。 |
2055 |
|
2056 |
=item * |
2057 |
|
2058 |
=begin original |
2059 |
|
2060 |
B<POSIX locale-dependent functions> (localeconv(), strcoll(), |
2061 |
strftime(), strxfrm()): |
2062 |
|
2063 |
=end original |
2064 |
|
2065 |
B<POSIX ロケール依存関数> (localeconv(), strcoll(), |
2066 |
strftime(), strxfrm()): |
2067 |
|
2068 |
=begin original |
2069 |
|
2070 |
Results are never tainted. |
2071 |
|
2072 |
=end original |
2073 |
|
2074 |
結果は決して汚染されません。 |
2075 |
|
2076 |
=item * |
2077 |
|
2078 |
=begin original |
2079 |
|
2080 |
B<POSIX character class tests> (isalnum(), isalpha(), isdigit(), |
2081 |
isgraph(), islower(), isprint(), ispunct(), isspace(), isupper(), |
2082 |
isxdigit()): |
2083 |
|
2084 |
=end original |
2085 |
|
2086 |
B<POSIX 文字クラステスト> (isalnum(), isalpha(), isdigit(), |
2087 |
isgraph(), islower(), isprint(), ispunct(), isspace(), isupper(), |
2088 |
isxdigit()): |
2089 |
|
2090 |
=begin original |
2091 |
|
2092 |
True/false results are never tainted. |
2093 |
|
2094 |
=end original |
2095 |
|
2096 |
真/偽の結果は決して汚染されません。 |
2097 |
|
2098 |
=back |
2099 |
|
2100 |
=begin original |
2101 |
|
2102 |
Three examples illustrate locale-dependent tainting. |
2103 |
The first program, which ignores its locale, won't run: a value taken |
2104 |
directly from the command line may not be used to name an output file |
2105 |
when taint checks are enabled. |
2106 |
|
2107 |
=end original |
2108 |
|
2109 |
三つの例を使って、ロケール依存の汚染を説明します。 |
2110 |
最初のプログラムはそのロケールを無視して、実行されません: 汚染検査が |
2111 |
有効であるときには、コマンドラインから直接とった値を出力ファイル名として |
2112 |
使うことはできません。 |
2113 |
|
2114 |
#/usr/local/bin/perl -T |
2115 |
# Run with taint checking |
2116 |
|
2117 |
# Command line sanity check omitted... |
2118 |
$tainted_output_file = shift; |
2119 |
|
2120 |
open(F, ">$tainted_output_file") |
2121 |
or warn "Open of $untainted_output_file failed: $!\n"; |
2122 |
|
2123 |
=begin original |
2124 |
|
2125 |
The program can be made to run by "laundering" the tainted value through |
2126 |
a regular expression: the second example--which still ignores locale |
2127 |
information--runs, creating the file named on its command line |
2128 |
if it can. |
2129 |
|
2130 |
=end original |
2131 |
|
2132 |
このプログラムは、汚染された値を正規表現を通して |
2133 |
「洗浄」(laundering)することにより実行できるようにできます: |
2134 |
以下に挙げる二番目の例は--これもロケール情報を無視しています-- |
2135 |
実行されると、コマンドラインにある名前のファイルを可能であれば作成します。 |
2136 |
|
2137 |
#/usr/local/bin/perl -T |
2138 |
|
2139 |
$tainted_output_file = shift; |
2140 |
$tainted_output_file =~ m%[\w/]+%; |
2141 |
$untainted_output_file = $&; |
2142 |
|
2143 |
open(F, ">$untainted_output_file") |
2144 |
or warn "Open of $untainted_output_file failed: $!\n"; |
2145 |
|
2146 |
=begin original |
2147 |
|
2148 |
Compare this with a similar but locale-aware program: |
2149 |
|
2150 |
=end original |
2151 |
|
2152 |
これを、非常に良く似てはいますが、ロケールを使ったプログラムと |
2153 |
比較してみてください。 |
2154 |
|
2155 |
#/usr/local/bin/perl -T |
2156 |
|
2157 |
$tainted_output_file = shift; |
2158 |
use locale; |
2159 |
$tainted_output_file =~ m%[\w/]+%; |
2160 |
$localized_output_file = $&; |
2161 |
|
2162 |
open(F, ">$localized_output_file") |
2163 |
or warn "Open of $localized_output_file failed: $!\n"; |
2164 |
|
2165 |
=begin original |
2166 |
|
2167 |
This third program fails to run because $& is tainted: it is the result |
2168 |
of a match involving C<\w> while C<use locale> is in effect. |
2169 |
|
2170 |
=end original |
2171 |
|
2172 |
この三番目のプログラムは、$& が汚染されているので実行に失敗します; |
2173 |
これは C<use locale> が有効であるときの C<\w> を含んだマッチングによる |
2174 |
結果です。 |
2175 |
|
2176 |
=head1 ENVIRONMENT |
2177 |
|
2178 |
(環境変数) |
2179 |
|
2180 |
=over 12 |
2181 |
|
2182 |
=item PERL_BADLANG |
2183 |
|
2184 |
=begin original |
2185 |
|
2186 |
A string that can suppress Perl's warning about failed locale settings |
2187 |
at startup. Failure can occur if the locale support in the operating |
2188 |
system is lacking (broken) in some way--or if you mistyped the name of |
2189 |
a locale when you set up your environment. If this environment |
2190 |
variable is absent, or has a value that does not evaluate to integer |
2191 |
zero--that is, "0" or ""-- Perl will complain about locale setting |
2192 |
failures. |
2193 |
|
2194 |
=end original |
2195 |
|
2196 |
Perl が起動時にロケールの設定に失敗した場合に警告を出すのを抑制できる |
2197 |
文字列です。 |
2198 |
オペレーティングシステムのロケールサポートがなんらかの理由でなかったり、 |
2199 |
壊れていたりするとき、あるいは環境変数に設定したロケールの名前を |
2200 |
間違えていた場合に発生します。 |
2201 |
もしこの変数が存在していないとか、あるいはその値が評価すると0に |
2202 |
ならないようなもの、つまり“0”や“”でない場合に、Perl はロケールの設定に |
2203 |
失敗するとメッセージを出力します。 |
2204 |
|
2205 |
=begin original |
2206 |
|
2207 |
B<NOTE>: PERL_BADLANG only gives you a way to hide the warning message. |
2208 |
The message tells about some problem in your system's locale support, |
2209 |
and you should investigate what the problem is. |
2210 |
|
2211 |
=end original |
2212 |
|
2213 |
B<注意>: PERL_BADLANG は警告メッセージを出さないようにするだけです。 |
2214 |
このメッセージはあなたの使うシステムのロケールサポートになにかの問題が |
2215 |
あるということを伝えるものですから、あなたは問題が何なのかを |
2216 |
確かめるべきでしょう。 |
2217 |
|
2218 |
=back |
2219 |
|
2220 |
=begin original |
2221 |
|
2222 |
The following environment variables are not specific to Perl: They are |
2223 |
part of the standardized (ISO C, XPG4, POSIX 1.c) setlocale() method |
2224 |
for controlling an application's opinion on data. |
2225 |
|
2226 |
=end original |
2227 |
|
2228 |
以下の環境変数は Perl に特有のものではなく、アプリケーションのデータの |
2229 |
扱いを制御するための標準的な(ISO C, XPG4, POSIX 1.c) setlocale() メソッドの |
2230 |
一部分です。 |
2231 |
|
2232 |
=over 12 |
2233 |
|
2234 |
=item LC_ALL |
2235 |
|
2236 |
=begin original |
2237 |
|
2238 |
C<LC_ALL> is the "override-all" locale environment variable. If |
2239 |
set, it overrides all the rest of the locale environment variables. |
2240 |
|
2241 |
=end original |
2242 |
|
2243 |
C<LC_ALL> は「全て上書き」ロケール環境変数です。 |
2244 |
もしこの環境変数が設定されていると、他のすべての環境変数を上書きします。 |
2245 |
|
2246 |
=item LANGUAGE |
2247 |
|
2248 |
=begin original |
2249 |
|
2250 |
B<NOTE>: C<LANGUAGE> is a GNU extension, it affects you only if you |
2251 |
are using the GNU libc. This is the case if you are using e.g. Linux. |
2252 |
If you are using "commercial" Unixes you are most probably I<not> |
2253 |
using GNU libc and you can ignore C<LANGUAGE>. |
2254 |
|
2255 |
=end original |
2256 |
|
2257 |
B<注意>: C<LANGUAGE> は GNU の拡張で、GNU libc を使っているときにのみ |
2258 |
効果があります。 |
2259 |
Linux を使ったときなどがこれに該当します。 |
2260 |
あなたが「商用の」Unix を使っているのであれば GNU libc は |
2261 |
使われていないでしょうし、C<LANGUAGE> は無視することができます。 |
2262 |
|
2263 |
=begin original |
2264 |
|
2265 |
However, in the case you are using C<LANGUAGE>: it affects the |
2266 |
language of informational, warning, and error messages output by |
2267 |
commands (in other words, it's like C<LC_MESSAGES>) but it has higher |
2268 |
priority than C<LC_ALL>. Moreover, it's not a single value but |
2269 |
instead a "path" (":"-separated list) of I<languages> (not locales). |
2270 |
See the GNU C<gettext> library documentation for more information. |
2271 |
|
2272 |
=end original |
2273 |
|
2274 |
C<LANGUAGE> を使った場合には、コマンドからの情報、警告、エラーといった |
2275 |
メッセージの言語に影響を及ぼします(言い換えると C<LC_MESSAGES> と |
2276 |
似ています)が、C<LC_ALL> よりも優先順位は下です。 |
2277 |
さらに、これは単一の値ではなくて言語(ロケールではありません)の、 |
2278 |
“:”で連結された「パス」になっています。 |
2279 |
より詳しい情報は GNU C<gettext> ライブラリのドキュメントを参照してください。 |
2280 |
|
2281 |
=item LC_CTYPE |
2282 |
|
2283 |
=begin original |
2284 |
|
2285 |
In the absence of C<LC_ALL>, C<LC_CTYPE> chooses the character type |
2286 |
locale. In the absence of both C<LC_ALL> and C<LC_CTYPE>, C<LANG> |
2287 |
chooses the character type locale. |
2288 |
|
2289 |
=end original |
2290 |
|
2291 |
C<LC_ALL> がないときに、C<LC_CTYPE> は文字タイプのロケールを選択します。 |
2292 |
C<LC_ALL> と C<LC_CTYPE> の両方ともない場合、C<LANG> が文字タイプの |
2293 |
ロケールを選択します。 |
2294 |
|
2295 |
=item LC_COLLATE |
2296 |
|
2297 |
=begin original |
2298 |
|
2299 |
In the absence of C<LC_ALL>, C<LC_COLLATE> chooses the collation |
2300 |
(sorting) locale. In the absence of both C<LC_ALL> and C<LC_COLLATE>, |
2301 |
C<LANG> chooses the collation locale. |
2302 |
|
2303 |
=end original |
2304 |
|
2305 |
C<LC_ALL> がないときに、C<LC_COLLATE> は照合(ソート)ロケールを選択します。 |
2306 |
C<LC_ALL> と C<LC_COLLATE> の両方ともない場合、C<LANG> が |
2307 |
照合ロケールを選択します。 |
2308 |
|
2309 |
=item LC_MONETARY |
2310 |
|
2311 |
=begin original |
2312 |
|
2313 |
In the absence of C<LC_ALL>, C<LC_MONETARY> chooses the monetary |
2314 |
formatting locale. In the absence of both C<LC_ALL> and C<LC_MONETARY>, |
2315 |
C<LANG> chooses the monetary formatting locale. |
2316 |
|
2317 |
=end original |
2318 |
|
2319 |
C<LC_ALL> がないときに、C<LC_MONETARY> は通貨形式ロケールを選択します。 |
2320 |
C<LC_ALL> と C<LC_MONETARY> の両方ともない場合、 |
2321 |
C<LANG> が通貨形式ロケールを選択します。 |
2322 |
|
2323 |
=item LC_NUMERIC |
2324 |
|
2325 |
=begin original |
2326 |
|
2327 |
In the absence of C<LC_ALL>, C<LC_NUMERIC> chooses the numeric format |
2328 |
locale. In the absence of both C<LC_ALL> and C<LC_NUMERIC>, C<LANG> |
2329 |
chooses the numeric format. |
2330 |
|
2331 |
=end original |
2332 |
|
2333 |
C<LC_ALL> がないときに、C<LC_NUMERIC> は数値表記のロケールを選択します。 |
2334 |
C<LC_ALL> と C<LC_NUMERIC> の両方ともない場合、C<LANG> が数値表記を |
2335 |
選択します。 |
2336 |
|
2337 |
=item LC_TIME |
2338 |
|
2339 |
=begin original |
2340 |
|
2341 |
In the absence of C<LC_ALL>, C<LC_TIME> chooses the date and time |
2342 |
formatting locale. In the absence of both C<LC_ALL> and C<LC_TIME>, |
2343 |
C<LANG> chooses the date and time formatting locale. |
2344 |
|
2345 |
=end original |
2346 |
|
2347 |
C<LC_ALL> がないときに、C<LC_TIME> は日付・時刻表記のロケールを選択します。 |
2348 |
C<LC_ALL> と C<LC_TIME> の両方ともない場合、C<LANG> が日付・時刻表記の |
2349 |
ロケールを選択します。 |
2350 |
|
2351 |
=item LANG |
2352 |
|
2353 |
=begin original |
2354 |
|
2355 |
C<LANG> is the "catch-all" locale environment variable. If it is set, it |
2356 |
is used as the last resort after the overall C<LC_ALL> and the |
2357 |
category-specific C<LC_...>. |
2358 |
|
2359 |
=end original |
2360 |
|
2361 |
C<LANG> は「包括的」なロケール環境変数です。 |
2362 |
これに値が設定されている場合、C<LC_ALL> も、各カテゴリーの C<LC_...> も |
2363 |
設定されていないときの最後の参照場所として使われます。 |
2364 |
|
2365 |
=back |
2366 |
|
2367 |
=head2 Examples |
2368 |
|
2369 |
(例) |
2370 |
|
2371 |
=begin original |
2372 |
|
2373 |
The LC_NUMERIC controls the numeric output: |
2374 |
|
2375 |
=end original |
2376 |
|
2377 |
LC_NUMERIC は数値出力を制御します: |
2378 |
|
2379 |
use locale; |
2380 |
use POSIX qw(locale_h); # Imports setlocale() and the LC_ constants. |
2381 |
setlocale(LC_NUMERIC, "fr_FR") or die "Pardon"; |
2382 |
printf "%g\n", 1.23; # If the "fr_FR" succeeded, probably shows 1,23. |
2383 |
|
2384 |
=begin original |
2385 |
|
2386 |
and also how strings are parsed by POSIX::strtod() as numbers: |
2387 |
|
2388 |
=end original |
2389 |
|
2390 |
そして文字列が POSIX::strtod() によってどのように数値としてパースされるかも |
2391 |
制御します: |
2392 |
|
2393 |
use locale; |
2394 |
use POSIX qw(locale_h strtod); |
2395 |
setlocale(LC_NUMERIC, "de_DE") or die "Entschuldigung"; |
2396 |
my $x = strtod("2,34") + 5; |
2397 |
print $x, "\n"; # Probably shows 7,34. |
2398 |
|
2399 |
=head1 NOTES |
2400 |
|
2401 |
(注意) |
2402 |
|
2403 |
=head2 Backward compatibility |
2404 |
|
2405 |
(過去互換性) |
2406 |
|
2407 |
=begin original |
2408 |
|
2409 |
Versions of Perl prior to 5.004 B<mostly> ignored locale information, |
2410 |
generally behaving as if something similar to the C<"C"> locale were |
2411 |
always in force, even if the program environment suggested otherwise |
2412 |
(see L<The setlocale function>). By default, Perl still behaves this |
2413 |
way for backward compatibility. If you want a Perl application to pay |
2414 |
attention to locale information, you B<must> use the S<C<use locale>> |
2415 |
pragma (see L<The use locale pragma>) or, in the unlikely event |
2416 |
that you want to do so for just pattern matching, the |
2417 |
C</l> regular expression modifier (see L<perlre/Character set |
2418 |
modifiers>) to instruct it to do so. |
2419 |
|
2420 |
=end original |
2421 |
|
2422 |
5.004 より前のバージョンの Perl では、B<ほとんど> ロケール情報を無視して、 |
2423 |
たとえプログラム環境が別のものを指示していたとしても常に C<"C"> ロケール |
2424 |
(L<The setlocale function> を参照) が強制されているかのように |
2425 |
振る舞っていました。 |
2426 |
デフォルトでは、Perl は今でもこのように動作するので、過去互換性があります。 |
2427 |
Perl アプリケーションをロケール情報に注目するようにしたいのなら、 |
2428 |
S<C<use locale>> プラグマ(L<The use locale pragma> を参照)あるいは、 |
2429 |
あまりなさそうな上京ですが単に正規表現でそうしたいなら、C</l> 正規表現修飾子 |
2430 |
(L<perlre/Character set modifiers> 参照) を B<使わなければなりません>。 |
2431 |
|
2432 |
=begin original |
2433 |
|
2434 |
Versions of Perl from 5.002 to 5.003 did use the C<LC_CTYPE> |
2435 |
information if available; that is, C<\w> did understand what |
2436 |
were the letters according to the locale environment variables. |
2437 |
The problem was that the user had no control over the feature: |
2438 |
if the C library supported locales, Perl used them. |
2439 |
|
2440 |
=end original |
2441 |
|
2442 |
5.002 から 5.003 の Perl は、使用可能である場合には C<LC_CTYPE> の情報を |
2443 |
使っていました; つまり、C<\w> はロケールの環境変数に従った文字を |
2444 |
理解していたのです。 |
2445 |
問題は、C ライブラリがロケールをサポートしている場合には Perl がそれを |
2446 |
使ってしまい、ユーザーがこの機能を制御できないということでした。 |
2447 |
|
2448 |
=head2 I18N:Collate obsolete |
2449 |
|
2450 |
(I18N:Collate は古いもの) |
2451 |
|
2452 |
=begin original |
2453 |
|
2454 |
In versions of Perl prior to 5.004, per-locale collation was possible |
2455 |
using the C<I18N::Collate> library module. This module is now mildly |
2456 |
obsolete and should be avoided in new applications. The C<LC_COLLATE> |
2457 |
functionality is now integrated into the Perl core language: One can |
2458 |
use locale-specific scalar data completely normally with C<use locale>, |
2459 |
so there is no longer any need to juggle with the scalar references of |
2460 |
C<I18N::Collate>. |
2461 |
|
2462 |
=end original |
2463 |
|
2464 |
5.004 より前のバージョンの Perl では、ロケール毎の照合は C<I18N::Collate> |
2465 |
ライブラリモジュールを使うことで可能でした。 |
2466 |
このモジュールは現在、やや時代遅れとなっていて、新しいアプリケーションでは |
2467 |
使用を避けるべきものです。 |
2468 |
現在、C<LC_COLLATE> 機能は Perl のコア言語に統合されました: |
2469 |
スカラデータのロケール固有の比較は C<use locale> を使うことで完全に |
2470 |
行なわれます; このため、C<I18N::Collate> のスカラリファレンスを使って |
2471 |
お手玉する必要はもはやないのです。 |
2472 |
|
2473 |
=head2 Sort speed and memory use impacts |
2474 |
|
2475 |
(ソートの速度とメモリ使用に与える影響) |
2476 |
|
2477 |
=begin original |
2478 |
|
2479 |
Comparing and sorting by locale is usually slower than the default |
2480 |
sorting; slow-downs of two to four times have been observed. It will |
2481 |
also consume more memory: once a Perl scalar variable has participated |
2482 |
in any string comparison or sorting operation obeying the locale |
2483 |
collation rules, it will take 3-15 times more memory than before. (The |
2484 |
exact multiplier depends on the string's contents, the operating system |
2485 |
and the locale.) These downsides are dictated more by the operating |
2486 |
system's implementation of the locale system than by Perl. |
2487 |
|
2488 |
=end original |
2489 |
|
2490 |
ロケールによる比較とソートは通常、デフォルトのソートに比べ二倍から |
2491 |
四倍遅くなります。 |
2492 |
また、メモリの使用量も増大します。 |
2493 |
Perl のスカラ変数がロケールの照合規則を使ったなんらかの文字列比較や |
2494 |
ソートの中で現れると、それによって以前より三倍から十五倍の時間を |
2495 |
要するようになります(実際のところの乗数は文字列の内容、オペレーティング |
2496 |
システム、ロケールに依存します)。 |
2497 |
この性能ダウンは、Perl によるものよりもオペレーティングシステムの |
2498 |
ロケールシステムの実装によるものが顕著に現れます。 |
2499 |
|
2500 |
=head2 write() and LC_NUMERIC |
2501 |
|
2502 |
(write() と LC_NUMERIC) |
2503 |
|
2504 |
=begin original |
2505 |
|
2506 |
If a program's environment specifies an LC_NUMERIC locale and C<use |
2507 |
locale> is in effect when the format is declared, the locale is used |
2508 |
to specify the decimal point character in formatted output. Formatted |
2509 |
output cannot be controlled by C<use locale> at the time when write() |
2510 |
is called. |
2511 |
|
2512 |
=end original |
2513 |
|
2514 |
プログラムの環境で LC_NUMERIC ロケールが指定されていて、フォーマットが |
2515 |
宣言されたときに C<use locale> が有効なら、書式指定された出力にある小数点の |
2516 |
文字は常にそこで指定されたものが使われます。 |
2517 |
書式指定された出力は、write() が呼び出された時点での C<use locale> によって |
2518 |
制御することはできません。 |
2519 |
|
2520 |
=head2 Freely available locale definitions |
2521 |
|
2522 |
(自由に利用可能なロケール定義) |
2523 |
|
2524 |
=begin original |
2525 |
|
2526 |
The Unicode CLDR project extracts the POSIX portion of many of its |
2527 |
locales, available at |
2528 |
|
2529 |
=end original |
2530 |
|
2531 |
The Unicode CLDR project extracts the POSIX portion of many of its |
2532 |
locales, available at |
2533 |
(TBT) |
2534 |
|
2535 |
http://unicode.org/Public/cldr/latest/ |
2536 |
|
2537 |
=begin original |
2538 |
|
2539 |
There is a large collection of locale definitions at: |
2540 |
|
2541 |
=end original |
2542 |
|
2543 |
ここにロケール定義の大規模なコレクションがあります: |
2544 |
|
2545 |
http://std.dkuug.dk/i18n/WG15-collection/locales/ |
2546 |
|
2547 |
=begin original |
2548 |
|
2549 |
You should be aware that it is |
2550 |
unsupported, and is not claimed to be fit for any purpose. If your |
2551 |
system allows installation of arbitrary locales, you may find the |
2552 |
definitions useful as they are, or as a basis for the development of |
2553 |
your own locales. |
2554 |
|
2555 |
=end original |
2556 |
|
2557 |
これがサポート無しのものであり、どんな目的にも適合するとは |
2558 |
主張していないものであることに注意すべきです。 |
2559 |
あなたの使うシステムがロケール機能のインストールを許しているのであれば、 |
2560 |
この場所で便利な定義を見つけることができるでしょうし、あるいは自分で |
2561 |
ロケールを定義する基礎となるようなものを見つけられるかもしれません。 |
2562 |
|
2563 |
=head2 I18n and l10n |
2564 |
|
2565 |
(I18n と l10n) |
2566 |
|
2567 |
=begin original |
2568 |
|
2569 |
"Internationalization" is often abbreviated as B<i18n> because its first |
2570 |
and last letters are separated by eighteen others. (You may guess why |
2571 |
the internalin ... internaliti ... i18n tends to get abbreviated.) In |
2572 |
the same way, "localization" is often abbreviated to B<l10n>. |
2573 |
|
2574 |
=end original |
2575 |
|
2576 |
"Internationalization" (国際化)はその最初と最後の文字、そしてその間にある |
2577 |
文字数から B<i18n> としばしば略されます。 |
2578 |
(You may guess why |
2579 |
the internalin ... internaliti ... i18n tends to get abbreviated.) |
2580 |
同様のやり方で、"localization" もしばしば B<l10n> と省略されます。 |
2581 |
(TBT) |
2582 |
|
2583 |
=head2 An imperfect standard |
2584 |
|
2585 |
(不完全な標準) |
2586 |
|
2587 |
=begin original |
2588 |
|
2589 |
Internationalization, as defined in the C and POSIX standards, can be |
2590 |
criticized as incomplete, ungainly, and having too large a granularity. |
2591 |
(Locales apply to a whole process, when it would arguably be more useful |
2592 |
to have them apply to a single thread, window group, or whatever.) They |
2593 |
also have a tendency, like standards groups, to divide the world into |
2594 |
nations, when we all know that the world can equally well be divided |
2595 |
into bankers, bikers, gamers, and so on. |
2596 |
|
2597 |
=end original |
2598 |
|
2599 |
国際対応は標準 C や標準 POSIX に定義されているように、不完全で、扱いにくく、 |
2600 |
粒度が大きすぎると酷評されます。 |
2601 |
(ロケールは、単一のスレッドであるとか、ウィンドウグループといったものに対して |
2602 |
適用するのが便利であるときにもプロセス全体に適用されます)。 |
2603 |
また、 |
2604 |
when we all know that the world can equally well be divided |
2605 |
into bankers, bikers, gamers, and so on |
2606 |
標準化グループに似て、世界を国に分割しようとする傾向があります。 |
2607 |
(TBT) |
2608 |
|
2609 |
=head1 Unicode and UTF-8 |
2610 |
|
2611 |
(Unicode と UTF-8) |
2612 |
|
2613 |
=begin original |
2614 |
|
2615 |
The support of Unicode is new starting from Perl version v5.6, and more fully |
2616 |
implemented in version v5.8 and later. See L<perluniintro>. It is |
2617 |
strongly recommended that when combining Unicode and locale (starting in |
2618 |
v5.16), you use |
2619 |
|
2620 |
=end original |
2621 |
|
2622 |
Unicode 対応は Perl バージョン 5.6 から始まり、バージョン 5.8 以降でより |
2623 |
完全に実装されました。 |
2624 |
L<perluniintro> を参照してください。 |
2625 |
It is |
2626 |
strongly recommended that when combining Unicode and locale (starting in |
2627 |
v5.16), you use |
2628 |
(TBT) |
2629 |
|
2630 |
use locale ':not_characters'; |
2631 |
|
2632 |
=begin original |
2633 |
|
2634 |
When this form of the pragma is used, only the non-character portions of |
2635 |
locales are used by Perl, for example C<LC_NUMERIC>. Perl assumes that |
2636 |
you have translated all the characters it is to operate on into Unicode |
2637 |
(actually the platform's native character set (ASCII or EBCDIC) plus |
2638 |
Unicode). For data in files, this can conveniently be done by also |
2639 |
specifying |
2640 |
|
2641 |
=end original |
2642 |
|
2643 |
When this form of the pragma is used, only the non-character portions of |
2644 |
locales are used by Perl, for example C<LC_NUMERIC>. Perl assumes that |
2645 |
you have translated all the characters it is to operate on into Unicode |
2646 |
(actually the platform's native character set (ASCII or EBCDIC) plus |
2647 |
Unicode). For data in files, this can conveniently be done by also |
2648 |
specifying |
2649 |
(TBT) |
2650 |
|
2651 |
use open ':locale'; |
2652 |
|
2653 |
=begin original |
2654 |
|
2655 |
This pragma arranges for all inputs from files to be translated into |
2656 |
Unicode from the current locale as specified in the environment (see |
2657 |
L</ENVIRONMENT>), and all outputs to files to be translated back |
2658 |
into the locale. (See L<open>). On a per-filehandle basis, you can |
2659 |
instead use the L<PerlIO::locale> module, or the L<Encode::Locale> |
2660 |
module, both available from CPAN. The latter module also has methods to |
2661 |
ease the handling of C<ARGV> and environment variables, and can be used |
2662 |
on individual strings. Also, if you know that all your locales will be |
2663 |
UTF-8, as many are these days, you can use the L<B<-C>|perlrun/-C> |
2664 |
command line switch. |
2665 |
|
2666 |
=end original |
2667 |
|
2668 |
This pragma arranges for all inputs from files to be translated into |
2669 |
Unicode from the current locale as specified in the environment (see |
2670 |
L</ENVIRONMENT>), and all outputs to files to be translated back |
2671 |
into the locale. (See L<open>). On a per-filehandle basis, you can |
2672 |
instead use the L<PerlIO::locale> module, or the L<Encode::Locale> |
2673 |
module, both available from CPAN. The latter module also has methods to |
2674 |
ease the handling of C<ARGV> and environment variables, and can be used |
2675 |
on individual strings. Also, if you know that all your locales will be |
2676 |
UTF-8, as many are these days, you can use the L<B<-C>|perlrun/-C> |
2677 |
command line switch. |
2678 |
(TBT) |
2679 |
|
2680 |
=begin original |
2681 |
|
2682 |
This form of the pragma allows essentially seamless handling of locales |
2683 |
with Unicode. The collation order will be Unicode's. It is strongly |
2684 |
recommended that when you need to order and sort strings that you use |
2685 |
the standard module L<Unicode::Collate> which gives much better results |
2686 |
in many instances than you can get with the old-style locale handling. |
2687 |
|
2688 |
=end original |
2689 |
|
2690 |
This form of the pragma allows essentially seamless handling of locales |
2691 |
with Unicode. The collation order will be Unicode's. It is strongly |
2692 |
recommended that when you need to order and sort strings that you use |
2693 |
the standard module L<Unicode::Collate> which gives much better results |
2694 |
in many instances than you can get with the old-style locale handling. |
2695 |
(TBT) |
2696 |
|
2697 |
=begin original |
2698 |
|
2699 |
For pre-v5.16 Perls, or if you use the locale pragma without the |
2700 |
C<:not_characters> parameter, Perl tries to work with both Unicode and |
2701 |
locales--but there are problems. |
2702 |
|
2703 |
=end original |
2704 |
|
2705 |
For pre-v5.16 Perls, or if you use the locale pragma without the |
2706 |
C<:not_characters> parameter, |
2707 |
Perl は Unicode とロケールを同時に動作させようとします -- しかし、 |
2708 |
問題があります。 |
2709 |
(TBT) |
2710 |
|
2711 |
=begin original |
2712 |
|
2713 |
Perl does not handle multi-byte locales in this case, such as have been |
2714 |
used for various |
2715 |
Asian languages, such as Big5 or Shift JIS. However, the increasingly |
2716 |
common multi-byte UTF-8 locales, if properly implemented, may work |
2717 |
reasonably well (depending on your C library implementation) in this |
2718 |
form of the locale pragma, simply because both |
2719 |
they and Perl store characters that take up multiple bytes the same way. |
2720 |
However, some, if not most, C library implementations may not process |
2721 |
the characters in the upper half of the Latin-1 range (128 - 255) |
2722 |
properly under LC_CTYPE. To see if a character is a particular type |
2723 |
under a locale, Perl uses the functions like C<isalnum()>. Your C |
2724 |
library may not work for UTF-8 locales with those functions, instead |
2725 |
only working under the newer wide library functions like C<iswalnum()>. |
2726 |
|
2727 |
=end original |
2728 |
|
2729 |
Perl は、Big5 や Shift JIS のような、様々なアジア言語で使われているような |
2730 |
マルチバイトロケールは扱いません。 |
2731 |
しかし、徐々に一般的になっているマルチバイトロケールは、適切に |
2732 |
実装されていれば、この形式の locale プラグマで十分にうまく動くかもしれません |
2733 |
(depending on your C library implementation); 単にこれらと |
2734 |
Perl はマルチバイトになる文字を同じ方法で保管するからです。 |
2735 |
However, some, if not most, C library implementations may not process |
2736 |
the characters in the upper half of the Latin-1 range (128 - 255) |
2737 |
properly under LC_CTYPE. To see if a character is a particular type |
2738 |
under a locale, Perl uses the functions like C<isalnum()>. Your C |
2739 |
library may not work for UTF-8 locales with those functions, instead |
2740 |
only working under the newer wide library functions like C<iswalnum()>. |
2741 |
(TBT) |
2742 |
|
2743 |
=begin original |
2744 |
|
2745 |
Perl generally takes the tack to use locale rules on code points that can fit |
2746 |
in a single byte, and Unicode rules for those that can't (though this |
2747 |
isn't uniformly applied, see the note at the end of this section). This |
2748 |
prevents many problems in locales that aren't UTF-8. Suppose the locale |
2749 |
is ISO8859-7, Greek. The character at 0xD7 there is a capital Chi. But |
2750 |
in the ISO8859-1 locale, Latin1, it is a multiplication sign. The POSIX |
2751 |
regular expression character class C<[[:alpha:]]> will magically match |
2752 |
0xD7 in the Greek locale but not in the Latin one. |
2753 |
|
2754 |
=end original |
2755 |
|
2756 |
Perl は一般的にシングルバイトに合う符号位置のロケールルールを使い、 |
2757 |
とり、それが出来ないときは Unicode のルールを使う方針をとります |
2758 |
(しかしこれは以前には一様に適用されません; see the note at the end of this section)。 |
2759 |
これは UTF-8 でないロケールでの多くの問題を防ぎます。 |
2760 |
ロケールがギリシャ語の ISO8859-7 であると仮定します。 |
2761 |
0xD7 の文字は capital Chi です。 |
2762 |
しかし Latin1 である ISO8859-1 ロケールでは、これは乗算記号です。 |
2763 |
POSIX 正規表現文字クラス C<[[:alpha:]]> はマジカルに、ギリシャ語ロケールでは |
2764 |
0xD7 にマッチングするけれども Latin ロケールではマッチングしません。 |
2765 |
(TBT) |
2766 |
|
2767 |
=begin original |
2768 |
|
2769 |
However, there are places where this breaks down. Certain constructs are |
2770 |
for Unicode only, such as C<\p{Alpha}>. They assume that 0xD7 always has its |
2771 |
Unicode meaning (or the equivalent on EBCDIC platforms). Since Latin1 is a |
2772 |
subset of Unicode and 0xD7 is the multiplication sign in both Latin1 and |
2773 |
Unicode, C<\p{Alpha}> will never match it, regardless of locale. A similar |
2774 |
issue occurs with C<\N{...}>. It is therefore a bad idea to use C<\p{}> or |
2775 |
C<\N{}> under plain C<use locale>--I<unless> you can guarantee that the |
2776 |
locale will be a ISO8859-1. Use POSIX character classes instead. |
2777 |
|
2778 |
=end original |
2779 |
|
2780 |
しかし、これを分解してみます。 |
2781 |
C<\p{Alpha}> のような一部の構造は Unicode のみです。 |
2782 |
これらは 0xD7 は常に Unicode での意味 (あるいは EBCDIC プラットフォームでの |
2783 |
等価物) を持つと仮定します。 |
2784 |
Latin1 は Unicode の部分集合でであり、0xD7 は Latin1 と Unicode の両方で |
2785 |
乗算記号なので、ロケールに関わらず C<\p{Alpha}> はマッチングしません。 |
2786 |
同じような問題は C<\N{...}> で起こります。 |
2787 |
従って生の C<use locale> で C<\p{}> や C<\N{}> を使うのは悪い考えです -- |
2788 |
ロケールが ISO8859-1 であることを I<保証できないかぎり> です。 |
2789 |
代わりに POSIX 文字クラスを使ってください。 |
2790 |
|
2791 |
=begin original |
2792 |
|
2793 |
Another problem with this approach is that operations that cross the |
2794 |
single byte/multiple byte boundary are not well-defined, and so are |
2795 |
disallowed. (This boundary is between the codepoints at 255/256.). |
2796 |
For example, lower casing LATIN CAPITAL LETTER Y WITH DIAERESIS (U+0178) |
2797 |
should return LATIN SMALL LETTER Y WITH DIAERESIS (U+00FF). But in the |
2798 |
Greek locale, for example, there is no character at 0xFF, and Perl |
2799 |
has no way of knowing what the character at 0xFF is really supposed to |
2800 |
represent. Thus it disallows the operation. In this mode, the |
2801 |
lowercase of U+0178 is itself. |
2802 |
|
2803 |
=end original |
2804 |
|
2805 |
Another problem with this approach is that operations that cross the |
2806 |
single byte/multiple byte boundary are not well-defined, and so are |
2807 |
disallowed. (This boundary is between the codepoints at 255/256.). |
2808 |
For example, lower casing LATIN CAPITAL LETTER Y WITH DIAERESIS (U+0178) |
2809 |
should return LATIN SMALL LETTER Y WITH DIAERESIS (U+00FF). But in the |
2810 |
Greek locale, for example, there is no character at 0xFF, and Perl |
2811 |
has no way of knowing what the character at 0xFF is really supposed to |
2812 |
represent. Thus it disallows the operation. In this mode, the |
2813 |
lowercase of U+0178 is itself. |
2814 |
(TBT) |
2815 |
|
2816 |
=begin original |
2817 |
|
2818 |
The same problems ensue if you enable automatic UTF-8-ification of your |
2819 |
standard file handles, default C<open()> layer, and C<@ARGV> on non-ISO8859-1, |
2820 |
non-UTF-8 locales (by using either the B<-C> command line switch or the |
2821 |
C<PERL_UNICODE> environment variable; see L<perlrun>). |
2822 |
Things are read in as UTF-8, which would normally imply a Unicode |
2823 |
interpretation, but the presence of a locale causes them to be interpreted |
2824 |
in that locale instead. For example, a 0xD7 code point in the Unicode |
2825 |
input, which should mean the multiplication sign, won't be interpreted by |
2826 |
Perl that way under the Greek locale. This is not a problem |
2827 |
I<provided> you make certain that all locales will always and only be either |
2828 |
an ISO8859-1, or, if you don't have a deficient C library, a UTF-8 locale. |
2829 |
|
2830 |
=end original |
2831 |
|
2832 |
同じ問題は、(B<-C> コマンドラインオプションか C<PERL_UNICODE> 環境変数を |
2833 |
使って (L<perlrun> を参照してください)) ISO-8859-1 でも UTF-8 でもない |
2834 |
ロケールの標準ファイルハンドル、デフォルト C<open()> 層、C<@ARGV> の |
2835 |
自動 UTF-8 化を有効にしている場合にも起こります。 |
2836 |
これらは UTF-8 として読み込まれ、普通は暗黙に Unicode として |
2837 |
解釈されますが、ロケールの存在によって、代わりにそのロケールとして |
2838 |
解釈されます。 |
2839 |
例えば、Unicode 入力での符号位置 0xD7 は、乗算記号を意味するべきですが、 |
2840 |
ギリシャ語ロケールでは Perl はそのようには解釈しません。 |
2841 |
全てのロケールが常に ISO-8859-1 か、 |
2842 |
if you don't have a deficient C library, |
2843 |
UTF-8 ロケールの |
2844 |
どちらかだけであることが I<確実なら> 問題ではありません。 |
2845 |
(TBT) |
2846 |
|
2847 |
=begin original |
2848 |
|
2849 |
Vendor locales are notoriously buggy, and it is difficult for Perl to test |
2850 |
its locale-handling code because this interacts with code that Perl has no |
2851 |
control over; therefore the locale-handling code in Perl may be buggy as |
2852 |
well. (However, the Unicode-supplied locales should be better, and |
2853 |
there is a feed back mechanism to correct any problems. See |
2854 |
L</Freely available locale definitions>.) |
2855 |
|
2856 |
=end original |
2857 |
|
2858 |
ベンダロケールはバグ持ちで悪名高く、これは Perl が制御できないコードと |
2859 |
相互作用するので、Perl がロケール操作コードをテストするのは困難です; |
2860 |
従って Perl のロケール操作コードは同様にバグ持ちかもしれません。 |
2861 |
(However, the Unicode-supplied locales should be better, and |
2862 |
there is a feed back mechanism to correct any problems. See |
2863 |
L</Freely available locale definitions>.) |
2864 |
(TBT) |
2865 |
|
2866 |
=begin original |
2867 |
|
2868 |
If you have Perl v5.16, the problems mentioned above go away if you use |
2869 |
the C<:not_characters> parameter to the locale pragma (except for vendor |
2870 |
bugs in the non-character portions). If you don't have v5.16, and you |
2871 |
I<do> have locales that work, using them may be worthwhile for certain |
2872 |
specific purposes, as long as you keep in mind the gotchas already |
2873 |
mentioned. For example, if the collation for your locales works, it |
2874 |
runs faster under locales than under L<Unicode::Collate>; and you gain |
2875 |
access to such things as the local currency symbol and the names of the |
2876 |
months and days of the week. (But to hammer home the point, in v5.16, |
2877 |
you get this access without the downsides of locales by using the |
2878 |
C<:not_characters> form of the pragma.) |
2879 |
|
2880 |
=end original |
2881 |
|
2882 |
If you have Perl v5.16, the problems mentioned above go away if you use |
2883 |
the C<:not_characters> parameter to the locale pragma (except for vendor |
2884 |
bugs in the non-character portions). If you don't have v5.16, and you |
2885 |
動作するロケールが I<ある> なら、それを使うことは、既に言及した |
2886 |
コツを心に留めている限りは、ある種の特定の用途には価値があるかもしれません。 |
2887 |
例えば、ロケール下での照合が動作するなら、 |
2888 |
L<Unicode::Collate> 下でのロケールよりも高速に実行されます; |
2889 |
そしてローカルな通貨記号、月や週の名前のようなものへのアクセスを得ます。 |
2890 |
(But to hammer home the point, in v5.16, |
2891 |
you get this access without the downsides of locales by using the |
2892 |
C<:not_characters> form of the pragma.) |
2893 |
(TBT) |
2894 |
|
2895 |
=begin original |
2896 |
|
2897 |
Note: The policy of using locale rules for code points that can fit in a |
2898 |
byte, and Unicode rules for those that can't is not uniformly applied. |
2899 |
Pre-v5.12, it was somewhat haphazard; in v5.12 it was applied fairly |
2900 |
consistently to regular expression matching except for bracketed |
2901 |
character classes; in v5.14 it was extended to all regex matches; and in |
2902 |
v5.16 to the casing operations such as C<"\L"> and C<uc()>. For |
2903 |
collation, in all releases, the system's C<strxfrm()> function is called, |
2904 |
and whatever it does is what you get. |
2905 |
|
2906 |
=end original |
2907 |
|
2908 |
Note: The policy of using locale rules for code points that can fit in a |
2909 |
byte, and Unicode rules for those that can't is not uniformly applied. |
2910 |
Pre-v5.12, it was somewhat haphazard; in v5.12 it was applied fairly |
2911 |
consistently to regular expression matching except for bracketed |
2912 |
character classes; in v5.14 it was extended to all regex matches; and in |
2913 |
v5.16 to the casing operations such as C<"\L"> and C<uc()>. For |
2914 |
collation, in all releases, the system's C<strxfrm()> function is called, |
2915 |
and whatever it does is what you get. |
2916 |
(TBT) |
2917 |
|
2918 |
=head1 BUGS |
2919 |
|
2920 |
(バグ) |
2921 |
|
2922 |
=head2 Broken systems |
2923 |
|
2924 |
(壊れているシステム) |
2925 |
|
2926 |
=begin original |
2927 |
|
2928 |
In certain systems, the operating system's locale support |
2929 |
is broken and cannot be fixed or used by Perl. Such deficiencies can |
2930 |
and will result in mysterious hangs and/or Perl core dumps when |
2931 |
C<use locale> is in effect. When confronted with such a system, |
2932 |
please report in excruciating detail to <F<perlbug@perl.org>>, and |
2933 |
also contact your vendor: bug fixes may exist for these problems |
2934 |
in your operating system. Sometimes such bug fixes are called an |
2935 |
operating system upgrade. |
2936 |
|
2937 |
=end original |
2938 |
|
2939 |
幾つかのオペレーティングシステムにおける環境でのロケールサポートは、 |
2940 |
おかしなもので、Perl がそれに対処したり使ったりできないようなものです。 |
2941 |
そういった不完全なものは、C<use locale> が有効になったときに Perl を |
2942 |
不可思議なハングアップに導いたり、コアダンプをさせたりします。 |
2943 |
このようなシステムに直面した場合、詳しい状況を <F<perlbug@perl.org>> に |
2944 |
レポートし、そして使用しているシステムのベンダーに連絡してください: |
2945 |
問題の幾つかに対するバグフィックスがされているかもしれません。 |
2946 |
そういったバグ修正は、オペレーティングシステムのアップグレードと |
2947 |
呼ばれることがあります。 |
2948 |
|
2949 |
=head1 SEE ALSO |
2950 |
|
2951 |
L<I18N::Langinfo>, L<perluniintro>, L<perlunicode>, L<open>, |
2952 |
L<POSIX/isalnum>, L<POSIX/isalpha>, |
2953 |
L<POSIX/isdigit>, L<POSIX/isgraph>, L<POSIX/islower>, |
2954 |
L<POSIX/isprint>, L<POSIX/ispunct>, L<POSIX/isspace>, |
2955 |
L<POSIX/isupper>, L<POSIX/isxdigit>, L<POSIX/localeconv>, |
2956 |
L<POSIX/setlocale>, L<POSIX/strcoll>, L<POSIX/strftime>, |
2957 |
L<POSIX/strtod>, L<POSIX/strxfrm>. |
2958 |
|
2959 |
=head1 HISTORY |
2960 |
|
2961 |
=begin original |
2962 |
|
2963 |
Jarkko Hietaniemi's original F<perli18n.pod> heavily hacked by Dominic |
2964 |
Dunlop, assisted by the perl5-porters. Prose worked over a bit by |
2965 |
Tom Christiansen, and updated by Perl 5 porters. |
2966 |
|
2967 |
=end original |
2968 |
|
2969 |
Jarkko Hietaniemi の原文書 F<perli18n.pod> は perl5-porters の助けの元、 |
2970 |
Dominic Dunlop によって大きく変更されました。 |
2971 |
表現に関しては Tom Christiansen が少し作業をし、Perl 5 porters によって |
2972 |
更新されました。 |
2973 |
|
2974 |
=begin meta |
2975 |
|
2976 |
Translate: KIMURA Koichi |
2977 |
Update: SHIRAKATA Kentaro <argrath@ub32.org> (5.8.8-) |
2978 |
Status: in progress |
2979 |
|
2980 |
=end meta |
2981 |
|