JapaneseInputHowto

Revision 3 as of 2005-10-08 19:43:10

Clear message

Introduction

As of the Breezy release, the procedure to enable Japanese input has changed and is even simpler. You can find it in the JapaneseInputHowToInBreezy page. The rest of this page is only valid for the previous Ubuntu releases (Warty 4.10 and Hoary 5.04) because the .gnomerc file can't contain input method-related information anymore.

At this time, there is no official support for Japanese input in Ubuntu 4.10. However, it is not too difficult to enable it yourself. This should work for various Chinese and Korean input methods as well, though I haven't tested it.

For Hoary, the installation process is about the same, except for the anthy package: you can install it directly from the universe without problem.

For Breezy, it's even simpler than all the rest thanks to the im-switcher program.

Character encoding

Enable UTF-8 (I'm not absolutely sure this is really necessary, but it is convenient in any case):

In a terminal, do:

    sudo dpkg-reconfigure locales

Select the languages you use with the ".UTF-8" endings. I have en_US.UTF-8, ja_JP.UTF-8 and sv_SE.UTF-8, for instance. Set one of the UTF-8 locales to be the default (I use sv_SE.UTF-8 - choose whichever language you will normally use).

Input method

There are severlas input methods available. We well explain how to install two of them. You can use any of them.

Alternative 1: uim-anthy

Anthy input method

We will use UIM with Anthy as the input method framework and input method, respectively. On top of this, we could use SCIM (which is a higher level system with nice setup dialogues and stuff). It's not really necessary, though, and UIM will work fine by itself.

The input method we will use is called [http://anthy.sourceforge.jp/ Anthy]. It is available in Universe, but is currently not installable, since the kanji dictionary isn't available. So for now, we'll build this package from source.

Don't panic - it's not that hard.

To build the package, we need a c++ compiler. If it's not installed, we can install just typing in a terminal:

    sudo apt-get install g++ build-essential

Now you get Anthy from anthy.sourceforge.jp:

    http://prdownloads.sourceforge.jp/anthy/10139/anthy-5500.tar.gz

We will unpack it, build it, then install: in a terminal, do

    tar -xvzf anthy-5500.tar.gz
    cd anthy-5500
    ./configure --prefix=/usr --sysconfdir=/etc
    make
    sudo make install

Now we should have the anthy library installed.

Maybe you need to restart gnome for the changes to apply.

UIM framework

[http://www.freedesktop.org/Software/uim UIM] is a freedesktop project and very active. The packages in Universe work fine, so we do not need to build it from source. Enable Universe, then search for "uim". Select the "uim" package to install, and it will pull in most packages you want. Add "uim-applet-gnome" as well, to get a nice panel applet.

Note that UIM supports a lot of different input methods, for Japanese, Chinese and Korean, and the Anthy library above may not be necessary for you. For Japanese input, I feel it is by far the most convenient one, however.

Setting up gnome

To have this input method permanently set (works fine for me using three languages so far), create a file .gnomerc (or open it if you already have one), and add

    LC_ALL=ja_JP.UTF-8 uim-xim &
    export GTK_IM_MODULE=uim-anthy
    export XMODIFIERS=@im=uim-anthy
    #export LC_ALL=en_US.UTF-8
    export LC_NUMERIC="en_US.UTF-8"
    export LC_TIME="en_US.UTF-8"
    export LC_COLLATE="en_US.UTF-8"
    export LC_MONETARY="en_US.UTF-8"
    export LC_MESSAGES="en_US.UTF-8"
    export LC_PAPER="en_US.UTF-8"
    export LC_NAME="en_US.UTF-8"
    export LC_ADDRESS="en_US.UTF-8"
    export LC_TELEPHONE="en_US.UTF-8"
    export LC_MEASUREMENT="en_US.UTF-8"
    export LC_IDENTIFICATION="en_US.UTF-8"
    export LC_CTYPE=ja_JP.UTF-8

The xim thing makes it possible for non-gtk applications to use this input method as well.

As uim supports multiple input methods, not only anthy, you need to ensure than the default method will be anthy and no other (like pinyin...). Edit /etc/gtk-2.0/gtk.immodules and move this line

    "uim-anthy" "uim-anthy (ja)" "gtk+" "" "ja"

to the last place (the last one will be the default one). Optionally, change "ja" for "*" to make uim-anthy work for any local, not only japanese.

**Another way to do this** is to create a file named .uim in your home directory, and to put the following lines into it.

    # select anthy as default input method for uim
    (define default-im-name 'anthy)
    # To have the 漢字(半角/全角) key change the input method (in case you have a japanese keyboard)
    (define-key anthy-on-key? '"zenkaku-hankaku")
    (define-key anthy-off-key? '"zenkaku-hankaku")

Also, in my .gnomerc I only have the two following lines, and it works well.

    export XMODIFIERS=@im=uim
    export GTK_IM_MODULE=uim

Testing

To test, restart gnome and start gedit. Right-click to get the context menu, choose "Input Methods", and then check that "uim-anthy" is selected by default. Note all the other uim input methods that are also available (though some of the others, like skk, need external libraries we haven't installed).

Type something - it should be ordinary roman text. Press Shift-Space, however, and type "watashi". It should come out as Hiragana "わたし" (it is Japanese for "I"). If you have the panel applet in the panel, it should change to reflect that you are typing Hiragana. Press Return to "fix" the word, or press Space to konvert it to a Kanji (you want "私"). If you got the wrong Kanji, press Space again to get a selection to choose from. Once you've got the right one, press Return. To type ordinary roman text again, just press Shift-Space once more.

You're typing Japanese!

Applications

As you may already have noticed, most GTK applications work just fine with this setup - Japanese input is never more than a Shift-Space away.

Firefox works fine as well, once you have set up the input method permanently as shown above (you can't get to the input method chooser menu from within, so it will default to a Chinese input method otherwise).

Abiword will work, sort of. Select a Japanese font (Kochi Mincho or Kochi Gothic), then type. You will notice that you do not get a preview where you are typing, but you go get it in a small, weird square up in the upper left corner. Workable, but not really good. There is a bug filed for abiword on this.

Openoffice will work if you set it up permanently as above and start it like this:

    LC_CTYPE=ja_JP.UTF-8 oowriter

Just substitute "ooimpress" or whatever for "oowriter" above. I'm not sure about the best way to make this change permanent.

Alternative 2: canna and kinput2

I would like to describe an alternate input method for Japanese. The system I'm going to describe, canna and kinput2, may represent the 'old style' of doing Japanese input, but it's a fairly mature technology. I followed the steps given here for anthy first, and it works, but I am more accustomed to canna and kinput2, so I'll outline what I did to get them working too.

Canna runs as a server, the client, kinput2, intercepts what you type, sends it to canna for conversion, and sends the result of the conversion to your X-windows application.

First perform the 'Character Encoding' step at the beginning of this page.

using synaptic, or apt-get, install the packages canna, canna-utils, kinput2-canna, libcanna1g

The canna server gets started at boot time, so you shouldn't need to bother with it. When you select Japanese as your language at the gdm screen, you'll want the kinput2 input method to start up. Something like the following in your ~/.gnomerc will do that

   #
   if [ "$LANG" = "ja_JP.EUC-JP" -o "$LANG" = "ja_JP.UTF-8" ]
   then
      export XMODIFIERS='@im=kinput2'
      export XIM_PROG=canna
      export CANNA_SERVER=unix
      export CANNAHOST=unix
      kinput2 -canna&
   fi

I use xfce4 as my desktop, so I had to do just a bit of tweaking to get this same script executed at startup time.

The user interface is very much like Anthy's, shift-space to toggle Japanese mode, arrow around the kanji choices shift-arrow keys to extend or shrink the conversion item.

I'm not sure which method is better, but both are available, and seem to do the job. I was just more accustomed to kinput2, so that's what I use.

Some Hints

Whichever input method you choose, also install the japanese language packs for firefox and for open office, and you get the complete user interface for those applications in Japanese, but only when Japanese is your chosen language.

I have an executable script called 'en' in my personal bin directory, this script changes the environment to English for a single command. I can execute, for example:

   en gedit

when my language is Japanese, and gedit runs with English menus, and the Japanese input method disabled. Very handy at times. Here's what that script looks like

   LC_ALL=en_US LANGUAGE=en_US GDM_LANG=en_US XMODIFIERS= LANG=en_US $*

Wherever you put this script, don't forget to make it executable! 'chmod +x en'

Add the following lines to /usr/X11R6/lib/X11/app-defaults/Kinput2 if you choose kinput2. It will remedy some problems with OpenOffice.

  !
  !       the following lines added to fix problems with Open Office
  !       reference http://lists.suse.com/archive/m17n/2002-May/0056.html
  *SeparateConversion.input: false
  *selectionShell.input: false
  *auxShell.input: false

Not an issue with Anthy.

  • Ubuntu/Kubuntu Hoary Hedgehog 5.04

Make sure you have universe enabled in order to get the packages.

1) $ sudo apt-get install uim anthy scim-gtk2-immodule scim-uim

2) Create a file called 75custom-write_japanese in /etc/X11/Xsession.d

3) Paste the following into it export XMODIFIERS="@im=SCIM" export GTK_IM_MODULE="scim" export XIM_PROGRAM="scim -d" export QT_IM_MODULE="scim"

4) sudo dpkg-reconfigure locales Select en_US.UTF-8 as default, it may be already.

5)System->Preferences->Sessions Startup Programs Add scim -d I left the order at 50

5a)For KDE users/Kubuntu users Create a file startscim in .kde/Autostart/ Paste the following text. #!/bin/sh scim -d Then chmod 744 startscim

6)Restart X or Reboot, Welcome to Japanese Input! I did not create any of these steps. This was all done by jalosxal http://www.mepis.org/node/5638 a mepis user. and http://www.ubuntulinux.org/wiki/JapaneseInputHowto The only thing I added was Adding it to auto start with gnome.

CategoryDocumentation