Added i18n.php and moved som functionality to that file.
[squirrelmail.git] / functions / i18n.php
CommitLineData
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.
11 **/
12
13 $i18n_php = true;
14
15 // Decodes a string to the internal encoding from the given charset
16 function charset_decode ($charset, $string) {
17 // All HTML special characters are 7 bit and can be replaced first
18 $string = htmlspecialchars ($string);
19
20 $charset = strolower($charset);
21
22 if (ereg("iso-8859-(.*)", $charset, $res)) {
23 if ($res[1] == "1")
24 return charset_decode_iso_8859_1 ($string);
25 else if ($res[1] == "15")
26 return charset_decode_iso_8859_15 ($string);
27 else
28 return charset_decode_iso_8859_default ($string);
29 } else if ($charset == "ns_4551-1") {
30 return charset_decode_ns_4551_1 ($string);
31 } else
32 return $string;
33 }
34
35 // iso-8859-1 is the same as Latin 1 and is normally used
36 // in western europe.
37 function charset_decode_iso_8859_1 ($string) {
38 // This is only debug code as long as the internal
39 // character set is iso-8859-1
40
41 // Latin small letter o with stroke
42 while (ereg("\370", $string))
43 $string = ereg_replace ("\370", "&#248;", $string);
44
45 return ($string);
46 }
47
48 // iso-8859-15 is Latin 15 and has very much the same use as Latin 1
49 // but has the Euro symbol and some characters needed for French.
50 function charset_decode_iso_8859_15 ($string) {
51 // Euro sign
52 while (ereg("\244", $replace))
53 $string = ereg_replace ("\244", "&#8364;", $string);
54 // Latin capital letter S with caron
55 while (ereg("\246", $string))
56 $string = ereg_replace ("\244", "&#352;", $string);
57 // Latin small letter s with caron
58 while (ereg("\250", $string))
59 $string = ereg_replace ("\250", "&#353;", $string);
60 // Latin capital letter Z with caron
61 while (ereg("\264", $string))
62 $string = ereg_replace ("\264", "&#381;", $string);
63 // Latin small letter z with caron
64 while (ereg("\270", $string))
65 $string = ereg_replace ("\270", "&#382;", $string);
66 // Latin capital ligature OE
67 while (ereg("\274", $string))
68 $string = ereg_replace ("\274", "&#338;", $string);
69 // Latin small ligature oe
70 while (ereg("\275", $string))
71 $string = ereg_replace ("\275", "&#339;", $string);
72 // Latin capital letter Y with diaeresis
73 while (ereg("\276", $string))
74 $string = ereg_replace ("\276", "&#376;", $string);
75
76 return ($string);
77 }
78
79 // Remove al 8 bit characters from all other ISO-8859 character sets
80 function charset_decode_iso_8859_default ($string) {
81 return (strtr($string, "\240\241\242\243\244\245\246\247".
82 "\250\251\252\253\254\255\256\257".
83 "\260\261\262\263\264\265\266\267".
84 "\270\271\272\273\274\275\276\277".
85 "\300\301\302\303\304\305\306\307".
86 "\310\311\312\313\314\315\316\317".
87 "\320\321\322\323\324\325\326\327".
88 "\330\331\332\333\334\335\336\337".
89 "\340\341\342\343\344\345\346\347".
90 "\350\351\352\353\354\355\356\357".
91 "\360\361\362\363\364\365\366\367".
92 "\370\371\372\373\374\375\376\377",
93 "????????????????????????????????????????".
94 "????????????????????????????????????????".
95 "????????????????????????????????????????".
96 "????????"));
97
98 }
99
100 // This is the same as ISO-646-NO and is used by some
101 // Microsoft programs when sending Norwegian characters
102 function charset_decode_ns_4551_1 ($string) {
103 // These characters are:
104 // Latin capital letter AE
105 // Latin capital letter O with stroke
106 // Latin capital letter A with ring above
107 // and the same as small letters
108 return strtr ($string, "[\\]{|}", "");
109 }
110
111?>