Translated using Weblate (Dutch)
[phpmyadmin.git] / libraries / kanji-encoding.lib.php
blobb879c3c0fd007e13cc087adf587493d683e051dd
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Set of functions for kanji-encoding convert (available only with japanese
5 * language)
7 * PHP4 configure requirements:
8 * --enable-mbstring --enable-mbstr-enc-trans --enable-mbregex
10 * 2002/2/22 - by Yukihiro Kawada <kawada@den.fujifilm.co.jp>
12 * @package PhpMyAdmin
14 if (! defined('PHPMYADMIN')) {
15 exit;
18 /**
19 * Gets the php internal encoding codes and sets the available encoding
20 * codes list
21 * 2002/1/4 by Y.Kawada
23 * @global string $kanji_encoding_list the available encoding codes list
25 * @return boolean always true
27 function PMA_Kanji_checkEncoding()
29 global $kanji_encoding_list;
31 $internal_enc = mb_internal_encoding();
32 if ($internal_enc == 'EUC-JP') {
33 $kanji_encoding_list = 'ASCII,EUC-JP,SJIS,JIS';
34 } else {
35 $kanji_encoding_list = 'ASCII,SJIS,EUC-JP,JIS';
38 return true;
39 } // end of the 'PMA_Kanji_checkEncoding' function
42 /**
43 * Reverses SJIS & EUC-JP position in the encoding codes list
44 * 2002/1/4 by Y.Kawada
46 * @global string $kanji_encoding_list the available encoding codes list
48 * @return boolean always true
50 function PMA_Kanji_changeOrder()
52 global $kanji_encoding_list;
54 $parts = explode(',', $kanji_encoding_list);
55 if ($parts[1] == 'EUC-JP') {
56 $kanji_encoding_list = 'ASCII,SJIS,EUC-JP,JIS';
57 } else {
58 $kanji_encoding_list = 'ASCII,EUC-JP,SJIS,JIS';
61 return true;
62 } // end of the 'PMA_Kanji_changeOrder' function
65 /**
66 * Kanji string encoding convert
67 * 2002/1/4 by Y.Kawada
69 * @param string $str the string to convert
70 * @param string $enc the destination encoding code
71 * @param string $kana set 'kana' convert to JIS-X208-kana
73 * @global string $kanji_encoding_list the available encoding codes list
75 * @return string the converted string
77 function PMA_Kanji_strConv($str, $enc, $kana)
79 global $kanji_encoding_list;
81 if ($enc == '' && $kana == '') {
82 return $str;
84 $string_encoding = mb_detect_encoding($str, $kanji_encoding_list);
85 if ($string_encoding === false) {
86 $string_encoding = 'utf-8';
89 if ($kana == 'kana') {
90 $dist = mb_convert_kana($str, 'KV', $string_encoding);
91 $str = $dist;
93 if ($string_encoding != $enc && $enc != '') {
94 $dist = mb_convert_encoding($str, $enc, $string_encoding);
95 } else {
96 $dist = $str;
98 return $dist;
99 } // end of the 'PMA_Kanji_strConv' function
103 * Kanji file encoding convert
104 * 2002/1/4 by Y.Kawada
106 * @param string $file the name of the file to convert
107 * @param string $enc the destination encoding code
108 * @param string $kana set 'kana' convert to JIS-X208-kana
110 * @return string the name of the converted file
112 function PMA_Kanji_fileConv($file, $enc, $kana)
114 if ($enc == '' && $kana == '') {
115 return $file;
118 $tmpfname = tempnam('', $enc);
119 $fpd = fopen($tmpfname, 'wb');
120 $fps = fopen($file, 'r');
121 PMA_Kanji_changeOrder();
122 while (!feof($fps)) {
123 $line = fgets($fps, 4096);
124 $dist = PMA_Kanji_strConv($line, $enc, $kana);
125 fputs($fpd, $dist);
126 } // end while
127 PMA_Kanji_changeOrder();
128 fclose($fps);
129 fclose($fpd);
130 unlink($file);
132 return $tmpfname;
133 } // end of the 'PMA_Kanji_fileConv' function
137 * Defines radio form fields to switch between encoding modes
138 * 2002/1/4 by Y.Kawada
140 * @return string xhtml code for the radio controls
142 function PMA_Kanji_encodingForm()
144 return "\n"
145 . '<ul>' . "\n" . '<li>'
146 . '<input type="radio" name="knjenc" value="" checked="checked" '
147 . 'id="kj-none" />'
148 . '<label for="kj-none">'
149 /* l10n: This is currently used only in Japanese locales */
150 . _pgettext('None encoding conversion', 'None')
151 . "</label>\n"
152 . '<input type="radio" name="knjenc" value="EUC-JP" id="kj-euc" />'
153 . '<label for="kj-euc">EUC</label>' . "\n"
154 . '<input type="radio" name="knjenc" value="SJIS" id="kj-sjis" />'
155 . '<label for="kj-sjis">SJIS</label>' . "\n"
156 . '</li>' . "\n" . '<li>'
157 . '<input type="checkbox" name="xkana" value="kana" id="kj-kana" />'
158 . "\n"
159 . '<label for="kj-kana">'
160 /* l10n: This is currently used only in Japanese locales */
161 . __('Convert to Kana')
162 . '</label><br />'
163 . "\n"
164 . '</li>' . "\n" . '</ul>'
166 } // end of the 'PMA_Kanji_encodingForm' function
169 PMA_Kanji_checkEncoding();