Comment clean-up: Remove $Id$, fix FSF address, copyright years
[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              bulgarian  => "bg",
18              catalan    => "ca",
19              czech      => "cs",
20              danish     => "da",
21              german     => "de",
22              greek      => "el",
23              esperanto  => "eo",
24              spanish    => "es",
25              finnish    => "fi",
26              french     => "fr",
27              croatian   => "hr",
28              hungarian  => "hu",
29              indonesian => "id",
30              italian    => "it",
31              japanese   => "ja",
32              korean     => "ko",
33              lithuanian => "lt",
34              dutch      => "nl",
35              norwegian  => "no",
36              polish     => "pl",
37              portuguese => "pt",
38              romanian   => "ro",
39              russian    => "ru",
40              swedish    => "sv",
41              slovene    => "sl",
42              slovak     => "sk",
43              turkish    => "tr",
44              chinese    => "zh",
45              );
46
47 # language directory name => native name of the language
48 # non-ASCII letters must be escaped (using entities)!
49 my %selflang = (
50                 ar     => 'عربية',
51                 bg     => 'Български',
52                 ca     => 'català',
53                 zh     => '中文',
54                 hr     => 'hrvatski',
55                 cs     => 'česky',
56                 da     => 'dansk',
57                 nl     => 'Nederlands',
58                 en     => 'English',
59                 eo     => 'Esperanto',
60                 fi     => 'suomi',
61                 fr     => 'français',
62                 de     => 'Deutsch',
63                 el     => 'Ελληνικά',
64                 hu     => 'magyar',
65                 id     => 'Indonesia',
66                 it     => 'Italiano',
67                 ja     => '日本語',
68                 ko     => '한국어',
69                 lt     => 'Lietuvių',
70                 "no"   => 'norsk (bokmål)',
71                 pl     => 'polski',
72                 pt_PT  => 'Português (pt)',
73                 pt_BR  => 'Português (br)',
74                 ro     => 'română',
75                 ru     => 'Русский',
76                 es     => 'español',
77                 sk     => 'slovak', #FIXME
78                 sv_SE  => 'svenska',
79                 sl     => 'slovenščina',
80                 tr     => 'Türkçe',
81                 uk     => 'ukrainian', #FIXME
82                 );
83
84 # language directory name => Latin transliteration of the language name
85 # This is used for language names which consist entirely of non-Latin
86 # characters, to aid those that have browsers which cannot show different
87 # character sets at once.
88 my %translit = (
89                 ar => "Arabiya",
90                 bg => "Bəlgarski",
91                 zh => "Zhongzu", # Not printed due to Chinese-specific code; kept for sort order
92                 el => "Ellinika",
93                 ja => "Nihongo",
94                 ko => "Hangul", # Not sure. "Hanguk-Mal" (=Spoken Korean)?
95                 ru => "Russkij",
96                 );
97
98 # second transliteration table, used for languages starting with a latin
99 # diacritic letter
100 my %translit2 = (
101                  cs    => "cesky",
102 );
103
104 sub langcmp ($$) {
105   my ($first, $second) = @_;
106
107   # Handle sorting of non-latin characters
108   # If there is a transliteration for this language available, use it
109   $first = $translit{$first} if defined $translit{$first};
110   $second = $translit{$second} if defined $translit{$second};
111
112   # Then handle special cases (initial latin letters with diacritics)
113   $first = $translit2{$first} if defined $translit2{$first};
114   $second = $translit2{$second} if defined $translit2{$second};
115
116   # Put remaining entity-only names last in the list
117   if (substr($first,0,1) eq '&')
118   {
119     $first =~ s/^&/ZZZ&/;
120   }
121   if (substr($second,0,1) eq '&')
122   {
123     $second =~ s/^&/ZZZ&/;
124   }
125   #    There seems to be a bug with localization in
126   #    Perl 5.005 so we need those extra variables.
127   my ($ufirst, $usecond) = (uc($first), uc($second));
128   return $ufirst cmp $usecond;
129 }
130
131 sub get_selfname {
132     return $selflang{$_[0]} if exists $selflang{$_[0]};
133     return undef;
134 }
135
136 sub get_transliteration {
137     return $translit{$_[0]} if exists $translit{$_[0]};
138     return undef;
139 }
140
141 1;