| English | 日本語 |

Tokyo Linux Users Group

The Super Quick Version

This will work in most versions of Linux. This quick guide is aimed towards a Linux using beginner who boots into X. #FreeBSD and #NetBSD have their own sections, each beginning with a quickstart guide. (Actually, the quickstart guide for NetBSD uses uim rather than scim, but at present, I don't think it really merits a separate page.)

export XMODIFIERS='@im=SCIM'
export LC_CTYPE=ja_JP.utf8  
export GTK_IM_MODULE=“scim”
export QT_IM_MODULE=“scim”
scim -d

(See #Environment, #Locale and #Starting Scim)

locale -a |grep ja_JP 

terminal. (See #Terminals)

If you boot into console mode rather than boot into an Xsession, add the export and scim -d lines to your .xinitrc rather than your bash profile. Add them above the line that calls the window manager.

Would you explain that please? It didn't work

Ok, the much longer version.

Installation

Japanese in Linux and other Unix like systems, becomes easier all the time. Most of this howto will focus on using the scim editor, anthy conversion method and scim-anthy input engine. Note that this howto will only refer to inputting Japanese in X, not the console.

Most distributions now have packages for scim, anthy and scim-anthy. As scim-anthy needs anthy and scim to work, a package manager that takes care of dependencies (e.g., apt, yum, pacman and emerge) should install all three programs. For example, in Ubuntu, one can do

apt-get install scim-anthy

This will also install scim and scim-anthy.

If your distribution doesn't have a scim-anthy package, and you have to build it from source, do it in the following order. Download and install anthy. After downloading the tarball

tar zxvf anthy-.tar.gz
cd anthy-
./configure --prefix=/usr && make && make install 

Replace with whatever version you download, I believe it's 8700b at time of writing.

This will install the anthy libraries in /usr rather than its default of /usr/local. If you prefer to have programs in /usr/local then leave out the --prefix=/usr/ part.

Once anthy is installed, you can download and install scim. It is installed in the same way

tar zxvf scim-.tar.gz
cd scim-
./configure --prefix=/usr && make && make install

Lastly do the same with scim-anthy. Note that the order of installation is important, first install anthy, then scim, and lastly scim-anthy.

If you install from source, you are often better off installing everything from source. That is, if your distribution has a package for scim, but not scim-anthy, it might put scim in some odd place where scim-anthy won't be able to find it. So, if you have to install any of the three programs from source, install all three of them from source.

Environment

For scim to work, you must set some environment variables. I've often gotten by with simply setting XMODIFIERS and setting LC_CTYPE to my native locale with UTF-8 encoding.

export XMODIFIERS='@im=SCIM'
export LC_CTYPE=en_US.utf8

However, this doesn't work all the time, which is one reason the quick guide takes a more conservative approach. Sometimes, your native language in UTF-8 will only work if you set the GTK_IM_MODULE and QT_IM_MODULE lines. It might vary with distribution and even application. I haven't found any real pattern to it, though one probably exists.

Setting the LC_CTYPE to Japanese rather than your native language doesn't seem to really affect any of the programs that I use. If you'd rather have the LC_CTYPE in your native language. feel free to try it. If it doesn't work, be sure that you have the GTK_IM_MODULE and QT_IM_MODULE variables set as in the quick start at the beginning of this article.

In the quick start, I say that one should add the variables to their .bash_profile. This way, they're set whenever you log into the system. If you use Ubuntu, Fedora, PCLINUXOS or any of the more popular newcomer friendly distros, they boot up into a graphical environment. However, if you're using Slackware, ArchLinux or Gentoo, you often choose to boot into a console. If you boot into text mode, then you don't necessary need these variables set till you start X. In that case, you might simply put these settings into your .xinitrc. Put it in before the line that calls your window manager, for example

export XMODIFIERS='@im=SCIM'
export LC_CTYPE=ja_JP.utf8
export GTK_IM_MODULE=“scim”
export QT_IM_MODULE=“scim”
scim -d
exec fluxbox

Locale

These days, most distributions include locales by default. Some of them, for example, ArchLinux, don't. With Arch, you have to uncomment the locales that you want to have in /etc/locale.gen then run the command

locale-gen

With Debian, at one point (I haven't used it for awhile, this may no longer be the case) you had to first install and configure locales.

apt-get install locales
dpkg-reconfigure locales

(This might be what Ubuntu does when you choose to add Japanese support from their System, Administration, Language Support menu, as well as add #Fonts. It's possible that rather than installing everything Ubuntu thinks you'll need for Japanese support, just doing the above would suffice.)

Although most distributions use ja_JP.utf8 one should always check this

locale | grep ja_JP

Sometimes, you might get an answer like ja_JP.utf-8 or ja_JP.UTF8. This is case sensitive so set your LC_CTYPE according to the result. Otherwise, you'll get an error message like locale not supported by environment. (Depending upon the application, you might not see that message, but if for example, you open one terminal from another terminal, you will see it.)

Starting Scim

In the quick start, scim is started as soon as you log in. It doesn't seem to use too many resources, so this won't really hurt anything. It can be done that way, although if you boot into text mode, you might, as shown above, put it in .xinitrc rather than your .bash_profile. However, if you only use it on rare occasions, you eliminate that line in your startup file (whether it be .bash_profile or .xinitrc) and just call it when needed. Open a terminal window and type

scim -d

Once scim starts, you can then use it in your applications. (It might not work in the terminal that you used to start it, however. Also, if you already have, for example, firefox running, you might have to restart firefox to get scim to work with it.

Fonts

Many distributions include Japanese fonts by default. However, if they don't, you'll have to install them. With Ubuntu, fonts are installed if you choose to add Japanese support. With RedHat and its offshoots, one can search for Japanese fonts with

yum search fonts-ja

At different times, I've had different results. For instance, CentOS offered ttfonts-ja, Fedora offered something like fonts-japanese.noarch. Regardless, the search for fonts-ja usually gave me results. In ArchLinux one adds ttf-arphic-uming and ttf-arphic-ukai with pacman.

One can always donwnload the substitute kochi fonts from sourceforge.jp. Get the package kochi-substitute-20030809.tar.bz2. Decompress and untar it, and it will create a kochi-substitute-20030809 directory. In the directory you'll see two files with a ttf ending, the kochi-gothic and kochi-mincho substitute fonts. Move them into one of the directories that your distribution searches for fonts--as mentioned above, you can grep FontPath in /etc/X11/xorg.conf.

For the beginner, you decompress and untar it with

tar jxvf kochi-substitute-20030809.tar.bz2

Most font directories (a popular location on many distros is /usr/X11R6/lib/X11/fonts) will already have a truetype, TrueType or TTF directory. Move the fonts into one of those (after making sure that directory is listed in your xorg.conf's FontPaths.)

Terminals

If you wish to use Japanese in an xterm with mutt or other text files, you will also need a terminal capble of displaying Japanese. Not every terminal can display UTF-8 encoding. Some terminals can't display any Asian characters, others, such as rxvt and mrxvt, will be able to use the older EUC encoding, but not UTF-8. The default xterm cannot display Japanese, however, these days, most systems also install uxterm, which can display UTF-8. If you use Gnome, KDE, or Xfce, their default terminals work. The vim editor usually has no trouble with Japanese, however, Slackware and some others actually use elvis. (The BSD's use nvi). One way to tell is do

which vi

You might get an answer like

/usr/bin/vi

Now do

ls -l /usr/bin/vi

In Slackware, you'd see something like

/usr/bin/vi -> /usr/bin/elvis

Install vim (it's available as a Slackware package) if it's not already installed, and change the symbolic link to point to vim. For example

cd /usr/bin
rm vi
ln -s vim vi

Make sure vim is in /usr/bin first by typing the command

which vim

Using scim

To switch to Japanese conversion, hit Ctrl+space. You should see a small widget appear in the lower right hand corner of your screen. If you type in romaji, for example shi, you should then see the hiragana for shi. Hitting the space bar will bring up a list of kanji--you can navigate the kanji with the arrow keys. Hitting space again will select the kanji that you've chosen.

In a few recent Fedora 7 installations, Ctl+space didn't work. Generally, when scim-anthy is installed, a $HOME/.scim/config file is created, with various defaults, includng that of using Ctl+space to open and close the input widget. In these Fedora installs, that line was blank. The scim-anthy application itself was working without problem, as long as I clicked on the icon it placed in the upper right of the Gnome screen when I started scim.

In this case, I was able to fix it by opening my $HOME/.scim/config file and adding the line

/Hotkeys/FrontEnd/Trigger = Control+space

to it. (Note that you can use other key combinations if you prefer--I find that Ctrl+space is convenient for me, and these Fedora installs aside, it is the default.)

If you are in an application that will not support scim, for example a standard xterm, then when you hit Ctl+space you won't see anything. If you see kana, but only see squares when you hit the space bar to bring up kanji, it means (and this is in the scim FAQ) that scim can't find the fonts. Check your font paths in xorg.conf with

grep FontPath /etc/X11/xorg.conf

and make sure that some Japanese fonts are there. (See #Fonts)

FreeBSD

Once again, the quick start.

cd /usr/ports/japanese/scim-anthy
make install clean

cd /usr/ports/japanese/kochi-ttfonts
make install clean

export XMODIFIERS='@im=SCIM'
export LC_CTYPE=ja_JP.UTF-8
export GTK_IM_MODULE=“scim”
export QT_IM_MODULE=“scim”
scim -d

The rest is the same as #The Super Quick Version for Linux. The only real difference here is that while most versions of Linux use ja_JP.utf8, FreeBSD uses ja_JP.UTF-8. As previously mentioned, when setting LC_CTYPE, case is important.

NetBSD

The quickstart version of NetBSD doesn't use scim-anthy, however, as mentioned at the very beginning of this article, I didn't feel it was worth giving it a separate page. The basic concepts are relatively similar.

NetBSD's pkgsrc doesn't yet have scim-anthy. It does, however, have anthy and uim, another popular input method.

cd /usr/pkgsrc/inputmethod/anthy
make install clean; make clean-depends
cd /usr/pkgsrc/inputmethod/uim
make PKG.OPTIONS.uim="-canna' install clean; make clean-depends

cd /usr/pkgsrc/fonts/kochi-ttf
make install clean; make clean-depends

ftp ftp://ftp.NetBSD.org

After you're connected

cd pub/NetBSD/NetBSD-current/src/share/locale/ctype
get en_US.UTF-8.src

For our example, we'll assume that you logged on as user joe and put the UTF-8.src file in your home directory

cd /usr/share/locale
sudo make locale < /home/joe/en_US.UTF-8.src > ja_JP.UTF-8

(I'm not sure if you'd use the & if you boot into X and add it to your shell's profile--most of the NetBSD users I know boot into text mode though)

export XMODIFIERS=@im=uim
uim-xim --engine=anthy &

NetBSD also has a collection of WIP (Work in Progress) packages. (That link takes you to the main page, which explains how to download and install the WIP tree.) As the page explains, you untar the WIP pkgsrc tree in your /usr/pkgsrc directory. Then, you can cd into the WIP scim-anthy directory and do the usual make install clean; make clean-depends.

If the package fails to build with an unable to allocate memory error, add the following to the scim-anthy Makefile's configuration options. (If you look at the Makefile, it will be fairly plain where these are.)

UNLIMIT_RESOURCES=      datasize

After that scim-anthy can be used in the same way it's used with Linux or FreeBSD, adding the various XMODIFIER and LC_CTYPE lines to your .xinitrc, along with scim -d if you want it to always be running. It will then be called with Ctrl+space and work as you would expect, entering romaji, seeing hiragana and hitting the space bar to view available kanji.

Using_scim-anthy