2 # Locale::Script - ISO codes for script identification (ISO 15924)
4 # $Id: Script.pm,v 2.1 2002/02/06 04:07:10 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.1 $ =~ /(\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);
168 ($alpha2, $alpha3, $numeric, $script) = split(/:/, $_, 4);
170 $CODES->[LOCALE_CODE_ALPHA_2]->{$alpha2} = $script;
171 $COUNTRIES->[LOCALE_CODE_ALPHA_2]->{"\L$script"} = $alpha2;
175 $CODES->[LOCALE_CODE_ALPHA_3]->{$alpha3} = $script;
176 $COUNTRIES->[LOCALE_CODE_ALPHA_3]->{"\L$script"} = $alpha3;
181 $CODES->[LOCALE_CODE_NUMERIC]->{$numeric} = $script;
182 $COUNTRIES->[LOCALE_CODE_NUMERIC]->{"\L$script"} = $numeric;
194 bh:bhm:300:Brahmi (Ashoka)
201 bu:bug:367:Buginese (Makassar)
202 by:bys:550:Blissymbols
204 ch:chu:221:Old Church Slavonic
206 cm:cmn:402:Cypro-Minoan
208 cp:cpr:403:Cypriote syllabary
210 ds:dsr:250:Deserel (Mormon)
211 dv:dvn:315:Devanagari (Nagari)
212 ed:egd:070:Egyptian demotic
213 eg:egy:050:Egyptian hieroglyphs
214 eh:egh:060:Egyptian hieratic
216 eo:eos:210:Etruscan and Oscan
218 gl:glg:225:Glagolitic
222 ha:han:500:Han ideographs
225 hm:hmo:450:Pahawh Hmong
228 hu:hun:176:Old Hungarian runic
229 hv:hvn:175:Kok Turki runic
231 iv:ivl:610:Indus Valley
232 ja:jap:930:(alias for Han + Hiragana + Katakana)
233 jl:jlg:445:Cherokee syllabary
235 ka:kam:241:Georgian (Mxedruli)
236 kh:khn:931:(alias for Hangul + Han)
240 kr:krn:357:Karenni (Kayah Li)
241 ks:kst:305:Kharoshthi
242 kx:kax:240:Georgian (Xucuri)
244 lf:laf:215:Latin (Fraktur variant)
245 lg:lag:216:Latin (Gaelic variant)
247 lp:lpc:335:Lepcha (Rong)
250 mh:may:090:Mayan hieroglyphs
259 ph:phx:115:Phoenician
261 pl:pld:282:Pollard Phonetic
262 pq:pqd:295:Klingon plQaD
263 pr:prm:227:Old Permic
264 ps:pst:600:Phaistos Disk
265 rn:rnr:211:Runic (Germanic)
266 rr:rro:620:Rongo-rongo
267 sa:sar:110:South Arabian
269 sj:syj:137:Syriac (Jacobite variant)
270 sl:slb:440:Unified Canadian Aboriginal Syllabics
271 sn:syn:136:Syriac (Nestorian variant)
272 sw:sww:281:Shavian (Shaw)
273 sy:syr:135:Syriac (Estrangelo)
283 vs:vsp:280:Visible Speech
284 xa:xas:000:Cuneiform, Sumero-Akkadian
285 xf:xfa:105:Cuneiform, Old Persian
286 xk:xkn:412:(alias for Hiragana + Katakana)
287 xu:xug:106:Cuneiform, Ugaritic
289 zx:zxx:997:Unwritten language
290 zy:zyy:998:Undetermined script
291 zz:zzz:999:Uncoded script