2 # Locale::Script - ISO codes for script identification (ISO 15924)
4 # $Id: Script.pm,v 2.2 2002/07/10 16:33:28 neilb Exp $
7 package Locale::Script;
13 use Locale::Constants;
16 #-----------------------------------------------------------------------
17 # Public Global Variables
18 #-----------------------------------------------------------------------
19 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
20 $VERSION = sprintf("%d.%02d", q$Revision: 2.21 $ =~ /(\d+)\.(\d+)/);
22 @EXPORT = qw(code2script script2code
23 all_script_codes all_script_names
25 LOCALE_CODE_ALPHA_2 LOCALE_CODE_ALPHA_3 LOCALE_CODE_NUMERIC);
27 #-----------------------------------------------------------------------
28 # Private Global Variables
29 #-----------------------------------------------------------------------
34 #=======================================================================
36 # code2script ( CODE [, CODESET ] )
38 #=======================================================================
42 my $codeset = @_ > 0 ? shift : LOCALE_CODE_DEFAULT;
45 return undef unless defined $code;
47 #-------------------------------------------------------------------
48 # Make sure the code is in the right form before we use it
49 # to look up the corresponding script.
50 # We have to sprintf because the codes are given as 3-digits,
51 # with leading 0's. Eg 070 for Egyptian demotic.
52 #-------------------------------------------------------------------
53 if ($codeset == LOCALE_CODE_NUMERIC)
55 return undef if ($code =~ /\D/);
56 $code = sprintf("%.3d", $code);
63 if (exists $CODES->[$codeset]->{$code})
65 return $CODES->[$codeset]->{$code};
69 #---------------------------------------------------------------
70 # no such script code!
71 #---------------------------------------------------------------
77 #=======================================================================
79 # script2code ( SCRIPT [, CODESET ] )
81 #=======================================================================
85 my $codeset = @_ > 0 ? shift : LOCALE_CODE_DEFAULT;
88 return undef unless defined $script;
89 $script = lc($script);
90 if (exists $COUNTRIES->[$codeset]->{$script})
92 return $COUNTRIES->[$codeset]->{$script};
96 #---------------------------------------------------------------
98 #---------------------------------------------------------------
104 #=======================================================================
106 # script_code2code ( CODE, IN-CODESET, OUT-CODESET )
108 #=======================================================================
111 (@_ == 3) or croak "script_code2code() takes 3 arguments!";
120 return undef if $inset == $outset;
121 $script = code2script($code, $inset);
122 return undef if not defined $script;
123 $outcode = script2code($script, $outset);
128 #=======================================================================
132 #=======================================================================
135 my $codeset = @_ > 0 ? shift : LOCALE_CODE_DEFAULT;
137 return keys %{ $CODES->[$codeset] };
141 #=======================================================================
145 #=======================================================================
148 my $codeset = @_ > 0 ? shift : LOCALE_CODE_DEFAULT;
150 return values %{ $CODES->[$codeset] };
154 #=======================================================================
156 # initialisation code - stuff the DATA into the ALPHA2 hash
158 #=======================================================================
160 my ($alpha2, $alpha3, $numeric);
169 ($alpha2, $alpha3, $numeric, $script) = split(/:/, $_, 4);
171 $CODES->[LOCALE_CODE_ALPHA_2]->{$alpha2} = $script;
172 $COUNTRIES->[LOCALE_CODE_ALPHA_2]->{"\L$script"} = $alpha2;
176 $CODES->[LOCALE_CODE_ALPHA_3]->{$alpha3} = $script;
177 $COUNTRIES->[LOCALE_CODE_ALPHA_3]->{"\L$script"} = $alpha3;
182 $CODES->[LOCALE_CODE_NUMERIC]->{$numeric} = $script;
183 $COUNTRIES->[LOCALE_CODE_NUMERIC]->{"\L$script"} = $numeric;
197 bh:bhm:300:Brahmi (Ashoka)
204 bu:bug:367:Buginese (Makassar)
205 by:bys:550:Blissymbols
207 ch:chu:221:Old Church Slavonic
209 cm:cmn:402:Cypro-Minoan
211 cp:cpr:403:Cypriote syllabary
213 ds:dsr:250:Deserel (Mormon)
214 dv:dvn:315:Devanagari (Nagari)
215 ed:egd:070:Egyptian demotic
216 eg:egy:050:Egyptian hieroglyphs
217 eh:egh:060:Egyptian hieratic
219 eo:eos:210:Etruscan and Oscan
221 gl:glg:225:Glagolitic
225 ha:han:500:Han ideographs
228 hm:hmo:450:Pahawh Hmong
231 hu:hun:176:Old Hungarian runic
232 hv:hvn:175:Kok Turki runic
234 iv:ivl:610:Indus Valley
235 ja:jap:930:(alias for Han + Hiragana + Katakana)
236 jl:jlg:445:Cherokee syllabary
238 ka:kam:241:Georgian (Mxedruli)
239 kh:khn:931:(alias for Hangul + Han)
243 kr:krn:357:Karenni (Kayah Li)
244 ks:kst:305:Kharoshthi
245 kx:kax:240:Georgian (Xucuri)
247 lf:laf:215:Latin (Fraktur variant)
248 lg:lag:216:Latin (Gaelic variant)
250 lp:lpc:335:Lepcha (Rong)
253 mh:may:090:Mayan hieroglyphs
262 ph:phx:115:Phoenician
264 pl:pld:282:Pollard Phonetic
265 pq:pqd:295:Klingon plQaD
266 pr:prm:227:Old Permic
267 ps:pst:600:Phaistos Disk
268 rn:rnr:211:Runic (Germanic)
269 rr:rro:620:Rongo-rongo
270 sa:sar:110:South Arabian
272 sj:syj:137:Syriac (Jacobite variant)
273 sl:slb:440:Unified Canadian Aboriginal Syllabics
274 sn:syn:136:Syriac (Nestorian variant)
275 sw:sww:281:Shavian (Shaw)
276 sy:syr:135:Syriac (Estrangelo)
286 vs:vsp:280:Visible Speech
287 xa:xas:000:Cuneiform, Sumero-Akkadian
288 xf:xfa:105:Cuneiform, Old Persian
289 xk:xkn:412:(alias for Hiragana + Katakana)
290 xu:xug:106:Cuneiform, Ugaritic
292 zx:zxx:997:Unwritten language
293 zy:zyy:998:Undetermined script
294 zz:zzz:999:Uncoded script