Translation update done using Pootle.
[phpmyadmin/madhuracj.git] / libraries / kanji-encoding.lib.php
blob86c4f09a16dcc47f5172bcdee604bcde0a91b39e
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 the current encoding code
24 * @global string the available encoding codes list
26 * @return boolean always true
28 function PMA_internal_enc_check()
30 global $internal_enc, $enc_list;
32 $internal_enc = mb_internal_encoding();
33 if ($internal_enc == 'EUC-JP') {
34 $enc_list = 'ASCII,EUC-JP,SJIS,JIS';
35 } else {
36 $enc_list = 'ASCII,SJIS,EUC-JP,JIS';
39 return true;
40 } // end of the 'PMA_internal_enc_check' function
43 /**
44 * Reverses SJIS & EUC-JP position in the encoding codes list
45 * 2002/1/4 by Y.Kawada
47 * @global string the available encoding codes list
49 * @return boolean always true
51 function PMA_change_enc_order()
53 global $enc_list;
55 $p = explode(',', $enc_list);
56 if ($p[1] == 'EUC-JP') {
57 $enc_list = 'ASCII,SJIS,EUC-JP,JIS';
58 } else {
59 $enc_list = 'ASCII,EUC-JP,SJIS,JIS';
62 return true;
63 } // end of the 'PMA_change_enc_order' function
66 /**
67 * Kanji string encoding convert
68 * 2002/1/4 by Y.Kawada
70 * @param string the string to convert
71 * @param string the destination encoding code
72 * @param string set 'kana' convert to JIS-X208-kana
74 * @global string the available encoding codes list
76 * @return string the converted string
78 function PMA_kanji_str_conv($str, $enc, $kana)
80 global $enc_list;
82 if ($enc == '' && $kana == '') {
83 return $str;
85 $nw = mb_detect_encoding($str, $enc_list);
87 if ($kana == 'kana') {
88 $dist = mb_convert_kana($str, 'KV', $nw);
89 $str = $dist;
91 if ($nw != $enc && $enc != '') {
92 $dist = mb_convert_encoding($str, $enc, $nw);
93 } else {
94 $dist = $str;
96 return $dist;
97 } // end of the 'PMA_kanji_str_conv' function
101 * Kanji file encoding convert
102 * 2002/1/4 by Y.Kawada
104 * @param string the name of the file to convert
105 * @param string the destination encoding code
106 * @param string set 'kana' convert to JIS-X208-kana
108 * @return string the name of the converted file
110 function PMA_kanji_file_conv($file, $enc, $kana)
112 if ($enc == '' && $kana == '') {
113 return $file;
116 $tmpfname = tempnam('', $enc);
117 $fpd = fopen($tmpfname, 'wb');
118 $fps = fopen($file, 'r');
119 PMA_change_enc_order();
120 while (!feof($fps)) {
121 $line = fgets($fps, 4096);
122 $dist = PMA_kanji_str_conv($line, $enc, $kana);
123 fputs($fpd, $dist);
124 } // end while
125 PMA_change_enc_order();
126 fclose($fps);
127 fclose($fpd);
128 unlink($file);
130 return $tmpfname;
131 } // end of the 'PMA_kanji_file_conv' function
135 * Defines radio form fields to switch between encoding modes
136 * 2002/1/4 by Y.Kawada
138 * @param string spaces character to prepend the output with
140 * @return string xhtml code for the radio controls
142 function PMA_set_enc_form($spaces)
144 return "\n"
145 /* l10n: This is currently used only in Japanese locales */
146 . $spaces . '<ul>' . "\n" . '<li>'
147 . $spaces . '<input type="radio" name="knjenc" value="" checked="checked" id="kj-none" /><label for="kj-none">' . _pgettext('None encoding conversion', 'None') . "</label>\n"
148 . $spaces . '<input type="radio" name="knjenc" value="EUC-JP" id="kj-euc" /><label for="kj-euc">EUC</label>' . "\n"
149 . $spaces . '<input type="radio" name="knjenc" value="SJIS" id="kj-sjis" /><label for="kj-sjis">SJIS</label>' . "\n"
150 . $spaces . '</li>' . "\n" . '<li>'
151 . $spaces . '<input type="checkbox" name="xkana" value="kana" id="kj-kana" />' . "\n"
152 /* l10n: This is currently used only in Japanese locales */
153 . $spaces . '<label for="kj-kana">' . __('Convert to Kana') . '</label><br />' . "\n"
154 . $spaces . '</li>' . "\n" . '</ul>'
156 } // end of the 'PMA_set_enc_form' function
159 PMA_internal_enc_check();