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