Home Page of Alberto Lepe Garza
About Japan
About Japan

Japanese SupportJapanese Support

Several times I required to enable Japanese in my Linux or in my web pages. This is a quick reference of how to setup your Linux or Web pages in order to display or use Japanese correctly.

Japanese in Ubuntu

Since I'm currently using Ubuntu, I will show first how to enable it in Ubuntu. When I was using Slackware the process was quite different, you may wish to look at the links I added at the end of this page.

How to enable Japanese IME in Ubuntu Linux:

1. sudo apt-get install uim anthy scim-gtk2-immodule scim-uim
2. in /etc/X11/Xsession.d/
create: 78japanese_ime:
export XMODIFIERS="@im=SCIM"
export GTK_IM_MODULE="scim"
export XIM_PROGRAM="scim -d"
export QT_IM_MODULE="scim"
3. sudo dpkg-reconfigure locales

4. It is recommendable to install additional Japanese fonts.


UPDATE: I tried my method in KDE but it didn't work, so I found out that you may require to install one more package:


sudo apt-get install scim-bridge


Then, edit the file /etc/X11/xinit/xinput.d/scim and replace the value of "GTK_IM_MODULE" and "QT_IM_MODULE" from "xim" to "scim-bridge".


Your file may look like this:


XIM=SCIM
XIM_PROGRAM=/usr/bin/scim
XIM_ARGS="-d"
XIM_PROGRAM_SETS_ITSELF_AS_DAEMON=yes
GTK_IM_MODULE="scim-bridge"
QT_IM_MODULE="scim-bridge"
DEPENDS="scim,scim-anthy|scim-canna|scim-chewing|scim-pinyin|scim-hangle|scim-prime|scim-skk|scim-tables-additional|scim-m17n|scim-u
im|scim-tables-ja|scim-tables-ko|scim-tables-zh"


 

Japanese in Php:

How to enable Japanese in Php (this may change in PHP6):

1. Compile your php with the --enable-mbstring argument, or add the respective module.

2. In your php.ini:
[mbstring]
mbstring.language = Japanese
; you may want to change this encoding according to your preference
mbstring.internal_encoding = UTF-8
; this is important to be able to manipulate coding in forms.
mbstring.http_input = pass
; also you can modify this encoding to EUC-JP / Shift_JIS / ISO-2022-JP / UTF-16
mbstring.http_output = UTF-8
mbstring.detect_order = auto
mbstring.substitute_character = none;
3. In the top your php file:
define (CHARSET,"EUC-JP");
header("Content-Type: text/html; charset=".CHARSET);
additionally, it is recommendable to add it to your meta tags:

This CHARSET, means the encoding of your data. For example if you store as EUC-JP your data in your database, in order to show it correctly (without any transformation) to that value.

Sometimes will be desire to receive in your forms with certain encoding, to do so, add at you
tag:

In this way, you can ensure you will receive your coding as UTF-8.

To ensure 100% that a kanji will display correctly in old browsers as well, you can convert the kanjis to htmlentities:


function utf2code($utf){
$full_code = "";
for($mbl = 0; $mbl < mb_strlen($utf); $mbl++){
$kanji = mb_substr($utf,$mbl,1);
$len = strlen($kanji);
for($ul=0;$ul<$len;$ul++){
$k[$ul] = ord(substr($kanji,$ul,1));
}
switch($len){
case 1: $code = $k[0]; break;
case 2: $code = ((($k[0]-192)<<6)+$k[1]-128); break;
case 3: $code = ((($k[0]-224)<<12)+(($k[1]-128)<<6)+$k[2]-128); break;
case 4: $code = ((($k[0]-240)<<18)+(($k[1]-128)<<12)+(($k[2]-128)<<6)+$k[3]-128); break;
}
if($code > 0) $full_code .= "&#".$code.";";
}
return $full_code;
}



Links

Enable Japanese in Linux (other distribuitions):


http://home.nyc.rr.com/computertaijutsu/jpninpt.html (FreeBSD, NetBSD)

http://promulgate.xs4all.nl/sowr/index.cgi?list=usage_10&l=n#req (Slackware)

http://yudit.org/download.html (Yudit download)

http://help.ubuntu.com/community/SCIM (Ubuntu SCIM help)


Site Map - CopyLeft 2008 - Powered by Yayahuic Framework - Made by Alberto Lepe G.
Check http header Validate webpage Validate style sheet Check accessibility