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", "ø", $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", "―", $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", "€", $string); |
1fd97780 |
106 | // Latin capital letter S with caron |
d23e472b |
107 | $string = str_replace ("\244", "Š", $string); |
1fd97780 |
108 | // Latin small letter s with caron |
d23e472b |
109 | $string = str_replace ("\250", "š", $string); |
1fd97780 |
110 | // Latin capital letter Z with caron |
d23e472b |
111 | $string = str_replace ("\264", "Ž", $string); |
1fd97780 |
112 | // Latin small letter z with caron |
d23e472b |
113 | $string = str_replace ("\270", "ž", $string); |
1fd97780 |
114 | // Latin capital ligature OE |
d23e472b |
115 | $string = str_replace ("\274", "Œ", $string); |
1fd97780 |
116 | // Latin small ligature oe |
d23e472b |
117 | $string = str_replace ("\275", "œ", $string); |
1fd97780 |
118 | // Latin capital letter Y with diaeresis |
d23e472b |
119 | $string = str_replace ("\276", "Ÿ", $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 |