Typing Japanese in FreeBSD

Thanks to some helpful guides on the Internets, I managed to finally get my installation of FreeBSD to type Japanese. The technology has definitely come a long way since I last tried this a few years ago, and documentation hasn’t always caught up with the changes, but some brave folks have posted their experiences for others to read, so I wanted to share what worked for me.

Some background first on my system:

  • OS: FreeBSD 7.2, running virtually on my Mac via Parallels.
  • Using GNOME 2.26 as my window manager.
  • Using public-domain Korn Shell (pdksh) as my user-shell. Any Bourne-shell derivative would work too. For some reason, I couldn’t make this work with C-Shell derivatives, probably because I am not setting environment variables right. Comments appreciated.

So, as of writing, FreeBSD provides both the SCIM and Anthy applications. These go hand-in-hand because SCIM provides the common platform for inputting East-Asian languages, while Anthy is what actually lets you type Hiragana, Kanji and such.

If you use FreeBSD packages, you should install the following applications:

pkg_add -r scim ja-anthy ja-scim-anthy ja-kochi-ttfonts ja-kasumi

The last two, ja-kochi-ttfonts and ja-kasumi, are optional, but highly recommended. The Kochi TrueType fonts make Japanese look better, and Kasumi is a kana dictionary.

If using the ports collection this can be done instead by doing the following:

  1. Go into /usr/src/ports/japanese/
  2. Go into each of the follow sub-folders: scim-anthy (installs “scim” too), anthy, kochi-ttfonts, kasumi, and for each one compile like so:

    make && make install && make clean

Notice that the names in ports are slightly different than the packages. This confused me at first, but the end-result is the same. If all five applications are installed, you’re half-way there! Now, you need to do some configurations.

First, you should set X to use your fancy new TrueType fonts. Edit /etc/X11/xorg.conf and add this line just after the other FontPath lines:

FontPath "/usr/local/lib/X11/fonts/TrueType/"

Note that for xorg.conf to read the file correctly, there must be a “tab” before FontPath, or it may not be read correctly. Better safe than sorry.

Now, you need to configure the environment variables. Without these variables set for your account, X will not know what to do with SCIM-Anthy. Set the follow variables in your .profile file for Bourne Shell and derivatives:

export XMODIFIERS=’@im=SCIM’
export GT_IM_MODULE=’scim’
export QT_IM_MODULE=’scim’
export LC_CTYPE=ja_JP.eucJP

If using csh or tcsh, then it’s:

setenv XMODIFIERS @im=SCIM
setenv GT_IM_MODULE scim
setenv QT_IM_MODULE scim
setenv LC_CTYPE ja_JP.eucJP

You could also set $LC_CTYPE to ja_JP.UTF-8, but I’ve found from experience that eucJP just works better for the time being.

Meanwhile, in my .xsession file I add the following line:1

scim -d

Which tells SCIM to run in the background, in daemon-mode. Now, if you log into GNOME either through GDM or from command-line, a small keyboard icon should appear beside the clock. If not, then SCIM is not running.

Now try to run a program like gedit or even Firefox. If you hit CTRL+Space2 then a small box with Japanese characters will appear to the bottom right. Start typing a word in romaji like “nihongo”, then hit Space to select what kanji you want, and finally Return key to select your choice. You can see an example of this here with a screen shot from my virtual FreeBSD machine:

FreeBSD 7.2 with SCIM/Anthy

Best of luck! :)

P.S. Typing this late night rather than doing the dishes. My wife would be appalled. ;)

P.P.S. Pro tip: if you’re a pdksh fan like me, you can enable tab-completion on FreeBSD by adding two lines to .shrc:

bind ^i=complete
bind ^i=complete-list

Just to be sure, you might have to log out entirely first for it to take effect, or at least run them on the command-line just once test. Felt like adding this to the post since I’ll forget later, and it’s too small to justify its own post. :)

1 Or .xinitrc if you’re booting X from command-line, not using GDM or something similar.

2 If you’re running virtually on a Mac like me, then you should disable the CTRL+Space shortcut key on Mac OS, otherwise it will trigger Spotlight instead. Or configure SCIM to use a different hotkey. Both options seem to work. Me? I never use Spotlight anyways.

About these ads

About Doug

A Buddhist, father and Japanophile / Koreaphile.
This entry was posted in Bsd, Japanese, Technology. Bookmark the permalink.

6 Responses to Typing Japanese in FreeBSD

  1. Kendall says:

    Haven’t used FreeBSD yet, but do have Ubuntu installed using VirtualBox on my MacBook. I was curious too about typing Japanese on Linux. I’ve set it up on Mac and Windows, but not Linux. Ubuntu makes it a bit easier than the directions you have here, but I still had to follow a tutorial to get it running well. SCIM is at least already installed. I used <a href="https://help.ubuntu.com/community/JapaneseInput

  2. Kendall says:

    Not sure what happened to the rest of my post. Here’s the rest.

    …”>this write-up and followed the directions for Ubuntu 8.10 even though I have 9.04 installed, as that was the farthest along direction set they had.

    It works good, but I can’t seem to get the key bindings in the SCIM settings to take hold for switching between Hiragana, Katakana, and Latin. It’s a bit of a pain to use the mouse to switch it when you’re typing away.

    Having done the setup on all 3 OSes, I have to say Mac makes it the easiest and is very pain-free. Windows XP was kind of a pain and I’m slowly figuring out the keyboard shortcuts for switching modes. I likely won’t be using Japanese much in Ubuntu so the keyboard shortcuts won’t be much of an issue there.

    Good job getting it setup in FreeBSD. I may give that OS a try one day. I’ve been curious about it since OSX is built on top of it.

  3. Doug says:

    Hi Kendall, I haven’t even tried the key bindings yet. I should give that a try sometime. Definitely Mac is by far the easiest, and I wasn’t even aware that Windows had shortcut keys for IME, but if it does, great.

    The more I use FreeBSD, the more I like it. I was a Linux user for a long time (still do at work, not entirely by choice), but I like BSD’s more UNIX-y feel, and some of the more sensible things it does. Also FreeBSD’s really come a long way since I last tried it a couple years ago.

    Update: I got the key bindings to work so I can switch between hiragana, katana and latin mode. I tried doing shift+ctrl+(something), but I think that conflicted with other existing hot-keys, but when I used scim-setup to bind keys to ctrl+alt and some letter (h for hiragana, k for katakana), it worked after that. :)

  4. Kendall says:

    For Windows XP, here are the shortcuts I found.

    alt+shift: switch between English/Japanese
    alt+` (The key above tab): Latin
    alt+caps lock: katakana カタカナ
    crtl+caps lock: hiragana ひらがな

    Sometimes the one for katakana/hiragana will toggle between the two. The shortcuts don’t always seem to be consistent.

    I was trying to setup the same key bindings you were at first on Linux (shift+ctrl+[j, k, ;]) so I might try some different key bindings to see if they take.

  5. Doug says:

    Cool, thanks for the tips. I’ll try that at work tomorrow. :)

  6. Scott says:

    Just in case this comes up for anyone…. (I came across this page while trying to solve another problem, so, even though it’s a few years old, it comes up in searches. )
    The two links at top, to computertaijutsu and the qnd guide are both my pages. The computertaijutsu one should be changed http://www.srobb.net/jpninpt.html and the second one,the qnd done is obsolete.

    Japanese has become fairly easy in FreeBSD, but (as covered on the srobb page mentioned above), ibus doesn’t seem to recognize hotkeys, and, thanks to a person on FreeBSD forums, there’s a little script that can do the switch between English and Japanese.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s