Convert remaining iso language codes
[deb/packages.git] / lib / Packages / I18N / Languages.pm
1 # Taken from the webwml CVS tree (english/templates/languages.wml)
2
3 package Packages::I18N::Languages;
4
5 use strict;
6 use warnings;
7
8 use Exporter;
9
10 our @ISA = qw( Exporter );
11 our @EXPORT = qw( langcmp get_transliteration get_selfname );
12
13 # language directory name => ISO 639 two-letter code for the language name
14 my %langs = (
15              english    => "en",
16              arabic     => "ar",
17              armenian   => "hy",
18              bulgarian  => "bg",
19              catalan    => "ca",
20              chinese    => "zh",
21              croatian   => "hr",
22              czech      => "cs",
23              danish     => "da",
24              dutch      => "nl",
25              german     => "de",
26              greek      => "el",
27              esperanto  => "eo",
28              spanish    => "es",
29              finnish    => "fi",
30              french     => "fr",
31              hungarian  => "hu",
32              indonesian => "id",
33              italian    => "it",
34              japanese   => "ja",
35              korean     => "ko",
36              lithuanian => "lt",
37              norwegian  => "no",
38              persian    => "fa",
39              polish     => "pl",
40              portuguese => "pt",
41              romanian   => "ro",
42              russian    => "ru",
43              swedish    => "sv",
44              slovene    => "sl",
45              slovak     => "sk",
46              turkish    => "tr",
47              );
48
49 # language directory name => native name of the language
50 # non-ASCII letters must be escaped (using entities)!
51 my %selflang = (
52                 ar     => 'عربية',
53                 bg     => 'Български',
54                 ca     => 'català',
55                 cs     => 'česky',
56                 da     => 'dansk',
57                 de     => 'Deutsch',
58                 el     => 'Ελληνικά',
59                 en     => 'English',
60                 eo     => 'Esperanto',
61                 es     => 'español',
62                 fa     => 'فارسی',
63                 fi     => 'suomi',
64                 fr     => 'français',
65                 hu     => 'magyar',
66                 hr     => 'hrvatski',
67                 hy     => 'Հայերեն',
68                 id     => 'Indonesia',
69                 it     => 'Italiano',
70                 ja     => '日本語',
71                 ko     => '한국어',
72                 lt     => 'Lietuvių',
73                 nl     => 'Nederlands',
74                 "no"   => 'norsk (bokmål)',
75                 pl     => 'polski',
76                 pt     => 'Português (pt)',
77                 'pt-pt'=> 'Português (pt)',
78                 'pt-br'=> 'Português (br)',
79                 ro     => 'română',
80                 ru     => 'Русский',
81                 sk     => 'slovensky',
82                 sv     => 'svenska',
83                 'sv-se'=> 'svenska',
84                 sl     => 'slovenščina',
85                 tr     => 'Türkçe',
86                 uk     => 'українська',
87                 zh     => '中文',
88                 'zh-cn'=> '中文',
89                 'zh-hk'=> '正體中文',
90                 'zh-tw'=> '中文',
91                 );
92
93 # language directory name => Latin transliteration of the language name
94 # This is used for language names which consist entirely of non-Latin
95 # characters, to aid those that have browsers which cannot show different
96 # character sets at once.
97 my %translit = (
98                 ar => "Arabiya",
99                 bg => "Bəlgarski",
100                 el => "Ellinika",
101                 fa => "Farsi",
102                 hy => "hayeren",
103                 ja => "Nihongo",
104                 ko => "Hangul", # Not sure. "Hanguk-Mal" (=Spoken Korean)?
105                 ru => "Russkij",
106                 uk => "ukrajins'ka",
107                 zh => "Zhongzu",
108                 'zh-cn'=> "Zhongzu,简",
109                 'zh-hk'=> "Zhongzu,HK",
110                 'zh-tw'=> "Zhongzu,繁",
111                 );
112
113 # second transliteration table, used for languages starting with a latin
114 # diacritic letter
115 my %translit2 = (
116                  cs    => "cesky",
117 );
118
119 sub langcmp ($$) {
120   my ($first, $second) = @_;
121
122   # Handle sorting of non-latin characters
123   # If there is a transliteration for this language available, use it
124   $first = $translit{$first} if defined $translit{$first};
125   $second = $translit{$second} if defined $translit{$second};
126
127   # Then handle special cases (initial latin letters with diacritics)
128   $first = $translit2{$first} if defined $translit2{$first};
129   $second = $translit2{$second} if defined $translit2{$second};
130
131   # Put remaining entity-only names last in the list
132   if (substr($first,0,1) eq '&')
133   {
134     $first =~ s/^&/ZZZ&/;
135   }
136   if (substr($second,0,1) eq '&')
137   {
138     $second =~ s/^&/ZZZ&/;
139   }
140   #    There seems to be a bug with localization in
141   #    Perl 5.005 so we need those extra variables.
142   my ($ufirst, $usecond) = (uc($first), uc($second));
143   return $ufirst cmp $usecond;
144 }
145
146 sub get_selfname {
147     return $selflang{$_[0]} if exists $selflang{$_[0]};
148     return undef;
149 }
150
151 sub get_transliteration {
152     return $translit{$_[0]} if exists $translit{$_[0]};
153     return undef;
154 }
155
156 1;