Default theme is set in config/config.php. Setting it here makes SM
[squirrelmail.git] / functions / i18n.php
CommitLineData
59177427 1<?php
1fd97780 2
35586184 3/**
4 * i18n.php
5 *
76911253 6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
35586184 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
961ca3d8 18require_once(SM_PATH . 'functions/global.php');
19
a2a7852b 20/* Decodes a string to the internal encoding from the given charset */
21function charset_decode ($charset, $string) {
6fbd125b 22 global $languages, $squirrelmail_language;
a2a7852b 23
3714db45 24 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
25 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
6fbd125b 26 $string = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $string);
27 }
b05c8961 28
a2a7852b 29 /* All HTML special characters are 7 bit and can be replaced first */
cef054e4 30
098ea084 31 $string = htmlspecialchars ($string);
a2a7852b 32
33 $charset = strtolower($charset);
34
94965562 35 set_my_charset() ;
36
5dd23dac 37 /* controls cpu and memory intensive decoding cycles */
38 $agresive_decoding = false;
39
a2a7852b 40 if (ereg('iso-8859-([[:digit:]]+)', $charset, $res)) {
41 if ($res[1] == '1') {
5dd23dac 42 include_once(SM_PATH . 'functions/decode/iso8859-1.php');
43 $ret = charset_decode_iso8859_1 ($string);
a2a7852b 44 } else if ($res[1] == '2') {
5dd23dac 45 include_once(SM_PATH . 'functions/decode/iso8859-2.php');
46 $ret = charset_decode_iso8859_2 ($string);
3a66bed2 47 } else if ($res[1] == '3') {
48 include_once(SM_PATH . 'functions/decode/iso8859-3.php');
49 $ret = charset_decode_iso8859_3 ($string);
9be313d5 50 } else if ($res[1] == '4') {
3a66bed2 51 include_once(SM_PATH . 'functions/decode/iso8859-4.php');
52 $ret = charset_decode_iso8859_4 ($string);
94965562 53 } else if ($res[1] == '5') {
3a66bed2 54 include_once(SM_PATH . 'functions/decode/iso8859-5.php');
55 $ret = charset_decode_iso8859_5 ($string);
ef82d2d5 56 } else if ($res[1] == '6') {
5dd23dac 57 include_once(SM_PATH . 'functions/decode/iso8859-6.php');
58 $ret = charset_decode_iso8859_6 ($string);
a2a7852b 59 } else if ($res[1] == '7') {
5dd23dac 60 include_once(SM_PATH . 'functions/decode/iso8859-7.php');
61 $ret = charset_decode_iso8859_7 ($string);
3a66bed2 62 } else if ($res[1] == '8') {
63 include_once(SM_PATH . 'functions/decode/iso8859-8.php');
64 $ret = charset_decode_iso8859_8 ($string);
3ab35042 65 } else if ($res[1] == '9') {
5dd23dac 66 include_once(SM_PATH . 'functions/decode/iso8859-9.php');
67 $ret = charset_decode_iso8859_9 ($string);
3a66bed2 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);
9be313d5 74 } else if ($res[1] == '13') {
3a66bed2 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);
a2a7852b 80 } else if ($res[1] == '15') {
5dd23dac 81 include_once(SM_PATH . 'functions/decode/iso8859-15.php');
82 $ret = charset_decode_iso8859_15 ($string);
3a66bed2 83 } else if ($res[1] == '16') {
84 include_once(SM_PATH . 'functions/decode/iso8859-16.php');
85 $ret = charset_decode_iso8859_16 ($string);
a2a7852b 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') {
5dd23dac 92 include_once(SM_PATH . 'functions/decode/koi8-r.php');
a2a7852b 93 $ret = charset_decode_koi8r ($string);
1c0e847f 94 } else if ($charset == 'koi8-u') {
5dd23dac 95 include_once(SM_PATH . 'functions/decode/koi8-u.php');
1c0e847f 96 $ret = charset_decode_koi8u ($string);
5dd23dac 97 } else if ($charset == 'windows-1250') {
98 include_once(SM_PATH . 'functions/decode/cp1250.php');
99 $ret = charset_decode_cp1250 ($string);
a2a7852b 100 } else if ($charset == 'windows-1251') {
5dd23dac 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);
3ab35042 106 } else if ($charset == 'windows-1253') {
5dd23dac 107 include_once(SM_PATH . 'functions/decode/cp1253.php');
108 $ret = charset_decode_cp1253 ($string);
3ab35042 109 } else if ($charset == 'windows-1254') {
5dd23dac 110 include_once(SM_PATH . 'functions/decode/cp1254.php');
111 $ret = charset_decode_cp1254 ($string);
c48a8ca7 112 } else if ($charset == 'windows-1255') {
5dd23dac 113 include_once(SM_PATH . 'functions/decode/cp1255.php');
114 $ret = charset_decode_cp1255 ($string);
c48a8ca7 115 } else if ($charset == 'windows-1256') {
5dd23dac 116 include_once(SM_PATH . 'functions/decode/cp1256.php');
117 $ret = charset_decode_cp1256 ($string);
c37a12f8 118 } else if ($charset == 'windows-1257') {
3a66bed2 119 include_once(SM_PATH . 'functions/decode/cp1257.php');
120 $ret = charset_decode_cp1257 ($string);
5dd23dac 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);
3ab35042 130 } else if ($charset == 'utf-8') {
5dd23dac 131 include_once(SM_PATH . 'functions/decode/utf-8.php');
3ab35042 132 $ret = charset_decode_utf8 ($string);
a2a7852b 133 } else {
134 $ret = $string;
135 }
136 return( $ret );
137}
138
a2a7852b 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".
1fd97780 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".
a2a7852b 153 "\370\371\372\373\374\375\376\377",
1fd97780 154 "????????????????????????????????????????".
155 "????????????????????????????????????????".
156 "????????????????????????????????????????".
157 "????????"));
a2a7852b 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