1 #-----------------------------------------------------------------------
5 Locale::Language - ISO two letter codes for language identification (ISO 639)
11 $lang = code2language('en'); # $lang gets 'English'
12 $code = language2code('French'); # $code gets 'fr'
14 @codes = all_language_codes();
15 @names = all_language_names();
19 #-----------------------------------------------------------------------
21 package Locale::Language;
25 #-----------------------------------------------------------------------
29 The C<Locale::Language> module provides access to the ISO two-letter
30 codes for identifying languages, as defined in ISO 639. You can either
31 access the codes via the L<conversion routines> (described below),
32 or via the two functions which return lists of all language codes or
37 #-----------------------------------------------------------------------
41 #-----------------------------------------------------------------------
42 # Public Global Variables
43 #-----------------------------------------------------------------------
44 use vars qw($VERSION @ISA @EXPORT);
45 $VERSION = sprintf("%d.%02d", q$Revision: 2.0 $ =~ /(\d+)\.(\d+)/);
47 @EXPORT = qw(&code2language &language2code
48 &all_language_codes &all_language_names );
50 #-----------------------------------------------------------------------
51 # Private Global Variables
52 #-----------------------------------------------------------------------
57 #=======================================================================
59 =head1 CONVERSION ROUTINES
61 There are two conversion routines: C<code2language()> and C<language2code()>.
67 This function takes a two letter language code and returns a string
68 which contains the name of the language identified. If the code is
69 not a valid language code, as defined by ISO 639, then C<undef>
72 $lang = code2language($code);
76 This function takes a language name and returns the corresponding
77 two letter language code, if such exists.
78 If the argument could not be identified as a language name,
79 then C<undef> will be returned.
81 $code = language2code('French');
83 The case of the language name is not important.
84 See the section L<KNOWN BUGS AND LIMITATIONS> below.
90 #=======================================================================
96 return undef unless defined $code;
98 if (exists $CODES{$code})
100 return $CODES{$code};
104 #---------------------------------------------------------------
105 # no such language code!
106 #---------------------------------------------------------------
116 return undef unless defined $lang;
118 if (exists $LANGUAGES{$lang})
120 return $LANGUAGES{$lang};
124 #---------------------------------------------------------------
126 #---------------------------------------------------------------
131 #=======================================================================
133 =head1 QUERY ROUTINES
135 There are two function which can be used to obtain a list of all
136 language codes, or all language names:
140 =item C<all_language_codes()>
142 Returns a list of all two-letter language codes.
143 The codes are guaranteed to be all lower-case,
144 and not in any particular order.
146 =item C<all_language_names()>
148 Returns a list of all language names for which there is a corresponding
149 two-letter language code. The names are capitalised, and not returned
150 in any particular order.
156 #=======================================================================
157 sub all_language_codes
162 sub all_language_names
164 return values %CODES;
167 #-----------------------------------------------------------------------
171 The following example illustrates use of the C<code2language()> function.
172 The user is prompted for a language code, and then told the corresponding
175 $| = 1; # turn off buffering
177 print "Enter language code: ";
178 chop($code = <STDIN>);
179 $lang = code2language($code);
182 print "$code = $lang\n";
186 print "'$code' is not a valid language code!\n";
189 =head1 KNOWN BUGS AND LIMITATIONS
195 In the current implementation, all data is read in when the
196 module is loaded, and then held in memory.
197 A lazy implementation would be more memory friendly.
201 Currently just supports the two letter language codes -
202 there are also three-letter codes, and numbers.
203 Would these be of any use to anyone?
211 =item Locale::Country
213 ISO codes for identification of country (ISO 3166).
214 Supports 2-letter, 3-letter, and numeric country codes.
218 ISO codes for identification of written scripts (ISO 15924).
220 =item Locale::Currency
222 ISO three letter codes for identification of currencies and funds (ISO 4217).
224 =item ISO 639:1988 (E/F)
226 Code for the representation of names of languages.
228 =item http://lcweb.loc.gov/standards/iso639-2/langhome.html
230 Home page for ISO 639-2.
237 Neil Bowers E<lt>neil@bowers.comE<gt>
241 Copyright (C) 2002, Neil Bowers.
243 Copyright (c) 1997-2001 Canon Research Centre Europe (CRE).
245 This module is free software; you can redistribute it and/or
246 modify it under the same terms as Perl itself.
250 #-----------------------------------------------------------------------
252 #=======================================================================
253 # initialisation code - stuff the DATA into the CODES hash
254 #=======================================================================
264 ($code, $language) = split(/:/, $_, 2);
265 $CODES{$code} = $language;
266 $LANGUAGES{"\L$language"} = $code;
392 oc:Occitan (post 1500)