Several years ago, I had a pretty hard time trying to get Japanese display and input working in gvim in XFree86 3. My goal was to have a system that was localized for english, but could also display Japanese text and allow me to input it. Thankfully it's become a lot simpler in recent years with advances in glibc and locales handling, as well as the introduction of XFree86 4.0. These instructions were developed and tested in Debian's unstable distribution, codenamed "Sid," but they should be appropriate for any linux installation with a minor amount of tweaking.
In Debian, locales is a seperate package from glibc, so you'll
have to install it in order to generate and use the Japanese locale in Liunx.
During installation, debconf will ask you to choose which locales to generate.
For starters, pick ja_JP.EUC-JP and en_US. You may
also want to choose en_US.UTF-8 and ja_JP.UTF-8 for
unicode support.
After installation, you can choose and generate locales manually by editing /etc/locale.gen. The contents of mine are as follows:
# This file lists locales that you wish to have built. You can find a list # of valid supported locales at /usr/share/doc/locales/SUPPORTED.gz. Other # combinations are possible, but may not be well tested. If you change # this file, you need to rerun locale-gen. en_US ISO-8859-1 en_US.UTF-8 UTF-8 ja_JP.EUC-JP EUC-JP ja_JP.UTF-8 UTF-8After editing the file, run locale-gen as root.
There are several special environment variables that determine how various locale-specific tasks should be handled.
LANG - Specifies the default locale for all unset locale variablesLANGUAGE - Most programs use this for the language of its interfaceLINGUAS - (Obsolete?) The WindowMaker window manager
used to use this instead of LANGUAGE.LC_ALL - Overrides the locale for all LC_ variables and LANGLC_CTYPE - Character handling functionsLC_COLLATE - Affects glob bracket ranges and sort orderLC_MESSAGES - Language that messages should be written in. Most
programs use the value of LANGUAGE instead.LC_NUMERIC - Determines the thousands seperator and how to write floating point numbersLC_TIME - How to format dates and times.Xsession file. These examples assume
your are running a Bourne-like shell, such as sh, bash, or zsh:
export LANGUAGE=en export LINGUAS=en export LC_CTYPE=ja_JP # May break certain things like window maker; untested export LC_TIME=C # Format time as English export LC_NUMERIC=C # Format numbers as English export LC_MESSAGES=C # Output messages in English export LC_COLLATE=ja_JP # Do sorting and collating of characters as Japanese export LANG=ja_JP # Use Japanese for all othersIf you are using a c-shell like csh or tcsh, use the following instead:
setenv LANGUAGE en setenv LINGUAS en setenv LC_CTYPE ja_JP setenv LC_TIME C setenv LC_NUMERIC C setenv LC_MESSAGES C setenv LC_COLLATE ja_JP setenv LANG ja_JP
cannaserver
for you and insert it into your rc scripts for automatic startup on boot. To
install it, run
# apt-get install canna canna-utils libcanna1g
On other systems, you may have to run cannaserver by hand and add it to your rc
scripts yourself.
# apt-get install kinput2-common kinput2-cannaTo make sure you can always input Japanese in your X applications,
you should run kinput2 in your .Xsession file. Insert the following lines after
your environment variable setup section:
export XMODIFIERS="@im=kinput2"
kinput2 -canna &*.inputMethod: kinput2 *.preeditType: OverTheSpot Kinput2*useOverrideShellForMode: true Kinput2*conversionStartKeys: Shift<Key>space ! for Kterm KTerm*VT100*KanjiMode: euc ! for rxvt Rxvt*multichar_encoding: eucj ! for Gvim Vim*international: True Vim*inputMethod: kinput2 Vim*preeditType: OnTheSpotIf you're in X already, be sure to run "
% xrdb -merge .Xresources"
or whatever to have your changes take effect.
(global-unbind-key-function 'japanese-mode)in your ~/.canna file. If you want to do it system-wide, edit the file /etc/canna/default.canna as well. Note that a ~/.canna takes precedence, so if it exists, you must add the line to that file anyway. Also note that for non-debian systems or custom installations, the system-wide file is probably /var/lib/canna/default.canna instead. After editing the file, you should restart X, or at least restart kinput2 as described below. You don't have to restart canna. (Thanks to Norio-san for his page on the matter: http://www.susono.com/~norio/linux/x/c-o.html )
$ LC_ALL=C xterm&Now in the xterm, kill off the current kinput2 and start it up again:
$ kill `pidof kinput2` && kinput2 -canna&It's best to minimize the time for which kinput2 isn't running. Programs currently using the input method may become unstable if they suddenly find it's no longer there. Finally, disown the process in the xterm so the shell won't complain when you exit:
$ disown ; exitNotes:
Kinput2*defaultFontList: -ricoh-ms mincho-medium-r-normal-*-*-160-*-*-*-*-jisx0208.1983-0 Kinput2*JpWcharDisplay.font: -ricoh-ms mincho-medium-r-normal-*-*-160-*-*-c-*-iso8859-1 Kinput2*JpWcharDisplay.kanjiFont: -ricoh-ms mincho-medium-r-normal-*-*-160-*-*-c-*-jisx0208.1983-0 Kinput2*JpWcharDisplay.kanaFont: -ricoh-ms mincho-medium-r-normal-*-*-160-*-*-c-*-jisx0201.1976-0See 'man kinput2' for more information. Restart your X server to have the changes take effect, or use 'xrdb -merge ~/.Xresources' and follow the instructions above for restarting kinput2.
# apt-get install rxvt rxvt-mlThen run krxvt and you should be able to view and input Japanese.