1Locale::Script(3pm) Perl Programmers Reference Guide Locale::Script(3pm)
2
3
4
6 Locale::Script - ISO codes for script identification (ISO 15924)
7
9 use Locale::Script;
10 use Locale::Constants;
11
12 $script = code2script('ph'); # 'Phoenician'
13 $code = script2code('Tibetan'); # 'bo'
14 $code3 = script2code('Tibetan',
15 LOCALE_CODE_ALPHA_3); # 'bod'
16 $codeN = script2code('Tibetan',
17 LOCALE_CODE_ALPHA_NUMERIC); # 330
18
19 @codes = all_script_codes();
20 @scripts = all_script_names();
21
23 The "Locale::Script" module provides access to the ISO codes for iden‐
24 tifying scripts, as defined in ISO 15924. For example, Egyptian hiero‐
25 glyphs are denoted by the two-letter code 'eg', the three-letter code
26 'egy', and the numeric code 050.
27
28 You can either access the codes via the conversion routines (described
29 below), or with the two functions which return lists of all script
30 codes or all script names.
31
32 There are three different code sets you can use for identifying
33 scripts:
34
35 alpha-2
36 Two letter codes, such as 'bo' for Tibetan. This code set is iden‐
37 tified with the symbol "LOCALE_CODE_ALPHA_2".
38
39 alpha-3
40 Three letter codes, such as 'ell' for Greek. This code set is
41 identified with the symbol "LOCALE_CODE_ALPHA_3".
42
43 numeric
44 Numeric codes, such as 410 for Hiragana. This code set is identi‐
45 fied with the symbol "LOCALE_CODE_NUMERIC".
46
47 All of the routines take an optional additional argument which speci‐
48 fies the code set to use. If not specified, it defaults to the two-
49 letter codes. This is partly for backwards compatibility (previous
50 versions of Locale modules only supported the alpha-2 codes), and
51 partly because they are the most widely used codes.
52
53 The alpha-2 and alpha-3 codes are not case-dependent, so you can use
54 'BO', 'Bo', 'bO' or 'bo' for Tibetan. When a code is returned by one
55 of the functions in this module, it will always be lower-case.
56
57 SPECIAL CODES
58
59 The standard defines various special codes.
60
61 · The standard reserves codes in the ranges qa - qt, qaa - qat, and
62 900 - 919, for private use.
63
64 · zx, zxx, and 997, are the codes for unwritten languages.
65
66 · zy, zyy, and 998, are the codes for an undetermined script.
67
68 · zz, zzz, and 999, are the codes for an uncoded script.
69
70 The private codes are not recognised by Locale::Script, but the others
71 are.
72
74 There are three conversion routines: "code2script()", "script2code()",
75 and "script_code2code()".
76
77 code2script( CODE, [ CODESET ] )
78 This function takes a script code and returns a string which con‐
79 tains the name of the script identified. If the code is not a
80 valid script code, as defined by ISO 15924, then "undef" will be
81 returned:
82
83 $script = code2script('cy'); # Cyrillic
84
85 script2code( STRING, [ CODESET ] )
86 This function takes a script name and returns the corresponding
87 script code, if such exists. If the argument could not be identi‐
88 fied as a script name, then "undef" will be returned:
89
90 $code = script2code('Gothic', LOCALE_CODE_ALPHA_3);
91 # $code will now be 'gth'
92
93 The case of the script name is not important. See the section
94 "KNOWN BUGS AND LIMITATIONS" below.
95
96 script_code2code( CODE, CODESET, CODESET )
97 This function takes a script code from one code set, and returns
98 the corresponding code from another code set.
99
100 $alpha2 = script_code2code('jwi',
101 LOCALE_CODE_ALPHA_3 => LOCALE_CODE_ALPHA_2);
102 # $alpha2 will now be 'jw' (Javanese)
103
104 If the code passed is not a valid script code in the first code
105 set, or if there isn't a code for the corresponding script in the
106 second code set, then "undef" will be returned.
107
109 There are two function which can be used to obtain a list of all codes,
110 or all script names:
111
112 "all_script_codes ( [ CODESET ] )"
113 Returns a list of all two-letter script codes. The codes are guar‐
114 anteed to be all lower-case, and not in any particular order.
115
116 "all_script_names ( [ CODESET ] )"
117 Returns a list of all script names for which there is a correspond‐
118 ing script code in the specified code set. The names are capi‐
119 talised, and not returned in any particular order.
120
122 The following example illustrates use of the "code2script()" function.
123 The user is prompted for a script code, and then told the corresponding
124 script name:
125
126 $⎪ = 1; # turn off buffering
127
128 print "Enter script code: ";
129 chop($code = <STDIN>);
130 $script = code2script($code, LOCALE_CODE_ALPHA_2);
131 if (defined $script)
132 {
133 print "$code = $script\n";
134 }
135 else
136 {
137 print "'$code' is not a valid script code!\n";
138 }
139
141 · When using "script2code()", the script name must currently appear
142 exactly as it does in the source of the module. For example,
143
144 script2code('Egyptian hieroglyphs')
145
146 will return eg, as expected. But the following will all return
147 "undef":
148
149 script2code('hieroglyphs')
150 script2code('Egyptian Hieroglypics')
151
152 If there's need for it, a future version could have variants for
153 script names.
154
155 · In the current implementation, all data is read in when the module
156 is loaded, and then held in memory. A lazy implementation would be
157 more memory friendly.
158
160 Locale::Language
161 ISO two letter codes for identification of language (ISO 639).
162
163 Locale::Currency
164 ISO three letter codes for identification of currencies and funds
165 (ISO 4217).
166
167 Locale::Country
168 ISO three letter codes for identification of countries (ISO 3166)
169
170 ISO 15924
171 The ISO standard which defines these codes.
172
173 http://www.evertype.com/standards/iso15924/
174 Home page for ISO 15924.
175
177 Neil Bowers <neil@bowers.com>
178
180 Copyright (c) 2002-2004 Neil Bowers.
181
182 This module is free software; you can redistribute it and/or modify it
183 under the same terms as Perl itself.
184
185
186
187perl v5.8.8 2001-09-21 Locale::Script(3pm)