advanced_tree: Fix for the IE fix that was breaking Opera7 and comments about tested...
[squirrelmail.git] / functions / i18n.php
... / ...
CommitLineData
1<?php
2
3/**
4 * i18n.php
5 *
6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * This file contains variuos functions that are needed to do
10 * internationalization of SquirrelMail.
11 *
12 * Internally the output character set is used. Other characters are
13 * encoded using Unicode entities according to HTML 4.0.
14 *
15 * $Id$
16 */
17
18require_once(SM_PATH . 'functions/global.php');
19
20/* Decodes a string to the internal encoding from the given charset */
21function charset_decode ($charset, $string) {
22 global $languages, $squirrelmail_language;
23
24 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
25 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
26 $string = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $string);
27 }
28
29 /* All HTML special characters are 7 bit and can be replaced first */
30
31 $string = htmlspecialchars ($string);
32
33 $charset = strtolower($charset);
34
35 set_my_charset() ;
36
37 /* controls cpu and memory intensive decoding cycles */
38 $agresive_decoding = false;
39
40 if (ereg('iso-8859-([[:digit:]]+)', $charset, $res)) {
41 if ($res[1] == '1') {
42 include_once(SM_PATH . 'functions/decode/iso8859-1.php');
43 $ret = charset_decode_iso8859_1 ($string);
44 } else if ($res[1] == '2') {
45 include_once(SM_PATH . 'functions/decode/iso8859-2.php');
46 $ret = charset_decode_iso8859_2 ($string);
47 } else if ($res[1] == '3') {
48 include_once(SM_PATH . 'functions/decode/iso8859-3.php');
49 $ret = charset_decode_iso8859_3 ($string);
50 } else if ($res[1] == '4') {
51 include_once(SM_PATH . 'functions/decode/iso8859-4.php');
52 $ret = charset_decode_iso8859_4 ($string);
53 } else if ($res[1] == '5') {
54 include_once(SM_PATH . 'functions/decode/iso8859-5.php');
55 $ret = charset_decode_iso8859_5 ($string);
56 } else if ($res[1] == '6') {
57 include_once(SM_PATH . 'functions/decode/iso8859-6.php');
58 $ret = charset_decode_iso8859_6 ($string);
59 } else if ($res[1] == '7') {
60 include_once(SM_PATH . 'functions/decode/iso8859-7.php');
61 $ret = charset_decode_iso8859_7 ($string);
62 } else if ($res[1] == '8') {
63 include_once(SM_PATH . 'functions/decode/iso8859-8.php');
64 $ret = charset_decode_iso8859_8 ($string);
65 } else if ($res[1] == '9') {
66 include_once(SM_PATH . 'functions/decode/iso8859-9.php');
67 $ret = charset_decode_iso8859_9 ($string);
68 } else if ($res[1] == '10') {
69 include_once(SM_PATH . 'functions/decode/iso8859-10.php');
70 $ret = charset_decode_iso8859_10 ($string);
71 } else if ($res[1] == '11') {
72 include_once(SM_PATH . 'functions/decode/iso8859-11.php');
73 $ret = charset_decode_iso8859_11 ($string);
74 } else if ($res[1] == '13') {
75 include_once(SM_PATH . 'functions/decode/iso8859-13.php');
76 $ret = charset_decode_iso8859_13 ($string);
77 } else if ($res[1] == '14') {
78 include_once(SM_PATH . 'functions/decode/iso8859-14.php');
79 $ret = charset_decode_iso8859_14 ($string);
80 } else if ($res[1] == '15') {
81 include_once(SM_PATH . 'functions/decode/iso8859-15.php');
82 $ret = charset_decode_iso8859_15 ($string);
83 } else if ($res[1] == '16') {
84 include_once(SM_PATH . 'functions/decode/iso8859-16.php');
85 $ret = charset_decode_iso8859_16 ($string);
86 } else {
87 $ret = charset_decode_iso_8859_default ($string);
88 }
89 } else if ($charset == 'ns_4551-1') {
90 $ret = charset_decode_ns_4551_1 ($string);
91 } else if ($charset == 'koi8-r') {
92 include_once(SM_PATH . 'functions/decode/koi8-r.php');
93 $ret = charset_decode_koi8r ($string);
94 } else if ($charset == 'koi8-u') {
95 include_once(SM_PATH . 'functions/decode/koi8-u.php');
96 $ret = charset_decode_koi8u ($string);
97 } else if ($charset == 'windows-1250') {
98 include_once(SM_PATH . 'functions/decode/cp1250.php');
99 $ret = charset_decode_cp1250 ($string);
100 } else if ($charset == 'windows-1251') {
101 include_once(SM_PATH . 'functions/decode/cp1251.php');
102 $ret = charset_decode_cp1251 ($string);
103 } else if ($charset == 'windows-1252') {
104 include_once(SM_PATH . 'functions/decode/cp1252.php');
105 $ret = charset_decode_cp1252 ($string);
106 } else if ($charset == 'windows-1253') {
107 include_once(SM_PATH . 'functions/decode/cp1253.php');
108 $ret = charset_decode_cp1253 ($string);
109 } else if ($charset == 'windows-1254') {
110 include_once(SM_PATH . 'functions/decode/cp1254.php');
111 $ret = charset_decode_cp1254 ($string);
112 } else if ($charset == 'windows-1255') {
113 include_once(SM_PATH . 'functions/decode/cp1255.php');
114 $ret = charset_decode_cp1255 ($string);
115 } else if ($charset == 'windows-1256') {
116 include_once(SM_PATH . 'functions/decode/cp1256.php');
117 $ret = charset_decode_cp1256 ($string);
118 } else if ($charset == 'windows-1257') {
119 include_once(SM_PATH . 'functions/decode/cp1257.php');
120 $ret = charset_decode_cp1257 ($string);
121 } else if ($charset == 'windows-1258') {
122 include_once(SM_PATH . 'functions/decode/cp1258.php');
123 $ret = charset_decode_cp1258 ($string);
124 } else if ($charset == 'big5' and $agresive_decoding ) {
125 include_once(SM_PATH . 'functions/decode/big5.php');
126 $ret = charset_decode_big5 ($string);
127 } else if ($charset == 'gb2312' and $agresive_decoding ) {
128 include_once(SM_PATH . 'functions/decode/gb2312.php');
129 $ret = charset_decode_gb2312 ($string);
130 } else if ($charset == 'utf-8') {
131 include_once(SM_PATH . 'functions/decode/utf-8.php');
132 $ret = charset_decode_utf8 ($string);
133 } else {
134 $ret = $string;
135 }
136 return( $ret );
137}
138
139
140/* Remove all 8 bit characters from all other ISO-8859 character sets */
141function charset_decode_iso_8859_default ($string) {
142 return (strtr($string, "\240\241\242\243\244\245\246\247".
143 "\250\251\252\253\254\255\256\257".
144 "\260\261\262\263\264\265\266\267".
145 "\270\271\272\273\274\275\276\277".
146 "\300\301\302\303\304\305\306\307".
147 "\310\311\312\313\314\315\316\317".
148 "\320\321\322\323\324\325\326\327".
149 "\330\331\332\333\334\335\336\337".
150 "\340\341\342\343\344\345\346\347".
151 "\350\351\352\353\354\355\356\357".
152 "\360\361\362\363\364\365\366\367".
153 "\370\371\372\373\374\375\376\377",
154 "????????????????????????????????????????".
155 "????????????????????????????????????????".
156 "????????????????????????????????????????".
157 "????????"));
158
159}
160
161/*
162 * This is the same as ISO-646-NO and is used by some
163 * Microsoft programs when sending Norwegian characters
164 */
165function charset_decode_ns_4551_1 ($string) {
166 /*
167 * These characters are:
168 * Latin capital letter AE
169 * Latin capital letter O with stroke
170 * Latin capital letter A with ring above
171 * and the same as small letters
172 */
173