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