Japanese Input and Display in X under Linux

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.



Installing the locales package

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-8
After editing the file, run locale-gen as root.

Setting up the environment

There are several special environment variables that determine how various locale-specific tasks should be handled.

To run X with an English interface but the ability to display, input, and copy-paste Japanese text, set the environment variables as follows prior to running X or in your .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 others
If 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      

Setting up the conversion server and the input engine

Setting up .Xresources

Add the following lines to your .Xresources file (for non-Debian distributions, this might be called .Xdefaults):
*.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: OnTheSpot
If you're in X already, be sure to run "% xrdb -merge .Xresources" or whatever to have your changes take effect.

Inputting Japanese

Now when you start X and a Japanese-aware application, you should be able to use shift-space to begin Japanese input. A little window containing a Japanese hiragana "A" should appear, and what you type will become hiragana as you go. Hit space to transform short segments of hiragana into Kanji, or ctrl-n to cycle through katakana, half-width katakana, double-width romaji, normal romaji, and back to hiragana. Hit enter to set your choice, space to choose the next kanji, or backspace to go back to entering more hiragana. Hit shift-space again to leave Japanese input mode, but beware that any text you haven't set by hitting enter will be lost.

Tips:


Helpful Software:

[ Home ]

Steven Mueller, diffusor@ugcs.caltech.edu
This page created: Saturday March 23, 2002
Last modified: Fri May 10 16:42:18 PDT 2002
(created/edited with Vim)