1 | ###########################################################################
|
---|
2 | #
|
---|
3 | # lang.pm --
|
---|
4 | # A component of the Greenstone digital library software
|
---|
5 | # from the New Zealand Digital Library Project at the
|
---|
6 | # University of Waikato, New Zealand.
|
---|
7 | #
|
---|
8 | # Copyright (C) 1999 New Zealand Digital Library Project
|
---|
9 | #
|
---|
10 | # This program is free software; you can redistribute it and/or modify
|
---|
11 | # it under the terms of the GNU General Public License as published by
|
---|
12 | # the Free Software Foundation; either version 2 of the License, or
|
---|
13 | # (at your option) any later version.
|
---|
14 | #
|
---|
15 | # This program is distributed in the hope that it will be useful,
|
---|
16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
18 | # GNU General Public License for more details.
|
---|
19 | #
|
---|
20 | # You should have received a copy of the GNU General Public License
|
---|
21 | # along with this program; if not, write to the Free Software
|
---|
22 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
23 | #
|
---|
24 | ###########################################################################
|
---|
25 |
|
---|
26 | # this module translates language descriptions to and from
|
---|
27 | # the ISO 639 standard
|
---|
28 |
|
---|
29 | package lang;
|
---|
30 |
|
---|
31 | @trans = (["ab", "Abkhazian"], ["om", "Afan Oromo"],
|
---|
32 | ["om", "Oromo"], ["aa", "Afar"],
|
---|
33 | ["af", "Afrikaans"], ["sq", "Albanian"],
|
---|
34 | ["am", "Amharic"], ["ar", "Arabic"],
|
---|
35 | ["hy", "Armenian"], ["as", "Assamese"],
|
---|
36 | ["ay", "Aymara"], ["az", "Azerbaijani"],
|
---|
37 |
|
---|
38 | ["ba", "Bashkir"], ["eu", "Basque"],
|
---|
39 | ["bn", "Bengali"], ["bn", "Bangla"],
|
---|
40 | ["dz", "Bhutani"], ["bh", "Bihari"],
|
---|
41 | ["bi", "Bislama"], ["br", "Breton"],
|
---|
42 | ["bg", "Bulgarian"], ["my", "Burmese"],
|
---|
43 | ["be", "Byelorussian"],
|
---|
44 |
|
---|
45 | ["km", "Cambodian"], ["ca", "Catalan"],
|
---|
46 | ["zh", "Chinese"], ["co", "Corsican"],
|
---|
47 | ["hr", "Croatian"], ["cs", "Czech"],
|
---|
48 |
|
---|
49 | ["da", "Danish"], ["nl", "Dutch"],
|
---|
50 |
|
---|
51 | ["en", "English"], ["eo", "Esperanto"],
|
---|
52 | ["et", "Estonian"], ["fo", "Faroese"],
|
---|
53 | ["fj", "Fijian"], ["fi", "Finnish"],
|
---|
54 | ["fr", "French"], ["fy", "Frisian"],
|
---|
55 |
|
---|
56 | ["gl", "Galician"], ["ka", "Georgian"],
|
---|
57 | ["de", "German"], ["el", "Greek"],
|
---|
58 | ["kl", "Greenlandic"], ["gn", "Guarani"],
|
---|
59 | ["gu", "Gujarati"],
|
---|
60 |
|
---|
61 | ["ha", "Hausa"], ["iw", "Hebrew"],
|
---|
62 | ["hi", "Hindi"], ["hu", "Hungarian"],
|
---|
63 |
|
---|
64 | ["is", "Icelandic"], ["in", "Indonesian"],
|
---|
65 | ["ia", "Interlingua"], ["ie", "Interlingue"],
|
---|
66 | ["ik", "Inupiak"], ["ga", "Irish"],
|
---|
67 | ["it", "Italian"],
|
---|
68 |
|
---|
69 | ["ja", "Japanese"], ["jv", "Javanese"],
|
---|
70 |
|
---|
71 | ["kn", "Kannada"], ["ks", "Kashmiri"],
|
---|
72 | ["kk", "Kazakh"], ["rw", "Kinyarwanda"],
|
---|
73 | ["ky", "Kirghiz"], ["rn", "Kirundi"],
|
---|
74 | ["ko", "Korean"], ["ku", "Kurdish"],
|
---|
75 |
|
---|
76 | ["lo", "Laothian"], ["la", "Latin"],
|
---|
77 | ["lv", "Latvian"], ["lv", "Lettish"],
|
---|
78 | ["ln", "Lingala"], ["lt", "Lithuanian"],
|
---|
79 |
|
---|
80 | ["mk", "Macedonian"], ["mg", "Malagasy"],
|
---|
81 | ["ms", "Malay"], ["ml", "Malayalam"],
|
---|
82 | ["mt", "Maltese"], ["mi", "Maori"],
|
---|
83 | ["mr", "Marathi"], ["mo", "Moldavian"],
|
---|
84 | ["mn", "Mongolian"],
|
---|
85 |
|
---|
86 | ["na", "Nauru"], ["ne", "Nepali"],
|
---|
87 | ["no", "Norwegian"],
|
---|
88 |
|
---|
89 | ["oc", "Occitan"], ["or", "Oriya"],
|
---|
90 |
|
---|
91 | ["ps", "Pashto"], ["ps", "Pushto"],
|
---|
92 | ["fa", "Persian"], ["pl", "Polish"],
|
---|
93 | ["pt", "Portuguese"], ["pa", "Punjabi"],
|
---|
94 |
|
---|
95 | ["qu", "Quechua"],
|
---|
96 |
|
---|
97 | ["rm", "Rhaeto-Romance"], ["ro", "Romanian"],
|
---|
98 | ["ru", "Russian"],
|
---|
99 |
|
---|
100 | ["sm", "Samoan"], ["sg", "Sangho"],
|
---|
101 | ["sa", "Sanskrit"], ["gd", "Scots Gaelic"],
|
---|
102 | ["sr", "Serbian"], ["sh", "Serbo-Croatian"],
|
---|
103 | ["st", "Sesotho"], ["tn", "Setswana"],
|
---|
104 | ["sn", "Shona"], ["sd", "Sindhi"],
|
---|
105 | ["si", "Singhalese"], ["ss", "Siswati"],
|
---|
106 | ["sk", "Slovak"], ["sl", "Slovenian"],
|
---|
107 | ["so", "Somali"], ["es", "Spanish"],
|
---|
108 | ["su", "Sundanese"], ["sw", "Swahili"],
|
---|
109 | ["sv", "Swedish"],
|
---|
110 |
|
---|
111 | ["tl", "Tagalog"], ["tg", "Tajik"],
|
---|
112 | ["ta", "Tamil"], ["tt", "Tatar"],
|
---|
113 | ["te", "Telugu"], ["th", "Thai"],
|
---|
114 | ["bo", "Tibetan"], ["ti", "Tigrinya"],
|
---|
115 | ["to", "Tonga"], ["ts", "Tsonga"],
|
---|
116 | ["tr", "Turkish"], ["tk", "Turkmen"],
|
---|
117 | ["tw", "Twi"],
|
---|
118 |
|
---|
119 | ["uk", "Ukrainian"], ["ur", "Urdu"],
|
---|
120 | ["uz", "Uzbek"],
|
---|
121 |
|
---|
122 | ["vi", "Vietnamese"], ["vo", "Volapuk"],
|
---|
123 |
|
---|
124 | ["cy", "Welsh"], ["wo", "Wolof"],
|
---|
125 |
|
---|
126 | ["xh", "Xhosa"],
|
---|
127 |
|
---|
128 | ["ji", "Yiddish"], ["yo", "Yoruba"],
|
---|
129 |
|
---|
130 | ["zu", "Zulu"]);
|
---|
131 |
|
---|
132 |
|
---|
133 | sub one_english_to_iso639 {
|
---|
134 | my ($english) = @_;
|
---|
135 | my $iso639 = "";
|
---|
136 |
|
---|
137 | foreach $lang (@trans) {
|
---|
138 | my $code = $lang->[0];
|
---|
139 | my $enname = $lang->[1];
|
---|
140 | if ($english =~ /\s*($code|$enname)\s*$/i) {
|
---|
141 | # found the language
|
---|
142 | $iso639 = $code;
|
---|
143 | last;
|
---|
144 |
|
---|
145 | }
|
---|
146 | }
|
---|
147 |
|
---|
148 | return $iso639;
|
---|
149 | }
|
---|
150 |
|
---|
151 |
|
---|
152 | sub english_to_iso639 {
|
---|
153 | my ($englishlist) = @_;
|
---|
154 | my ($english);
|
---|
155 |
|
---|
156 | my @englishlist = split (",", $englishlist);
|
---|
157 | my @iso639list = ();
|
---|
158 |
|
---|
159 | foreach $english (@englishlist) {
|
---|
160 | push (@iso639list, &one_english_to_iso639($english));
|
---|
161 | }
|
---|
162 |
|
---|
163 | return join (",", @iso639list);
|
---|
164 | }
|
---|
165 |
|
---|
166 |
|
---|
167 | sub one_iso639_to_english {
|
---|
168 | my ($iso639) = @_;
|
---|
169 | my $english = "";
|
---|
170 |
|
---|
171 | foreach $lang (@trans) {
|
---|
172 | my $code = $lang->[0];
|
---|
173 | my $enname = $lang->[1];
|
---|
174 | if ($iso639 =~ /\s*($code|$enname)\s*$/i) {
|
---|
175 | # found the language
|
---|
176 | $english = $enname;
|
---|
177 | last;
|
---|
178 |
|
---|
179 | }
|
---|
180 | }
|
---|
181 |
|
---|
182 | return $enname;
|
---|
183 | }
|
---|
184 |
|
---|
185 |
|
---|
186 | sub iso639_to_english {
|
---|
187 | my ($iso639list) = @_;
|
---|
188 | my ($iso639);
|
---|
189 |
|
---|
190 | my @iso639list = split (",", $iso639list);
|
---|
191 | my @englishlist = ();
|
---|
192 |
|
---|
193 | foreach $iso639 (@iso639list) {
|
---|
194 | push (@englishlist, &one_iso639_to_english($iso639));
|
---|
195 | }
|
---|
196 |
|
---|
197 | return join (",", @englishlist);
|
---|
198 | }
|
---|
199 |
|
---|
200 |
|
---|
201 | 1;
|
---|