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"; |
d30d79f2 |
23 | |
1fd97780 |
24 | // Decodes a string to the internal encoding from the given charset |
25 | function charset_decode ($charset, $string) { |
26 | // All HTML special characters are 7 bit and can be replaced first |
27 | $string = htmlspecialchars ($string); |
28 | |
44139266 |
29 | $charset = strtolower($charset); |
1fd97780 |
30 | |
31 | if (ereg("iso-8859-(.*)", $charset, $res)) { |
32 | if ($res[1] == "1") |
33 | return charset_decode_iso_8859_1 ($string); |
173ed887 |
34 | if ($res[1] == "7") |
35 | return charset_decode_iso_8859_7 ($string); |
1fd97780 |
36 | else if ($res[1] == "15") |
37 | return charset_decode_iso_8859_15 ($string); |
38 | else |
39 | return charset_decode_iso_8859_default ($string); |
40 | } else if ($charset == "ns_4551-1") { |
41 | return charset_decode_ns_4551_1 ($string); |
17ce8467 |
42 | } else if ($charset == "koi8-r") { |
43 | return charset_decode_koi8r ($string); |
209e2f82 |
44 | } else |
1fd97780 |
45 | return $string; |
46 | } |
47 | |
48 | // iso-8859-1 is the same as Latin 1 and is normally used |
49 | // in western europe. |
50 | function charset_decode_iso_8859_1 ($string) { |
51 | // This is only debug code as long as the internal |
52 | // character set is iso-8859-1 |
53 | |
54 | // Latin small letter o with stroke |
55 | while (ereg("\370", $string)) |
56 | $string = ereg_replace ("\370", "ø", $string); |
57 | |
58 | return ($string); |
59 | } |
60 | |
0a86e9f3 |
61 | // iso-8859-7 is Greek. |
209e2f82 |
62 | function charset_decode_iso_8859_7 ($string) { |
173ed887 |
63 | // Could not find Unicode equivalent of 0xA1 and 0xA2 |
64 | // 0xA4, 0xA5, 0xAA, 0xAE, 0xD2 and 0xFF should not be used |
65 | $string = strtr($string, "\241\242\244\245\252\256\322\377", |
66 | "????????"); |
67 | |
68 | // Horizontal bar (parentheki pavla) |
69 | while (ereg("\257", $string)) |
70 | $string = ereg_replace ("\257", "―", $string); |
71 | |
72 | // ISO-8859-7 characters from 11/04 (0xB4) to 11/06 (0xB6) |
73 | // These are Unicode 900-902 |
74 | while (ereg("([\264-\266])", $string, $res)) { |
0a86e9f3 |
75 | $replace = "&#" . (ord($res[1])+720) . ";"; |
76 | $string = ereg_replace($res[1], $replace, $string); |
173ed887 |
77 | } |
78 | |
79 | // 11/07 (0xB7) Middle dot is the same in iso-8859-1 |
80 | |
81 | // ISO-8859-7 characters from 11/08 (0xB8) to 11/10 (0xBA) |
82 | // These are Unicode 900-902 |
83 | while (ereg("([\270-\272])", $string, $res)) { |
0a86e9f3 |
84 | $replace = "&#" . (ord($res[1])+720) . ";"; |
85 | $string = ereg_replace($res[1], $replace, $string); |
173ed887 |
86 | } |
87 | |
88 | // 11/11 (0xBB) Right angle quotation mark is the same as in |
89 | // iso-8859-1 |
90 | |
91 | // And now the rest of the charset |
92 | while (ereg("([\273-\376])", $string, $res)) { |
0a86e9f3 |
93 | $replace = "&#" . (ord($res[1])+720) . ";"; |
94 | $string = ereg_replace($res[1], $replace, $string); |
173ed887 |
95 | } |
96 | |
97 | return $string; |
98 | } |
99 | |
1fd97780 |
100 | // iso-8859-15 is Latin 15 and has very much the same use as Latin 1 |
101 | // but has the Euro symbol and some characters needed for French. |
102 | function charset_decode_iso_8859_15 ($string) { |
103 | // Euro sign |
104 | while (ereg("\244", $replace)) |
105 | $string = ereg_replace ("\244", "€", $string); |
106 | // Latin capital letter S with caron |
107 | while (ereg("\246", $string)) |
108 | $string = ereg_replace ("\244", "Š", $string); |
109 | // Latin small letter s with caron |
110 | while (ereg("\250", $string)) |
111 | $string = ereg_replace ("\250", "š", $string); |
112 | // Latin capital letter Z with caron |
113 | while (ereg("\264", $string)) |
114 | $string = ereg_replace ("\264", "Ž", $string); |
115 | // Latin small letter z with caron |
116 | while (ereg("\270", $string)) |
117 | $string = ereg_replace ("\270", "ž", $string); |
118 | // Latin capital ligature OE |
119 | while (ereg("\274", $string)) |
120 | $string = ereg_replace ("\274", "Œ", $string); |
121 | // Latin small ligature oe |
122 | while (ereg("\275", $string)) |
123 | $string = ereg_replace ("\275", "œ", $string); |
124 | // Latin capital letter Y with diaeresis |
125 | while (ereg("\276", $string)) |
126 | $string = ereg_replace ("\276", "Ÿ", $string); |
127 | |
128 | return ($string); |
129 | } |
130 | |
17ce8467 |
131 | // ISO-8859-15 is Cyrillic |
132 | function charset_decode_iso_8859_5 ($string) { |
133 | // Not yet implemented. |
134 | } |
135 | |
173ed887 |
136 | // Remove all 8 bit characters from all other ISO-8859 character sets |
1fd97780 |
137 | function charset_decode_iso_8859_default ($string) { |
138 | return (strtr($string, "\240\241\242\243\244\245\246\247". |
139 | "\250\251\252\253\254\255\256\257". |
140 | "\260\261\262\263\264\265\266\267". |
141 | "\270\271\272\273\274\275\276\277". |
142 | "\300\301\302\303\304\305\306\307". |
143 | "\310\311\312\313\314\315\316\317". |
144 | "\320\321\322\323\324\325\326\327". |
145 | "\330\331\332\333\334\335\336\337". |
146 | "\340\341\342\343\344\345\346\347". |
147 | "\350\351\352\353\354\355\356\357". |
148 | "\360\361\362\363\364\365\366\367". |
149 | "\370\371\372\373\374\375\376\377", |
150 | "????????????????????????????????????????". |
151 | "????????????????????????????????????????". |
152 | "????????????????????????????????????????". |
153 | "????????")); |
154 | |
155 | } |
156 | |
157 | // This is the same as ISO-646-NO and is used by some |
158 | // Microsoft programs when sending Norwegian characters |
159 | function charset_decode_ns_4551_1 ($string) { |
160 | // These characters are: |
161 | // Latin capital letter AE |
162 | // Latin capital letter O with stroke |
163 | // Latin capital letter A with ring above |
164 | // and the same as small letters |
165 |