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.2 $ =~ /(\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;
196 bh:bhm:300:Brahmi (Ashoka)
203 bu:bug:367:Buginese (Makassar)
204 by:bys:550:Blissymbols
206 ch:chu:221:Old Church Slavonic
208 cm:cmn:402:Cypro-Minoan
210 cp:cpr:403:Cypriote syllabary
212 ds:dsr:250:Deserel (Mormon)
213 dv:dvn:315:Devanagari (Nagari)
214 ed:egd:070:Egyptian demotic
215 eg:egy:050:Egyptian hieroglyphs
216 eh:egh:060:Egyptian hieratic
218 eo:eos:210:Etruscan and Oscan
220 gl:glg:225:Glagolitic
224 ha:han:500:Han ideographs
227 hm:hmo:450:Pahawh Hmong
230 hu:hun:176:Old Hungarian runic
231 hv:hvn:175:Kok Turki runic
233 iv:ivl:610:Indus Valley
234 ja:jap:930:(alias for Han + Hiragana + Katakana)
235 jl:jlg:445:Cherokee syllabary
237 ka:kam:241:Georgian (Mxedruli)
238 kh:khn:931:(alias for Hangul + Han)
242 kr:krn:357:Karenni (Kayah Li)
243 ks:kst:305:Kharoshthi
244 kx:kax:240:Georgian (Xucuri)
246 lf:laf:215:Latin (Fraktur variant)
247 lg:lag:216:Latin (Gaelic variant)
249 lp:lpc:335:Lepcha (Rong)
252 mh:may:090:Mayan hieroglyphs
261 ph:phx:115:Phoenician
263 pl:pld:282:Pollard Phonetic
264 pq:pqd:295:Klingon plQaD
265 pr:prm:227:Old Permic
266 ps:pst:600:Phaistos Disk
267 rn:rnr:211:Runic (Germanic)
268 rr:rro:620:Rongo-rongo
269 sa:sar:110:South Arabian
271 sj:syj:137:Syriac (Jacobite variant)
272 sl:slb:440:Unified Canadian Aboriginal Syllabics
273 sn:syn:136:Syriac (Nestorian variant)
274 sw:sww:281:Shavian (Shaw)
275 sy:syr:135:Syriac (Estrangelo)
285 vs:vsp:280:Visible Speech
286 xa:xas:000:Cuneiform, Sumero-Akkadian
287 xf:xfa:105:Cuneiform, Old Persian
288 xk:xkn:412:(alias for Hiragana + Katakana)
289 xu:xug:106:Cuneiform, Ugaritic
291 zx:zxx:997:Unwritten language
292 zy:zyy:998:Undetermined script
293 zz:zzz:999:Uncoded script