1 package Locale::Codes::Language;
2 # Copyright (C) 2001 Canon Research Centre Europe (CRE).
3 # Copyright (C) 2002-2009 Neil Bowers
4 # Copyright (c) 2010-2011 Sullivan Beck
5 # This program is free software; you can redistribute it and/or modify it
6 # under the same terms as Perl itself.
15 use Locale::Codes::Constants;
16 use Locale::Codes::Language_Codes;
18 #=======================================================================
19 # Public Global Variables
20 #=======================================================================
22 our($VERSION,@ISA,@EXPORT,@EXPORT_OK);
26 @EXPORT = qw(code2language
37 my($code,$codeset) = @_;
38 $code = "" if (! $code);
40 $codeset = LOCALE_LANG_DEFAULT if (! defined($codeset) || $codeset eq "");
42 if ($codeset =~ /^\d+$/) {
43 if ($codeset == LOCALE_LANG_ALPHA_2) {
45 } elsif ($codeset == LOCALE_LANG_ALPHA_3) {
47 } elsif ($codeset == LOCALE_LANG_TERM) {
54 if ($codeset eq "alpha2" ||
55 $codeset eq "alpha3" ||
62 return (0,$code,$codeset);
65 #=======================================================================
67 # code2language ( CODE [,CODESET] )
69 #=======================================================================
72 my($err,$code,$codeset) = _code(@_);
73 return undef if ($err ||
76 return Locale::Codes::_code2name("language",$code,$codeset);
79 #=======================================================================
81 # language2code ( LANGUAGE [,CODESET] )
83 #=======================================================================
86 my($language,$codeset) = @_;
88 ($err,$tmp,$codeset) = _code("",$codeset);
89 return undef if ($err ||
92 return Locale::Codes::_name2code("language",$language,$codeset);
95 #=======================================================================
97 # language_code2code ( CODE,CODESET_IN,CODESET_OUT )
99 #=======================================================================
101 sub language_code2code {
102 (@_ == 3) or croak "language_code2code() takes 3 arguments!";
103 my($code,$inset,$outset) = @_;
105 ($err,$code,$inset) = _code($code,$inset);
106 return undef if ($err);
107 ($err,$tmp,$outset) = _code("",$outset);
108 return undef if ($err);
110 return Locale::Codes::_code2code("language",$code,$inset,$outset);
113 #=======================================================================
115 # all_language_codes ( [CODESET] )
117 #=======================================================================
119 sub all_language_codes {
122 ($err,$tmp,$codeset) = _code("",$codeset);
125 return Locale::Codes::_all_codes("language",$codeset);
129 #=======================================================================
131 # all_language_names ( [CODESET] )
133 #=======================================================================
135 sub all_language_names {
138 ($err,$tmp,$codeset) = _code("",$codeset);
141 return Locale::Codes::_all_names("language",$codeset);
144 #=======================================================================
146 # rename_language ( CODE,NAME [,CODESET] )
148 #=======================================================================
150 sub rename_language {
151 my($code,$new_name,@args) = @_;
153 $nowarn = 1, pop(@args) if (@args && $args[$#args] eq "nowarn");
154 my $codeset = shift(@args);
156 ($err,$code,$codeset) = _code($code,$codeset);
158 return Locale::Codes::_rename("language",$code,$new_name,$codeset,$nowarn);
161 #=======================================================================
163 # add_language ( CODE,NAME [,CODESET] )
165 #=======================================================================
168 my($code,$name,@args) = @_;
170 $nowarn = 1, pop(@args) if (@args && $args[$#args] eq "nowarn");
171 my $codeset = shift(@args);
173 ($err,$code,$codeset) = _code($code,$codeset);
175 return Locale::Codes::_add_code("language",$code,$name,$codeset,$nowarn);
178 #=======================================================================
180 # delete_language ( CODE [,CODESET] )
182 #=======================================================================
184 sub delete_language {
185 my($code,@args) = @_;
187 $nowarn = 1, pop(@args) if (@args && $args[$#args] eq "nowarn");
188 my $codeset = shift(@args);
190 ($err,$code,$codeset) = _code($code,$codeset);
192 return Locale::Codes::_delete_code("language",$code,$codeset,$nowarn);
195 #=======================================================================
197 # add_language_alias ( NAME,NEW_NAME )
199 #=======================================================================
201 sub add_language_alias {
202 my($name,$new_name,$nowarn) = @_;
203 $nowarn = (defined($nowarn) && $nowarn eq "nowarn" ? 1 : 0);
205 return Locale::Codes::_add_alias("language",$name,$new_name,$nowarn);
208 #=======================================================================
210 # delete_language_alias ( NAME )
212 #=======================================================================
214 sub delete_language_alias {
215 my($name,$nowarn) = @_;
216 $nowarn = (defined($nowarn) && $nowarn eq "nowarn" ? 1 : 0);
218 return Locale::Codes::_delete_alias("language",$name,$nowarn);
221 #=======================================================================
223 # rename_language_code ( CODE,NEW_CODE [,CODESET] )
225 #=======================================================================
227 sub rename_language_code {
228 my($code,$new_code,@args) = @_;
230 $nowarn = 1, pop(@args) if (@args && $args[$#args] eq "nowarn");
231 my $codeset = shift(@args);
233 ($err,$code,$codeset) = _code($code,$codeset);
234 ($err,$new_code,$codeset) = _code($new_code,$codeset) if (! $err);
236 return Locale::Codes::_rename_code("language",$code,$new_code,$codeset,$nowarn);
239 #=======================================================================
241 # add_language_code_alias ( CODE,NEW_CODE [,CODESET] )
243 #=======================================================================
245 sub add_language_code_alias {
246 my($code,$new_code,@args) = @_;
248 $nowarn = 1, pop(@args) if (@args && $args[$#args] eq "nowarn");
249 my $codeset = shift(@args);
251 ($err,$code,$codeset) = _code($code,$codeset);
252 ($err,$new_code,$codeset) = _code($new_code,$codeset) if (! $err);
254 return Locale::Codes::_add_code_alias("language",$code,$new_code,$codeset,$nowarn);
257 #=======================================================================
259 # delete_language_code_alias ( CODE [,CODESET] )
261 #=======================================================================
263 sub delete_language_code_alias {
264 my($code,@args) = @_;
266 $nowarn = 1, pop(@args) if (@args && $args[$#args] eq "nowarn");
267 my $codeset = shift(@args);
269 ($err,$code,$codeset) = _code($code,$codeset);
271 return Locale::Codes::_delete_code_alias("language",$code,$codeset,$nowarn);
277 # indent-tabs-mode: nil
278 # cperl-indent-level: 3
279 # cperl-continued-statement-offset: 2
280 # cperl-continued-brace-offset: 0
281 # cperl-brace-offset: 0
282 # cperl-brace-imaginary-offset: 0
283 # cperl-label-offset: -2