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