]> git.deb.at Git - deb/packages.git/blob - lib/Packages/I18N/Languages.pm
Merge branch 'master' into debian-master
[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                 'km-kh'=> 'Khmer',
72                 ko     => '한국어',
73                 lt     => 'Lietuvių',
74                 nl     => 'Nederlands',
75                 "no"   => 'norsk (bokmål)',
76                 pl     => 'polski',
77                 pt     => 'Português (pt)',
78                 'pt-pt'=> 'Português (pt)',
79                 'pt-br'=> 'Português (br)',
80                 ro     => 'română',
81                 ru     => 'Русский',
82                 sk     => 'slovensky',
83                 sv     => 'svenska',
84                 'sv-se'=> 'svenska',
85                 sl     => 'slovenščina',
86                 tr     => 'Türkçe',
87                 uk     => 'українська',
88                 zh     => '中文',
89                 'zh-cn'=> '中文',
90                 'zh-hk'=> '正體中文',
91                 'zh-tw'=> '中文',
92                 );
93
94 # language directory name => Latin transliteration of the language name
95 # This is used for language names which consist entirely of non-Latin
96 # characters, to aid those that have browsers which cannot show different
97 # character sets at once.
98 my %translit = (
99                 ar => "Arabiya",
100                 bg => "Bəlgarski",
101                 el => "Ellinika",
102                 fa => "Farsi",
103                 hy => "hayeren",
104                 ja => "Nihongo",
105                 ko => "Hangul", # Not sure. "Hanguk-Mal" (=Spoken Korean)?
106                 ru => "Russkij",
107                 uk => "ukrajins'ka",
108                 zh => "Zhongwen",
109                 'zh-cn'=> "Zhongwen,简",
110                 'zh-hk'=> "Zhongwen,HK",
111                 'zh-tw'=> "Zhongwen,繁",
112                 );
113
114 # second transliteration table, used for languages starting with a latin
115 # diacritic letter
116 my %translit2 = (
117                  cs    => "cesky",
118 );
119
120 sub langcmp ($$) {
121   my ($first, $second) = @_;
122
123   # Handle sorting of non-latin characters
124   # If there is a transliteration for this language available, use it
125   $first = $translit{$first} if defined $translit{$first};
126   $second = $translit{$second} if defined $translit{$second};
127
128   # Then handle special cases (initial latin letters with diacritics)
129   $first = $translit2{$first} if defined $translit2{$first};
130   $second = $translit2{$second} if defined $translit2{$second};
131
132   # Put remaining entity-only names last in the list
133   if (substr($first,0,1) eq '&')
134   {
135     $first =~ s/^&/ZZZ&/;
136   }
137   if (substr($second,0,1) eq '&')
138   {
139     $second =~ s/^&/ZZZ&/;
140   }
141   #    There seems to be a bug with localization in
142   #    Perl 5.005 so we need those extra variables.
143   my ($ufirst, $usecond) = (uc($first), uc($second));
144   return $ufirst cmp $usecond;
145 }
146
147 sub get_selfname {
148     return $selflang{$_[0]} if exists $selflang{$_[0]};
149     return undef;
150 }
151
152 sub get_transliteration {
153     return $translit{$_[0]} if exists $translit{$_[0]};
154     return undef;
155 }
156
157 1;