fixed quote problem, and added \r\n to imap message
[squirrelmail.git] / functions / i18n.php
CommitLineData
1fd97780 1<?
2
3/**
4 ** i18n.php
5 **
6 ** This file contains variuos functions that are needed to do
7 ** internationalization of SquirrelMail.
8 **
9 ** Internally iso-8859-1 is used as character set. Other characters
10 ** are encoded using Unicode entities according to HTML 4.0.
173ed887 11 **
1fd97780 12 **/
13
14 $i18n_php = true;
15
d30d79f2 16 // This array specifies the available languages.
17 $languages[0]["NAME"] = "English";
18 $languages[0]["CODE"] = "en";
19 $languages[1]["NAME"] = "Norsk";
20 $languages[1]["CODE"] = "no";
907762bb 21 $languages[2]["NAME"] = "Deutcsh";
22 $languages[2]["CODE"] = "de";
e4ff0781 23 $languages[2]["NAME"] = "Russian KOI8-R";
24 $languages[2]["CODE"] = "ru";
d30d79f2 25
1fd97780 26 // Decodes a string to the internal encoding from the given charset
27 function charset_decode ($charset, $string) {
28 // All HTML special characters are 7 bit and can be replaced first
29 $string = htmlspecialchars ($string);
30
44139266 31 $charset = strtolower($charset);
1fd97780 32
33 if (ereg("iso-8859-(.*)", $charset, $res)) {
34 if ($res[1] == "1")
35 return charset_decode_iso_8859_1 ($string);
173ed887 36 if ($res[1] == "7")
37 return charset_decode_iso_8859_7 ($string);
1fd97780 38 else if ($res[1] == "15")
39 return charset_decode_iso_8859_15 ($string);
40 else
41 return charset_decode_iso_8859_default ($string);
42 } else if ($charset == "ns_4551-1") {
43 return charset_decode_ns_4551_1 ($string);
17ce8467 44 } else if ($charset == "koi8-r") {
45 return charset_decode_koi8r ($string);
209e2f82 46 } else
1fd97780 47 return $string;
48 }
49
50 // iso-8859-1 is the same as Latin 1 and is normally used
51 // in western europe.
52 function charset_decode_iso_8859_1 ($string) {
53 // This is only debug code as long as the internal
54 // character set is iso-8859-1
55
56 // Latin small letter o with stroke
d23e472b 57 $string = str_replace ("\370", "&#248;", $string);
1fd97780 58
59 return ($string);
60 }
61
0a86e9f3 62 // iso-8859-7 is Greek.
209e2f82 63 function charset_decode_iso_8859_7 ($string) {
173ed887 64 // Could not find Unicode equivalent of 0xA1 and 0xA2
65 // 0xA4, 0xA5, 0xAA, 0xAE, 0xD2 and 0xFF should not be used
66 $string = strtr($string, "\241\242\244\245\252\256\322\377",
67 "????????");
68
69 // Horizontal bar (parentheki pavla)
70 while (ereg("\257", $string))
d23e472b 71 $string = str_replace ("\257", "&#8213;", $string);
173ed887 72
73 // ISO-8859-7 characters from 11/04 (0xB4) to 11/06 (0xB6)
74 // These are Unicode 900-902
75 while (ereg("([\264-\266])", $string, $res)) {
0a86e9f3 76 $replace = "&#" . (ord($res[1])+720) . ";";
d23e472b 77 $string = str_replace($res[1], $replace, $string);
173ed887 78 }
79
80 // 11/07 (0xB7) Middle dot is the same in iso-8859-1
81
82 // ISO-8859-7 characters from 11/08 (0xB8) to 11/10 (0xBA)
83 // These are Unicode 900-902
84 while (ereg("([\270-\272])", $string, $res)) {
0a86e9f3 85 $replace = "&#" . (ord($res[1])+720) . ";";
d23e472b 86 $string = str_replace($res[1], $replace, $string);
173ed887 87 }
88
89 // 11/11 (0xBB) Right angle quotation mark is the same as in
90 // iso-8859-1
91
92 // And now the rest of the charset
93 while (ereg("([\273-\376])", $string, $res)) {
0a86e9f3 94 $replace = "&#" . (ord($res[1])+720) . ";";
d23e472b 95 $string = str_replace($res[1], $replace, $string);
173ed887 96 }
97
98 return $string;
99 }
100
1fd97780 101 // iso-8859-15 is Latin 15 and has very much the same use as Latin 1
102 // but has the Euro symbol and some characters needed for French.
103 function charset_decode_iso_8859_15 ($string) {
104 // Euro sign
d23e472b 105 $string = str_replace ("\244", "&#8364;", $string);
1fd97780 106 // Latin capital letter S with caron
d23e472b 107 $string = str_replace ("\244", "&#352;", $string);
1fd97780 108 // Latin small letter s with caron
d23e472b 109 $string = str_replace ("\250", "&#353;", $string);
1fd97780 110 // Latin capital letter Z with caron
d23e472b 111 $string = str_replace ("\264", "&#381;", $string);
1fd97780 112 // Latin small letter z with caron
d23e472b 113 $string = str_replace ("\270", "&#382;", $string);
1fd97780 114 // Latin capital ligature OE
d23e472b 115 $string = str_replace ("\274", "&#338;", $string);
1fd97780 116 // Latin small ligature oe
d23e472b 117 $string = str_replace ("\275", "&#339;", $string);
1fd97780 118 // Latin capital letter Y with diaeresis
d23e472b 119 $string = str_replace ("\276", "&#376;", $string);
1fd97780 120
121 return ($string);
122 }
123
17ce8467 124 // ISO-8859-15 is Cyrillic
125 function charset_decode_iso_8859_5 ($string) {
d23e472b 126 // Convert to KOI8-R, then return this decoded.
127 $string = convert_cyr_string($string, "i", "k");
128 return charset_decode_koi8r($string);
17ce8467 129 }
130
173ed887 131 // Remove all 8 bit characters from all other ISO-8859 character sets
1fd97780 132 function charset_decode_iso_8859_default ($string) {
133 return (strtr($string, "\240\241\242\243\244\245\246\247".
134 "\250\251\252\253\254\255\256\257".
135 "\260\261\262\263\264\265\266\267".
136 "\270\271\272\273\274\275\276\277".
137 "\300\301\302\303\304\305\306\307".
138 "\310\311\312\313\314\315\316\317".
139 "\320\321\322\323\324\325\326\327".
140 "\330\331\332\333\334\335\336\337".
141 "\340\341\342\343\344\345\346\347".
142 "\350\351\352\353\354\355\356\357".
143 "\360\361\362\363\364\365\366\367".
144 "\370\371\372\373\374\375\376\377",
145 "????????????????????????????????????????".
146 "????????????????????????????????????????".
147 "????????????????????????????????????????".
148 "????????"));
149
150 }
151
152 // This is the same as ISO-646-NO and is used by some
153 // Microsoft programs when sending Norwegian characters
154 function charset_decode_ns_4551_1 ($string) {
155 // These characters are:
156 // Latin capital letter AE
157 // Latin capital letter O with stroke
158 // Latin capital letter A with ring above
159 // and the same as small letters
160 return strtr ($string, "[\\]{|}", "");
161 }
162
17ce8467 163 // KOI8-R is used to encode Russian mail (Cyrrilic). Defined in RFC
164 // 1489.
165 function charset_decode_koi8r ($string) {
166 global $default_charset;
167
168 if ($default_charset == "koi8-r") {
169 return $string;
170 } else {
171 // Convert to Unicode HTML entities.
172 // This code is rather ineffective.
d23e472b 173 $string = str_replace("\200", "&#9472;", $string);
174 $string = str_replace("\201", "&#9474;", $string);
175 $string = str_replace("\202", "&#9484;", $string);
176 $string = str_replace("\203", "&#9488;", $string);
177 $string = str_replace("\204", "&#9492;", $string);
178 $string = str_replace("\205", "&#9496;", $string);
179 $string = str_replace("\206", "&#9500;", $string);
180 $string = str_replace("\207", "&#9508;", $string);
181 $string = str_replace("\210", "&#9516;", $string);
182 $string = str_replace("\211", "&#9524;", $string);
183 $string = str_replace("\212", "&#9532;", $string);
184 $string = str_replace("\213", "&#9600;", $string);
185 $string = str_replace("\214", "&#9604;", $string);
186 $string = str_replace("\215", "&#9608;", $string);
187 $string = str_replace("\216", "&#9612;", $string);
188 $string = str_replace("\217", "&#9616;", $string);
189 $string = str_replace("\220", "&#9617;", $string);
190 $string = str_replace("\221", "&#9618;", $string);
191 $string = str_replace("\222", "&#9619;", $string);
192 $string = str_replace("\223", "&#8992;", $string);
193 $string = str_replace("\224", "&#9632;", $string);
194 $string = str_replace("\225", "&#8729;", $string);
195 $string = str_replace("\226", "&#8730;", $string);
196 $string = str_replace("\227", "&#8776;", $string);
197 $string = str_replace("\230", "&#8804;", $string);
198 $string = str_replace("\231", "&#8805;", $string);
199 $string = str_replace("\232", "&#160;", $string);
200 $string = str_replace("\233", "&#8993;", $string);
201 $string = str_replace("\234", "&#176;", $string);
202 $string = str_replace("\235", "&#178;", $string);
203 $string = str_replace("\236", "&#183;", $string);
204 $string = str_replace("\237", "&#247;", $string);
205 $string = str_replace("\240", "&#9552;", $string);
206 $string = str_replace("\241", "&#9553;", $string);
207 $string = str_replace("\242", "&#9554;", $string);
208 $string = str_replace("\243", "&#1105;", $string);
209 $string = str_replace("\244", "&#9555;", $string);
210 $string = str_replace("\245", "&#9556;", $string);
211 $string = str_replace("\246", "&#9557;", $string);
212 $string = str_replace("\247", "&#9558;", $string);
213 $string = str_replace("\250", "&#9559;", $string);
214 $string = str_replace("\251", "&#9560;", $string);
215 $string = str_replace("\252", "&#9561;", $string);
216 $string = str_replace("\253", "&#9562;", $string);
217 $string = str_replace("\254", "&#9563;", $string);
218 $string = str_replace("\255", "&#9564;", $string);
219 $string = str_replace("\256", "&#9565;", $string);
220 $string = str_replace("\257", "&#9566;", $string);
221 $string = str_replace("\260", "&#9567;", $string);
222 $string = str_replace("\261", "&#9568;", $string);
223 $string = str_replace("\262", "&#9569;", $string);
224 $string = str_replace("\263", "&#1025;", $string);
225 $string = str_replace("\264", "&#9570;", $string);
226 $string = str_replace("\265", "&#9571;", $string);
227 $string = str_replace("\266", "&#9572;", $string);
228 $string = str_replace("\267", "&#9573;", $string);
229 $string = str_replace("\270", "&#9574;", $string);
230 $string = str_replace("\271", "&#9575;", $string);
231 $string = str_replace("\272", "&#9576;", $string);
232 $string = str_replace("\273", "&#9577;", $string);
233 $string = str_replace("\274", "&#9578;", $string);
234 $string = str_replace("\275", "&#9579;", $string);
235 $string = str_replace("\276", "&#9580;", $string);
236 $string = str_replace("\277", "&#169;", $string);
237 $string = str_replace("\300", "&#1102;", $string);
238 $string = str_replace("\301", "&#1072;", $string);
239 $string = str_replace("\302", "&#1073;", $string);
240 $string = str_replace("\303", "&#1094;", $string);
241 $string = str_replace("\304", "&#1076;", $string);
242 $string = str_replace("\305", "&#1077;", $string);
243 $string = str_replace("\306", "&#1092;", $string);
244 $string = str_replace("\307", "&#1075;", $string);
245 $string = str_replace("\310", "&#1093;", $string);
246 $string = str_replace("\311", "&#1080;", $string);
247 $string = str_replace("\312", "&#1081;", $string);
248 $string = str_replace("\313", "&#1082;", $string);
249 $string = str_replace("\314", "&#1083;", $string);
250 $string = str_replace("\315", "&#1084;", $string);
251 $string = str_replace("\316", "&#1085;", $string);
252 $string = str_replace("\317", "&#1086;", $string);
253 $string = str_replace("\320", "&#1087;", $string);
254 $string = str_replace("\321", "&#1103;", $string);
255 $string = str_replace("\322", "&#1088;", $string);
256 $string = str_replace("\323", "&#1089;", $string);
257 $string = str_replace("\324", "&#1090;", $string);
258 $string = str_replace("\325", "&#1091;", $string);
259 $string = str_replace("\326", "&#1078;", $string);
260 $string = str_replace("\327", "&#1074;", $string);
261 $string = str_replace("\330", "&#1100;", $string);
262 $string = str_replace("\331", "&#1099;", $string);
263 $string = str_replace("\332", "&#1079;", $string);
264 $string = str_replace("\333", "&#1096;", $string);
265 $string = str_replace("\334", "&#1101;", $string);
266 $string = str_replace("\335", "&#1097;", $string);
267 $string = str_replace("\336", "&#1095;", $string);
268 $string = str_replace("\337", "&#1098;", $string);
269 $string = str_replace("\340", "&#1070;", $string);
270 $string = str_replace("\341", "&#1040;", $string);
271 $string = str_replace("\342", "&#1041;", $string);
272 $string = str_replace("\343", "&#1062;", $string);
273 $string = str_replace("\344", "&#1044;", $string);
274 $string = str_replace("\345", "&#1045;", $string);
275 $string = str_replace("\346", "&#1060;", $string);
276 $string = str_replace("\347", "&#1043;", $string);
277 $string = str_replace("\350", "&#1061;", $string);
278 $string = str_replace("\351", "&#1048;", $string);
279 $string = str_replace("\352", "&#1049;", $string);
280 $string = str_replace("\353", "&#1050;", $string);
281 $string = str_replace("\354", "&#1051;", $string);
282 $string = str_replace("\355", "&#1052;", $string);
283 $string = str_replace("\356", "&#1053;", $string);
284 $string = str_replace("\357", "&#1054;", $string);
285 $string = str_replace("\360", "&#1055;", $string);
286 $string = str_replace("\361", "&#1071;", $string);
287 $string = str_replace("\362", "&#1056;", $string);
288 $string = str_replace("\363", "&#1057;", $string);
289 $string = str_replace("\364", "&#1058;", $string);
290 $string = str_replace("\365", "&#1059;", $string);
291 $string = str_replace("\366", "&#1046;", $string);
292 $string = str_replace("\367", "&#1042;", $string);
293 $string = str_replace("\370", "&#1068;", $string);
294 $string = str_replace("\371", "&#1067;", $string);
295 $string = str_replace("\372", "&#1047;", $string);
296 $string = str_replace("\373", "&#1064;", $string);
297 $string = str_replace("\374", "&#1069;", $string);
298 $string = str_replace("\375", "&#1065;", $string);
299 $string = str_replace("\376", "&#1063;", $string);
300 $string = str_replace("\377", "&#1066;", $string);
17ce8467 301
302 return $string;
303 }
304 }
305
1fd97780 306?>