i18n.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. <?php
  2. /**
  3. * i18n.php
  4. *
  5. * Copyright (c) 1999-2003 The SquirrelMail Project Team
  6. * Licensed under the GNU GPL. For full terms see the file COPYING.
  7. *
  8. * This file contains variuos functions that are needed to do
  9. * internationalization of SquirrelMail.
  10. *
  11. * Internally the output character set is used. Other characters are
  12. * encoded using Unicode entities according to HTML 4.0.
  13. *
  14. * $Id$
  15. */
  16. require_once(SM_PATH . 'functions/global.php');
  17. /* Decodes a string to the internal encoding from the given charset */
  18. function charset_decode ($charset, $string) {
  19. global $languages, $squirrelmail_language;
  20. if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
  21. function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
  22. $string = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $string);
  23. }
  24. /* All HTML special characters are 7 bit and can be replaced first */
  25. $string = htmlspecialchars ($string);
  26. $charset = strtolower($charset);
  27. set_my_charset() ;
  28. /* controls cpu and memory intensive decoding cycles */
  29. $agresive_decoding = false;
  30. if (ereg('iso-8859-([[:digit:]]+)', $charset, $res)) {
  31. if ($res[1] == '1') {
  32. include_once(SM_PATH . 'functions/decode/iso8859-1.php');
  33. $ret = charset_decode_iso8859_1 ($string);
  34. } else if ($res[1] == '2') {
  35. include_once(SM_PATH . 'functions/decode/iso8859-2.php');
  36. $ret = charset_decode_iso8859_2 ($string);
  37. } else if ($res[1] == '3') {
  38. include_once(SM_PATH . 'functions/decode/iso8859-3.php');
  39. $ret = charset_decode_iso8859_3 ($string);
  40. } else if ($res[1] == '4') {
  41. include_once(SM_PATH . 'functions/decode/iso8859-4.php');
  42. $ret = charset_decode_iso8859_4 ($string);
  43. } else if ($res[1] == '5') {
  44. include_once(SM_PATH . 'functions/decode/iso8859-5.php');
  45. $ret = charset_decode_iso8859_5 ($string);
  46. } else if ($res[1] == '6') {
  47. include_once(SM_PATH . 'functions/decode/iso8859-6.php');
  48. $ret = charset_decode_iso8859_6 ($string);
  49. } else if ($res[1] == '7') {
  50. include_once(SM_PATH . 'functions/decode/iso8859-7.php');
  51. $ret = charset_decode_iso8859_7 ($string);
  52. } else if ($res[1] == '8') {
  53. include_once(SM_PATH . 'functions/decode/iso8859-8.php');
  54. $ret = charset_decode_iso8859_8 ($string);
  55. } else if ($res[1] == '9') {
  56. include_once(SM_PATH . 'functions/decode/iso8859-9.php');
  57. $ret = charset_decode_iso8859_9 ($string);
  58. } else if ($res[1] == '10') {
  59. include_once(SM_PATH . 'functions/decode/iso8859-10.php');
  60. $ret = charset_decode_iso8859_10 ($string);
  61. } else if ($res[1] == '11') {
  62. include_once(SM_PATH . 'functions/decode/iso8859-11.php');
  63. $ret = charset_decode_iso8859_11 ($string);
  64. } else if ($res[1] == '13') {
  65. include_once(SM_PATH . 'functions/decode/iso8859-13.php');
  66. $ret = charset_decode_iso8859_13 ($string);
  67. } else if ($res[1] == '14') {
  68. include_once(SM_PATH . 'functions/decode/iso8859-14.php');
  69. $ret = charset_decode_iso8859_14 ($string);
  70. } else if ($res[1] == '15') {
  71. include_once(SM_PATH . 'functions/decode/iso8859-15.php');
  72. $ret = charset_decode_iso8859_15 ($string);
  73. } else if ($res[1] == '16') {
  74. include_once(SM_PATH . 'functions/decode/iso8859-16.php');
  75. $ret = charset_decode_iso8859_16 ($string);
  76. } else {
  77. $ret = charset_decode_iso_8859_default ($string);
  78. }
  79. } else if ($charset == 'ns_4551-1') {
  80. $ret = charset_decode_ns_4551_1 ($string);
  81. } else if ($charset == 'koi8-r') {
  82. include_once(SM_PATH . 'functions/decode/koi8-r.php');
  83. $ret = charset_decode_koi8r ($string);
  84. } else if ($charset == 'koi8-u') {
  85. include_once(SM_PATH . 'functions/decode/koi8-u.php');
  86. $ret = charset_decode_koi8u ($string);
  87. } else if ($charset == 'windows-1250') {
  88. include_once(SM_PATH . 'functions/decode/cp1250.php');
  89. $ret = charset_decode_cp1250 ($string);
  90. } else if ($charset == 'windows-1251') {
  91. include_once(SM_PATH . 'functions/decode/cp1251.php');
  92. $ret = charset_decode_cp1251 ($string);
  93. } else if ($charset == 'windows-1252') {
  94. include_once(SM_PATH . 'functions/decode/cp1252.php');
  95. $ret = charset_decode_cp1252 ($string);
  96. } else if ($charset == 'windows-1253') {
  97. include_once(SM_PATH . 'functions/decode/cp1253.php');
  98. $ret = charset_decode_cp1253 ($string);
  99. } else if ($charset == 'windows-1254') {
  100. include_once(SM_PATH . 'functions/decode/cp1254.php');
  101. $ret = charset_decode_cp1254 ($string);
  102. } else if ($charset == 'windows-1255') {
  103. include_once(SM_PATH . 'functions/decode/cp1255.php');
  104. $ret = charset_decode_cp1255 ($string);
  105. } else if ($charset == 'windows-1256') {
  106. include_once(SM_PATH . 'functions/decode/cp1256.php');
  107. $ret = charset_decode_cp1256 ($string);
  108. } else if ($charset == 'windows-1257') {
  109. include_once(SM_PATH . 'functions/decode/cp1257.php');
  110. $ret = charset_decode_cp1257 ($string);
  111. } else if ($charset == 'windows-1258') {
  112. include_once(SM_PATH . 'functions/decode/cp1258.php');
  113. $ret = charset_decode_cp1258 ($string);
  114. } else if ($charset == 'big5' and $agresive_decoding ) {
  115. include_once(SM_PATH . 'functions/decode/big5.php');
  116. $ret = charset_decode_big5 ($string);
  117. } else if ($charset == 'gb2312' and $agresive_decoding ) {
  118. include_once(SM_PATH . 'functions/decode/gb2312.php');
  119. $ret = charset_decode_gb2312 ($string);
  120. } else if ($charset == 'utf-8') {
  121. include_once(SM_PATH . 'functions/decode/utf-8.php');
  122. $ret = charset_decode_utf8 ($string);
  123. } else {
  124. $ret = $string;
  125. }
  126. return( $ret );
  127. }
  128. /* Remove all 8 bit characters from all other ISO-8859 character sets */
  129. function charset_decode_iso_8859_default ($string) {
  130. return (strtr($string, "\240\241\242\243\244\245\246\247".
  131. "\250\251\252\253\254\255\256\257".
  132. "\260\261\262\263\264\265\266\267".
  133. "\270\271\272\273\274\275\276\277".
  134. "\300\301\302\303\304\305\306\307".
  135. "\310\311\312\313\314\315\316\317".
  136. "\320\321\322\323\324\325\326\327".
  137. "\330\331\332\333\334\335\336\337".
  138. "\340\341\342\343\344\345\346\347".
  139. "\350\351\352\353\354\355\356\357".
  140. "\360\361\362\363\364\365\366\367".
  141. "\370\371\372\373\374\375\376\377",
  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. */
  151. function charset_decode_ns_4551_1 ($string) {
  152. /*
  153. * These characters are:
  154. * Latin capital letter AE
  155. * Latin capital letter O with stroke
  156. * Latin capital letter A with ring above
  157. * and the same as small letters
  158. */
  159. return strtr ($string, "[\\]{|}", "ÆØÅæøå");
  160. }
  161. /*
  162. * Set up the language to be output
  163. * if $do_search is true, then scan the browser information
  164. * for a possible language that we know
  165. */
  166. function set_up_language($sm_language, $do_search = false, $default = false) {
  167. static $SetupAlready = 0;
  168. global $use_gettext, $languages,
  169. $squirrelmail_language, $squirrelmail_default_language,
  170. $sm_notAlias;
  171. if ($SetupAlready) {
  172. return;
  173. }
  174. $SetupAlready = TRUE;
  175. sqgetGlobalVar('HTTP_ACCEPT_LANGUAGE', $accept_lang, SQ_SERVER);
  176. if ($do_search && ! $sm_language && isset($accept_lang)) {
  177. $sm_language = substr($accept_lang, 0, 2);
  178. }
  179. if ((!$sm_language||$default) && isset($squirrelmail_default_language)) {
  180. $squirrelmail_language = $squirrelmail_default_language;
  181. $sm_language = $squirrelmail_default_language;
  182. }
  183. $sm_notAlias = $sm_language;
  184. while (isset($languages[$sm_notAlias]['ALIAS'])) {
  185. $sm_notAlias = $languages[$sm_notAlias]['ALIAS'];
  186. }
  187. if ( isset($sm_language) &&
  188. $use_gettext &&
  189. $sm_language != '' &&
  190. isset($languages[$sm_notAlias]['CHARSET']) ) {
  191. bindtextdomain( 'squirrelmail', SM_PATH . 'locale/' );
  192. textdomain( 'squirrelmail' );
  193. if (function_exists('bind_textdomain_codeset')) {
  194. bind_textdomain_codeset ("squirrelmail", $languages[$sm_notAlias]['CHARSET'] );
  195. }
  196. if (isset($languages[$sm_notAlias]['LOCALE'])){
  197. $longlocale=$languages[$sm_notAlias]['LOCALE'];
  198. } else {
  199. $longlocale=$sm_notAlias;
  200. }
  201. if ( !ini_get('safe_mode') &&
  202. getenv( 'LC_ALL' ) != $longlocale ) {
  203. putenv( "LC_ALL=$longlocale" );
  204. putenv( "LANG=$longlocale" );
  205. putenv( "LANGUAGE=$longlocale" );
  206. }
  207. setlocale(LC_ALL, $longlocale);
  208. $squirrelmail_language = $sm_notAlias;
  209. if ($squirrelmail_language == 'ja_JP' && function_exists('mb_detect_encoding') ) {
  210. header ('Content-Type: text/html; charset=EUC-JP');
  211. if (!function_exists('mb_internal_encoding')) {
  212. echo _("You need to have php4 installed with the multibyte string function enabled (using configure option --enable-mbstring).");
  213. }
  214. if (function_exists('mb_language')) {
  215. mb_language('Japanese');
  216. }
  217. mb_internal_encoding('EUC-JP');
  218. mb_http_output('pass');
  219. } else {
  220. header( 'Content-Type: text/html; charset=' . $languages[$sm_notAlias]['CHARSET'] );
  221. }
  222. }
  223. }
  224. function set_my_charset(){
  225. /*
  226. * There can be a $default_charset setting in the
  227. * config.php file, but the user may have a different language
  228. * selected for a user interface. This function checks the
  229. * language selected by the user and tags the outgoing messages
  230. * with the appropriate charset corresponding to the language
  231. * selection. This is "more right" (tm), than just stamping the
  232. * message blindly with the system-wide $default_charset.
  233. */
  234. global $data_dir, $username, $default_charset, $languages, $squirrelmail_default_language;
  235. $my_language = getPref($data_dir, $username, 'language');
  236. if (!$my_language) {
  237. $my_language = $squirrelmail_default_language ;
  238. }
  239. while (isset($languages[$my_language]['ALIAS'])) {
  240. $my_language = $languages[$my_language]['ALIAS'];
  241. }
  242. $my_charset = $languages[$my_language]['CHARSET'];
  243. if ($my_charset) {
  244. $default_charset = $my_charset;
  245. }
  246. }
  247. /* ------------------------------ main --------------------------- */
  248. global $squirrelmail_language, $languages, $use_gettext;
  249. if (! isset($squirrelmail_language)) {
  250. $squirrelmail_language = '';
  251. }
  252. /* This array specifies the available languages. */
  253. if ( file_exists( SM_PATH . 'locale/ca_ES') ) {
  254. // The glibc locale is ca_ES.
  255. $languages['ca_ES']['NAME'] = 'Catalan';
  256. $languages['ca_ES']['CHARSET'] = 'iso-8859-1';
  257. $languages['ca']['ALIAS'] = 'ca_ES';
  258. }
  259. if ( file_exists( SM_PATH . 'locale/cs_CZ') ) {
  260. $languages['cs_CZ']['NAME'] = 'Czech';
  261. $languages['cs_CZ']['CHARSET'] = 'iso-8859-2';
  262. $languages['cs']['ALIAS'] = 'cs_CZ';
  263. }
  264. if ( file_exists( SM_PATH . 'locale/da_DK') ) {
  265. // Danish locale is da_DK.
  266. $languages['da_DK']['NAME'] = 'Danish';
  267. $languages['da_DK']['CHARSET'] = 'iso-8859-1';
  268. $languages['da']['ALIAS'] = 'da_DK';
  269. }
  270. if ( file_exists( SM_PATH . 'locale/de_DE') ) {
  271. $languages['de_DE']['NAME'] = 'Deutsch';
  272. $languages['de_DE']['CHARSET'] = 'iso-8859-1';
  273. $languages['de']['ALIAS'] = 'de_DE';
  274. }
  275. // There is no en_EN! There is en_US, en_BR, en_AU, and so forth,
  276. // but who cares about !US, right? Right? :)
  277. if ( file_exists( SM_PATH . 'locale/el_GR') ) {
  278. $languages['el_GR']['NAME'] = 'Greek';
  279. $languages['el_GR']['CHARSET'] = 'iso-8859-7';
  280. $languages['el']['ALIAS'] = 'el_GR';
  281. }
  282. $languages['en_US']['NAME'] = 'English';
  283. $languages['en_US']['CHARSET'] = 'iso-8859-1';
  284. $languages['en']['ALIAS'] = 'en_US';
  285. if ( file_exists( SM_PATH . 'locale/es_ES') ) {
  286. $languages['es_ES']['NAME'] = 'Spanish';
  287. $languages['es_ES']['CHARSET'] = 'iso-8859-1';
  288. $languages['es']['ALIAS'] = 'es_ES';
  289. }
  290. if ( file_exists( SM_PATH . 'locale/et_EE') ) {
  291. $languages['et_EE']['NAME'] = 'Estonian';
  292. $languages['et_EE']['CHARSET'] = 'iso-8859-15';
  293. $languages['et']['ALIAS'] = 'et_EE';
  294. }
  295. if ( file_exists( SM_PATH . 'locale/fo_FO') ) {
  296. $languages['fo_FO']['NAME'] = 'Faroese';
  297. $languages['fo_FO']['CHARSET'] = 'iso-8859-1';
  298. $languages['fo']['ALIAS'] = 'fo_FO';
  299. }
  300. if ( file_exists( SM_PATH . 'locale/fi_FI') ) {
  301. $languages['fi_FI']['NAME'] = 'Finnish';
  302. $languages['fi_FI']['CHARSET'] = 'iso-8859-1';
  303. $languages['fi']['ALIAS'] = 'fi_FI';
  304. }
  305. if ( file_exists( SM_PATH . 'locale/fr_FR') ) {
  306. $languages['fr_FR']['NAME'] = 'French';
  307. $languages['fr_FR']['CHARSET'] = 'iso-8859-1';
  308. $languages['fr']['ALIAS'] = 'fr_FR';
  309. }
  310. if ( file_exists( SM_PATH . 'locale/hr_HR') ) {
  311. $languages['hr_HR']['NAME'] = 'Croatian';
  312. $languages['hr_HR']['CHARSET'] = 'iso-8859-2';
  313. $languages['hr']['ALIAS'] = 'hr_HR';
  314. }
  315. if ( file_exists( SM_PATH . 'locale/hu_HU') ) {
  316. $languages['hu_HU']['NAME'] = 'Hungarian';
  317. $languages['hu_HU']['CHARSET'] = 'iso-8859-2';
  318. $languages['hu']['ALIAS'] = 'hu_HU';
  319. }
  320. if ( file_exists( SM_PATH . 'locale/id_ID') ) {
  321. $languages['id_ID']['NAME'] = 'Bahasa Indonesia';
  322. $languages['id_ID']['CHARSET'] = 'iso-8859-1';
  323. $languages['id']['ALIAS'] = 'id_ID';
  324. }
  325. if ( file_exists( SM_PATH . 'locale/is_IS') ) {
  326. $languages['is_IS']['NAME'] = 'Icelandic';
  327. $languages['is_IS']['CHARSET'] = 'iso-8859-1';
  328. $languages['is']['ALIAS'] = 'is_IS';
  329. }
  330. if ( file_exists( SM_PATH . 'locale/it_IT') ) {
  331. $languages['it_IT']['NAME'] = 'Italian';
  332. $languages['it_IT']['CHARSET'] = 'iso-8859-1';
  333. $languages['it']['ALIAS'] = 'it_IT';
  334. }
  335. if ( file_exists( SM_PATH . 'locale/ja_JP') ) {
  336. $languages['ja_JP']['NAME'] = 'Japanese';
  337. $languages['ja_JP']['CHARSET'] = 'iso-2022-jp';
  338. $languages['ja_JP']['XTRA_CODE'] = 'japanese_charset_xtra';
  339. $languages['ja']['ALIAS'] = 'ja_JP';
  340. }
  341. if ( file_exists( SM_PATH . 'locale/ko_KR') ) {
  342. $languages['ko_KR']['NAME'] = 'Korean';
  343. $languages['ko_KR']['CHARSET'] = 'euc-KR';
  344. $languages['ko_KR']['XTRA_CODE'] = 'korean_charset_xtra';
  345. $languages['ko']['ALIAS'] = 'ko_KR';
  346. }
  347. if ( file_exists( SM_PATH . 'locale/nl_NL') ) {
  348. $languages['nl_NL']['NAME'] = 'Dutch';
  349. $languages['nl_NL']['CHARSET'] = 'iso-8859-1';
  350. $languages['nl']['ALIAS'] = 'nl_NL';
  351. }
  352. if ( file_exists( SM_PATH . 'locale/no_NO') ) {
  353. $languages['no_NO']['NAME'] = 'Norwegian (Bokm&aring;l)';
  354. $languages['no_NO']['CHARSET'] = 'iso-8859-1';
  355. $languages['no']['ALIAS'] = 'no_NO';
  356. }
  357. if ( file_exists( SM_PATH . 'locale/nn_NO') ) {
  358. $languages['nn_NO']['NAME'] = 'Norwegian (Nynorsk)';
  359. $languages['nn_NO']['CHARSET'] = 'iso-8859-1';
  360. }
  361. if ( file_exists( SM_PATH . 'locale/pl_PL') ) {
  362. $languages['pl_PL']['NAME'] = 'Polish';
  363. $languages['pl_PL']['CHARSET'] = 'iso-8859-2';
  364. $languages['pl']['ALIAS'] = 'pl_PL';
  365. }
  366. if ( file_exists( SM_PATH . 'locale/pt_PT') ) {
  367. $languages['pt_PT']['NAME'] = 'Portuguese (Portugal)';
  368. $languages['pt_PT']['CHARSET'] = 'iso-8859-1';
  369. $languages['pt']['ALIAS'] = 'pt_PT';
  370. }
  371. if ( file_exists( SM_PATH . 'locale/pt_BR') ) {
  372. $languages['pt_BR']['NAME'] = 'Portuguese (Brazil)';
  373. $languages['pt_BR']['CHARSET'] = 'iso-8859-1';
  374. }
  375. if ( file_exists( SM_PATH . 'locale/ru_RU') ) {
  376. $languages['ru_RU']['NAME'] = 'Russian';
  377. $languages['ru_RU']['CHARSET'] = 'koi8-r';
  378. $languages['ru_RU']['LOCALE'] = 'ru_RU.KOI8-R';
  379. $languages['ru']['ALIAS'] = 'ru_RU';
  380. }
  381. if ( file_exists( SM_PATH . 'locale/sr_YU') ) {
  382. $languages['sr_YU']['NAME'] = 'Serbian';
  383. $languages['sr_YU']['CHARSET'] = 'iso-8859-2';
  384. $languages['sr']['ALIAS'] = 'sr_YU';
  385. }
  386. if ( file_exists( SM_PATH . 'locale/sv_SE') ) {
  387. $languages['sv_SE']['NAME'] = 'Swedish';
  388. $languages['sv_SE']['CHARSET'] = 'iso-8859-1';
  389. $languages['sv']['ALIAS'] = 'sv_SE';
  390. }
  391. if ( file_exists( SM_PATH . 'locale/tr_TR') ) {
  392. $languages['tr_TR']['NAME'] = 'Turkish';
  393. $languages['tr_TR']['CHARSET'] = 'iso-8859-9';
  394. $languages['tr']['ALIAS'] = 'tr_TR';
  395. }
  396. if ( file_exists( SM_PATH . 'locale/zh_TW') ) {
  397. $languages['zh_TW']['NAME'] = 'Chinese Trad';
  398. $languages['zh_TW']['CHARSET'] = 'big5';
  399. $languages['tw']['ALIAS'] = 'zh_TW';
  400. }
  401. if ( file_exists( SM_PATH . 'locale/zh_CN') ) {
  402. $languages['zh_CN']['NAME'] = 'Chinese Simp';
  403. $languages['zh_CN']['CHARSET'] = 'gb2312';
  404. $languages['cn']['ALIAS'] = 'zh_CN';
  405. }
  406. if ( file_exists( SM_PATH . 'locale/sk_SK') ) {
  407. $languages['sk_SK']['NAME'] = 'Slovak';
  408. $languages['sk_SK']['CHARSET'] = 'iso-8859-2';
  409. $languages['sk']['ALIAS'] = 'sk_SK';
  410. }
  411. if ( file_exists( SM_PATH . 'locale/ro_RO') ) {
  412. $languages['ro_RO']['NAME'] = 'Romanian';
  413. $languages['ro_RO']['CHARSET'] = 'iso-8859-2';
  414. $languages['ro']['ALIAS'] = 'ro_RO';
  415. }
  416. if ( file_exists( SM_PATH . 'locale/th_TH') ) {
  417. $languages['th_TH']['NAME'] = 'Thai';
  418. $languages['th_TH']['CHARSET'] = 'tis-620';
  419. $languages['th']['ALIAS'] = 'th_TH';
  420. }
  421. if ( file_exists( SM_PATH . 'locale/lt_LT') ) {
  422. $languages['lt_LT']['NAME'] = 'Lithuanian';
  423. $languages['lt_LT']['CHARSET'] = 'iso-8859-4';
  424. $languages['lt_LT']['LOCALE'] = 'lt_LT.ISO-8859-4';
  425. $languages['lt']['ALIAS'] = 'lt_LT';
  426. }
  427. if ( file_exists( SM_PATH . 'locale/sl_SI') ) {
  428. $languages['sl_SI']['NAME'] = 'Slovenian';
  429. $languages['sl_SI']['CHARSET'] = 'iso-8859-2';
  430. $languages['sl']['ALIAS'] = 'sl_SI';
  431. }
  432. if ( file_exists( SM_PATH . 'locale/bg_BG') ) {
  433. $languages['bg_BG']['NAME'] = 'Bulgarian';
  434. $languages['bg_BG']['CHARSET'] = 'windows-1251';
  435. $languages['bg']['ALIAS'] = 'bg_BG';
  436. }
  437. if ( file_exists( SM_PATH . 'locale/uk_UA') ) {
  438. $languages['uk_UA']['NAME'] = 'Ukrainian';
  439. $languages['uk_UA']['CHARSET'] = 'koi8-u';
  440. $languages['uk']['ALIAS'] = 'uk_UA';
  441. }
  442. if ( file_exists( SM_PATH . 'locale/cy_GB') ) {
  443. $languages['cy_GB']['NAME'] = 'Welsh';
  444. $languages['cy_GB']['CHARSET'] = 'iso-8859-1';
  445. $languages['cy']['ALIAS'] = 'cy_GB';
  446. }
  447. if ( file_exists( SM_PATH . 'locale/vi_VN') ) {
  448. $languages['vi_VN']['NAME'] = 'Vietnamese';
  449. $languages['vi_VN']['CHARSET'] = 'utf-8';
  450. $languages['vi']['ALIAS'] = 'vi_VN';
  451. }
  452. // Right to left languages
  453. if ( file_exists( SM_PATH . 'locale/ar') ) {
  454. $languages['ar']['NAME'] = 'Arabic';
  455. $languages['ar']['CHARSET'] = 'windows-1256';
  456. $languages['ar']['DIR'] = 'rtl';
  457. }
  458. if ( file_exists( SM_PATH . 'locale/he_IL') ) {
  459. $languages['he_IL']['NAME'] = 'Hebrew';
  460. $languages['he_IL']['CHARSET'] = 'windows-1255';
  461. $languages['he_IL']['DIR'] = 'rtl';
  462. $languages['he']['ALIAS'] = 'he_IL';
  463. }
  464. /* Detect whether gettext is installed. */
  465. $gettext_flags = 0;
  466. if (function_exists('_')) {
  467. $gettext_flags += 1;
  468. }
  469. if (function_exists('bindtextdomain')) {
  470. $gettext_flags += 2;
  471. }
  472. if (function_exists('textdomain')) {
  473. $gettext_flags += 4;
  474. }
  475. /* If gettext is fully loaded, cool */
  476. if ($gettext_flags == 7) {
  477. $use_gettext = true;
  478. }
  479. /* If we can fake gettext, try that */
  480. elseif ($gettext_flags == 0) {
  481. $use_gettext = true;
  482. include_once(SM_PATH . 'functions/gettext.php');
  483. } else {
  484. /* Uh-ho. A weird install */
  485. if (! $gettext_flags & 1) {
  486. function _($str) {
  487. return $str;
  488. }
  489. }
  490. if (! $gettext_flags & 2) {
  491. function bindtextdomain() {
  492. return;
  493. }
  494. }
  495. if (! $gettext_flags & 4) {
  496. function textdomain() {
  497. return;
  498. }
  499. }
  500. }
  501. /*
  502. * Japanese charset extra function
  503. *
  504. */
  505. function japanese_charset_xtra() {
  506. $ret = func_get_arg(1); /* default return value */
  507. if (function_exists('mb_detect_encoding')) {
  508. switch (func_get_arg(0)) { /* action */
  509. case 'decode':
  510. $detect_encoding = @mb_detect_encoding($ret);
  511. if ($detect_encoding == 'JIS' ||
  512. $detect_encoding == 'EUC-JP' ||
  513. $detect_encoding == 'SJIS' ||
  514. $detect_encoding == 'UTF-8') {
  515. $ret = mb_convert_kana(mb_convert_encoding($ret, 'EUC-JP', 'AUTO'), "KV");
  516. }
  517. break;
  518. case 'encode':
  519. $detect_encoding = @mb_detect_encoding($ret);
  520. if ($detect_encoding == 'JIS' ||
  521. $detect_encoding == 'EUC-JP' ||
  522. $detect_encoding == 'SJIS' ||
  523. $detect_encoding == 'UTF-8') {
  524. $ret = mb_convert_encoding(mb_convert_kana($ret, "KV"), 'JIS', 'AUTO');
  525. }
  526. break;
  527. case 'strimwidth':
  528. $width = func_get_arg(2);
  529. $ret = mb_strimwidth($ret, 0, $width, '...');
  530. break;
  531. case 'encodeheader':
  532. $result = '';
  533. if (strlen($ret) > 0) {
  534. $tmpstr = mb_substr($ret, 0, 1);
  535. $prevcsize = strlen($tmpstr);
  536. for ($i = 1; $i < mb_strlen($ret); $i++) {
  537. $tmp = mb_substr($ret, $i, 1);
  538. if (strlen($tmp) == $prevcsize) {
  539. $tmpstr .= $tmp;
  540. } else {
  541. if ($prevcsize == 1) {
  542. $result .= $tmpstr;
  543. } else {
  544. $result .= str_replace(' ', '',
  545. mb_encode_mimeheader($tmpstr,'iso-2022-jp','B',''));
  546. }
  547. $tmpstr = $tmp;
  548. $prevcsize = strlen($tmp);
  549. }
  550. }
  551. if (strlen($tmpstr)) {
  552. if (strlen(mb_substr($tmpstr, 0, 1)) == 1)
  553. $result .= $tmpstr;
  554. else
  555. $result .= str_replace(' ', '',
  556. mb_encode_mimeheader($tmpstr,'iso-2022-jp','B',''));
  557. }
  558. }
  559. $ret = $result;
  560. break;
  561. case 'decodeheader':
  562. $ret = str_replace("\t", "", $ret);
  563. if (eregi('=\\?([^?]+)\\?(q|b)\\?([^?]+)\\?=', $ret))
  564. $ret = @mb_decode_mimeheader($ret);
  565. $ret = @mb_convert_encoding($ret, 'EUC-JP', 'AUTO');
  566. break;
  567. case 'downloadfilename':
  568. $useragent = func_get_arg(2);
  569. if (strstr($useragent, 'Windows') !== false ||
  570. strstr($useragent, 'Mac_') !== false) {
  571. $ret = mb_convert_encoding($ret, 'SJIS', 'AUTO');
  572. } else {
  573. $ret = mb_convert_encoding($ret, 'EUC-JP', 'AUTO');
  574. }
  575. break;
  576. case 'wordwrap':
  577. $no_begin = "\x21\x25\x29\x2c\x2e\x3a\x3b\x3f\x5d\x7d\xa1\xf1\xa1\xeb\xa1" .
  578. "\xc7\xa1\xc9\xa2\xf3\xa1\xec\xa1\xed\xa1\xee\xa1\xa2\xa1\xa3\xa1\xb9" .
  579. "\xa1\xd3\xa1\xd5\xa1\xd7\xa1\xd9\xa1\xdb\xa1\xcd\xa4\xa1\xa4\xa3\xa4" .
  580. "\xa5\xa4\xa7\xa4\xa9\xa4\xc3\xa4\xe3\xa4\xe5\xa4\xe7\xa4\xee\xa1\xab" .
  581. "\xa1\xac\xa1\xb5\xa1\xb6\xa5\xa1\xa5\xa3\xa5\xa5\xa5\xa7\xa5\xa9\xa5" .
  582. "\xc3\xa5\xe3\xa5\xe5\xa5\xe7\xa5\xee\xa5\xf5\xa5\xf6\xa1\xa6\xa1\xbc" .
  583. "\xa1\xb3\xa1\xb4\xa1\xaa\xa1\xf3\xa1\xcb\xa1\xa4\xa1\xa5\xa1\xa7\xa1" .
  584. "\xa8\xa1\xa9\xa1\xcf\xa1\xd1";
  585. $no_end = "\x5c\x24\x28\x5b\x7b\xa1\xf2\x5c\xa1\xc6\xa1\xc8\xa1\xd2\xa1" .
  586. "\xd4\xa1\xd6\xa1\xd8\xa1\xda\xa1\xcc\xa1\xf0\xa1\xca\xa1\xce\xa1\xd0\xa1\xef";
  587. $wrap = func_get_arg(2);
  588. if (strlen($ret) >= $wrap &&
  589. substr($ret, 0, 1) != '>' &&
  590. strpos($ret, 'http://') === FALSE &&
  591. strpos($ret, 'https://') === FALSE &&
  592. strpos($ret, 'ftp://') === FALSE) {
  593. $ret = mb_convert_kana($ret, "KV");
  594. $line_new = '';
  595. $ptr = 0;
  596. while ($ptr < strlen($ret) - 1) {
  597. $l = mb_strcut($ret, $ptr, $wrap);
  598. $ptr += strlen($l);
  599. $tmp = $l;
  600. $l = mb_strcut($ret, $ptr, 2);
  601. while (strlen($l) != 0 && mb_strpos($no_begin, $l) !== FALSE ) {
  602. $tmp .= $l;
  603. $ptr += strlen($l);
  604. $l = mb_strcut($ret, $ptr, 1);
  605. }
  606. $line_new .= $tmp;
  607. if ($ptr < strlen($ret) - 1)
  608. $line_new .= "\n";
  609. }
  610. $ret = $line_new;
  611. }
  612. break;
  613. case 'utf7-imap_encode':
  614. $ret = mb_convert_encoding($ret, 'UTF7-IMAP', 'EUC-JP');
  615. break;
  616. case 'utf7-imap_decode':
  617. $ret = mb_convert_encoding($ret, 'EUC-JP', 'UTF7-IMAP');
  618. break;
  619. }
  620. }
  621. return $ret;
  622. }
  623. /*
  624. * Korean charset extra function
  625. * Hangul(Korean Character) Attached File Name Fix.
  626. */
  627. function korean_charset_xtra() {
  628. $ret = func_get_arg(1); /* default return value */
  629. if (func_get_arg(0) == 'downloadfilename') { /* action */
  630. $ret = str_replace("\x0D\x0A", '', $ret); /* Hanmail's CR/LF Clear */
  631. for ($i=0;$i<strlen($ret);$i++) {
  632. if ($ret[$i] >= "\xA1" && $ret[$i] <= "\xFE") { /* 0xA1 - 0XFE are Valid */
  633. $i++;
  634. continue;
  635. } else if (($ret[$i] >= 'a' && $ret[$i] <= 'z') || /* From Original ereg_replace in download.php */
  636. ($ret[$i] >= 'A' && $ret[$i] <= 'Z') ||
  637. ($ret[$i] == '.') || ($ret[$i] == '-')) {
  638. continue;
  639. } else {
  640. $ret[$i] = '_';
  641. }
  642. }
  643. }
  644. return $ret;
  645. }
  646. ?>