Uim を使って日本語を入力

提供: ArchWiki
2010年8月19日 (木) 16:49時点におけるimported>Blowbackによる版 (途中まで。)
ナビゲーションに移動 検索に移動

テンプレート:I18n

この記事あるいはセクションは翻訳の途中です。
ノート: please use the first argument of the template to provide more detailed indications. (議論: トーク:Uim を使って日本語を入力#)

このページでは uim を使った日本語入力の方法について説明しています。
もしあなたが SCIM を使っているなら、Smart Common Input Method platform を参照して下さい。

インストール

日本語入力を行うためには、次のパッケージが必要です。

  • 日本語フォント
  • 日本語入力システム (かな漢字変換エンジン): このページでは AnthyMozc について説明します。
  • 入力メソッドフレームワーク: uim

日本語フォント

詳細については Fonts を参照して下さい。

おすすめの日本語フォントは以下の通りです。

高品質かつ無償で利用できるアウトラインフォント。ゴシック体 (サンセリフ体) や明朝体 (セリフ体) グリフを含む。openSUSE の日本語ロケールの標準フォント。
IPAフォントの派生フォント。IPAフォントの問題をコミュニティによって速やかに修正することを目的としている。Ubuntu 日本語ローカライズ版 の日本語標準フォント。
Debian や Fedora の日本語環境、Vine Linux などで採用されている標準フォント。
Mandriva Linux 日本語環境の標準フォント。

2ちゃんねるの Shift JIS アート を適切に表示したい場合、次のいずれかのフォントを使うと良いでしょう:

uim

pacman を使う

uim は次のコマンドでインストールできます。

# pacman -S uim

PKGBUILD を使ってソースから uim をコンパイル

次のような場合、ソースからコンパイルすべきです。

  • Arch リポジトリのパッケージが古い場合。
  • Anthy (UTF-8) を使いたい場合。uim 1.5.7 時点で、Anthy (UTF-8) のサポートは標準では無効になっています (デフォルトの文字エンコーディングは EUC-JP)。
  • KDE を使っていて、uim-qt-tools を使いたい場合。Qt に関するすべてのツールは標準では無効になっています。

ここでは ABS を利用してソースからビルドする方法を説明します。
まず、ABS をインストールします:

# pacman -S abs

ABS を更新します:

# abs

それから、uim のディレクトリを $HOME 以下にコピーします。例えば:

$ cp -R /var/abs/extra/uim ~/sources/

次に、テンプレート:Filename を編集します。代表的なビルドオプションは次の通りです:

Anthy (UTF-8) のサポートを有効にする。
gnome-applet をビルドしない ― gnome-panel を makedepends および optdepends から外せます。
Qt で使えるように uim-tools をビルドする (Qt が必要)。
Qt で使えるように UimQt (Qt immodule サポート) をビルドする (Qt が必要)。

PKGBUILD のサンプルを以下に示します。これは extra/uim 1.5.7 を基に、anthy-utf8 を有効にし、gnome-applet を無効にし、uim のモードアイコンの色を反転するオプション (下記 を参照) を追加したものです。

## You can invert the color of mode icons by uncommenting below line. This is useful for darker theme.
#_icon4darker=yes

pkgname=uim-custom
_pkgname=uim
pkgver=1.5.7
pkgrel=1
pkgdesc="Multilingual input method library"
arch=('i686' 'x86_64')
url="http://code.google.com/p/uim/"
license=('custom')
depends=('m17n-lib' 'ncurses' 'gtk2')
#makedepends=('gnome-panel' 'pkgconfig' 'gettext' 'intltool')
makedepends=('pkgconfig' 'gettext' 'intltool')
#optdepends=('gnome-panel: for using the GNOME applet')
options=('!libtool')
provides=('uim')
conflicts=('uim')
install=uim.install
source=(http://uim.googlecode.com/files/${_pkgname}-${pkgver}.tar.bz2)
md5sums=('b84a43fb92d7ceb4bd801a76120c2a71')

if [[ "$_icon4darker" = "yes" ]]; then
  makedepends=(${makedepends[@]} imagemagick)
  _modify_icons=(
          direct_input.png
          ja_direct.png
          ja_fullwidth_alnum.png
          ja_halfkana.png
          ja_halfwidth_alnum.png
          ja_hiragana.png
          ja_katakana.png
          unknown.png
  )
fi

build() {
  cd "${srcdir}/${_pkgname}-${pkgver}"

  # invert the color of mode icons for darker theme
  if [[ "$_icon4darker" = "yes" ]]; then
    cd pixmaps
    for _icon in ${_modify_icons[@]}
    do
      convert -negate $_icon tmp.${_icon} || return 1
      mv -f tmp.${_icon} $_icon
    done
    cd -
  fi

  ./configure --prefix=/usr --libexecdir=/usr/lib/uim \
              --with-anthy-utf8 \
              --disable-gnome-applet \
              || return 1
  make || return 1
}

package() {
  cd "${srcdir}/${_pkgname}-${pkgver}"

  make DESTDIR="${pkgdir}" install || return 1
  install -D -m644 COPYING "${pkgdir}/usr/share/licenses/${pkgname}/COPYING"
}

最後に、uim ディレクトリで makepkg を実行し、パッケージをビルドおよびインストールします。

$ makepkg -s -i

日本語入力システム

Anthy

Anthy はオープンソースの世界で最も知られているインプットメソッドの一つです。長い間メンテされていませんでしたが、2010年5月より、Debian が引き継ぎました。

Anthy は以下のコマンドでインストールできます:

# pacman -S anthy

Modified Anthy

Modified Anthy はオリジナル Anthy のかな漢字変換の品質向上を狙ったパッチ及び辞書のセットです。

警告: Modified Anthy は Anthy (UTF-8) にのみ対応しています。従って uim は "テンプレート:Codeline" でビルドされていなければなりません。
警告: Modified Anthy はオリジナル Anthy に対し、辞書及び学習データの互換性がありません。

PKGBUILD を使って Modified Anthy をコンパイル

Modified Anthy は、以下の2つのアップストリームからなっています:

  • G-HAL氏によって作成されているパッチの当てられたAnthy
  • UTSUMI氏によって作成されている巨大な辞書。

G-HAL 氏のパッチは自動ダウンロードを許していないので、氏のウェブページから直接手動でダウンロードする必要があります。2010年07月05日現在の安定バージョンは以下のものです:

anthy-9100h.patch13B-23-iconv-ucdict.2010629.alt-depgraph-100603d.alt-cannadic-100603-patch100628.zipdic-201005-patch100614.tar.lzma

「patch13 安定版 系列:」と書かれたセクションにありますので、最新のものを入手してください。

ノート: 2つのアップストリームはいずれも過去のバージョンを残していないか、直接参照できない様になっています。毎回自身で確認し、最新のものを使用するようにしてください。めんどくさいですか? じゃあ、mozc を試してみてください。

サンプルの PKGBUILD を以下に示します:

pkgname=modified-anthy
_pkgname=anthy
pkgver=20100710
_pkgver=9100h
_ghalarc="anthy-9100h.patch13B-23-iconv-ucdict.2010629.alt-depgraph-100603d.alt-cannadic-100603-patch100628.zipdic-201005-patch100614.tar.lzma"
_utver=20100710
pkgrel=1
pkgdesc="Hiragana text to Kana Kanji mixed text Japanese input method"
arch=("i686" "x86_64")
url="http://sourceforge.jp/projects/anthy/"
license=('LGPL' 'GPL')
depends=('glibc')
options=('!libtool' 'force')
provides=("anthy=${_pkgver}")
conflicts=('anthy')
source=(${_ghalarc}
        "http://downloads.sourceforge.net/project/mdk-ut/30-source/source/anthy-ut-patches-${_utver}.tar.bz2")
md5sums=('6be18e8ef5fec087ead4b6ebf798219b'
        'd7321adeaed49dda8b06407c64c91973')

build() {

  cd ${srcdir}

  tar xvf $_ghalarc --lzma

  cd ${srcdir}/${_pkgname}-${_pkgver}

  # UTSUMI dictionalies and patches
  cat anthy-conf.in ${srcdir}/anthy-ut-patches-${_utver}/ghal-patch/conf > anthy-conf.in.new || return 1
  mv -f anthy-conf.in.new anthy-conf.in

  cp -f ${srcdir}/anthy-ut-patches-${_utver}/dictionaries/*         alt-cannadic/
  cp -f ${srcdir}/anthy-ut-patches-${_utver}/zipcode/zipcode.t      mkworddic/
  cp -f ${srcdir}/anthy-ut-patches-${_utver}/mkworddic/dict.args.in mkworddic/dict.args.in

  mkdir -p doc-ut
  cp -f ${srcdir}/anthy-ut-patches-${_utver}/AUTHORS \
        ${srcdir}/anthy-ut-patches-${_utver}/ChangeLog.* \
        ${srcdir}/anthy-ut-patches-${_utver}/README* \
        ${srcdir}/anthy-ut-patches-${_utver}/THANKS \
        doc-ut
  autoreconf -fiv || return 1

  ./configure --prefix=/usr --sysconfdir=/etc || return 1
  make EMACS=emacs sysconfdir=/etc || return 1
}

package() {
  cd ${srcdir}/${_pkgname}-${_pkgver}
  make EMACS=emacs DESTDIR=$pkgdir install || return 1
}

最後に、makepkg でビルド及びインストールします:

$ makepkg -s -i

すでに Anthy を使用していた場合は、既存の学習データのフォーマットを変換しなければなりません。

$ rm ~/.anthy/last-record1_*.bin
$ anthy-agent --update-base-record
$ rm ~/.anthy/last-record1_*.bin
$ anthy-agent --update-base-record

(同じ事を2回繰り返していますが、間違いではありません)

Mozc

Mozc (AUR) は、Google日本語入力 のオープンソース版です。その辞書はGoogle日本語入力と異なり貧弱です。サジェスト機能の具備などの特徴があります。Mozc は公式には ibus と scim にしか対応していませんが、macuim が uim-mozc プラグインを提供しており、AUR の テンプレート:Package AUR で利用可能です。

PKGBUILD を使って Mozc をコンパイル (uim から Mozc を使う)

まず mozc-svn の tarball を AUR から入手するか、yaourt のような AUR ツールを使用し、PKGBUILD を編集します。uim-mozc を有効にするには、以下のように テンプレート:Codeline の行をコメントから外してください。ibusを使用しないなら、テンプレート:Codeline の行をコメントアウトしてください:

## You can choose the input method framework to use either ibus, uim or both.
## If you will be not using ibus, comment out below.
#_ibus_mozc="yes"
## If you will be using uim, uncomment below.
_uim_mozc="yes"
## If you will be using scim, uncomment below.
#_scim_mozc="yes"

日本の郵便番号辞書の構築 (オプション)

mozc は日本郵便 が提供する郵便番号データを辞書シードとしてインポートできます。

郵便番号を辞書に追加するには、PKGBUILD の以下の行をコメントから外してください:

## You can add Japanese zip code provided by Japan Post.
## If you want to use it, uncomment below.
_zipcode="yes"

ビルド、インストール、そして登録

オプションの設定が終わったら、PKGBUILD を保存し、ビルド及びインストールします:

$ makepkg -s -i

最後に、Mozc を uim に登録します。

# uim-module-manager --register mozc
ノート: このコマンドは、uim のアップグレードや (再) インストールのたびに必要です。

Mozc をアンインストールしたときは、Mozcを登録解除してください。

# uim-module-manager --unregister mozc

設定

以下を ~/.xprofile、~/.xinitrc、~/.xsession などに設定します:

環境変数

export GTK_IM_MODULE='uim'
export QT_IM_MODULE='uim'
uim-xim &
export XMODIFIERS=@im='uim'

ツールバーユーティリティ

If you want to use UimToolbar utilities which shows and controls uim mode, add one of the followings too.

uim-toolbar-gtk/qt

Using toolbar appears as a window:

uim-toolbar-gtk &

or if you built テンプレート:Codeline, you can add:

uim-toolbar-qt &

uim-toolbar-gtk-systray

Using toolbar for system tray:

uim-toolbar-gtk-systray &

パネルアプレット

Or, if you use GNOME, KDE or Xfce, you can use uim-toolbar panel applet (Xfce requires xfce4-xfapplet-plugin to use uim-applet-gnome and KDE requires to buid uim with テンプレート:Codeline).

uim の外観

Configure uim preferences by running :

$ uim-pref-gtk

which brings forth a GUI.
Choose テンプレート:Codeline, テンプレート:Codeline or テンプレート:Codeline for 'Default input method'.

ノート: Mozc will be not listed in 'Default input method' at first time so you will need to add it into 'Enabled input methods' to use.


You can run テンプレート:Codeline or restart X to test your settings.
Provided everything went well you should be able to input Japanese in X.

Emacs で uim を使う

uim provides uim.el the bridge software between Emacs and uim.

マイナーモードで使うための設定

Here is a sample to use uim with utf-8 encoding. Add the following into your テンプレート:Filename or some other file for Emacs customizing.

;; read uim.el
(require 'uim)
;; uncomment next and comment out previous to load uim.el on-demand
;; (autoload 'uim-mode "uim" nil t)

;; key-binding for activate uim (ex. C-\)
(global-set-key "\C-\\" 'uim-mode)

;; Set UTF-8 as preferred character encoding (default is euc-jp).
(setq uim-lang-code-alist
      (cons '("Japanese" "Japanese" utf-8 "UTF-8")
           (delete (assoc "Japanese" uim-lang-code-alist) 
                   uim-lang-code-alist)))

;; Set Hiragana input mode at activating uim with anthy (utf-8).
;(setq uim-default-im-prop '("action_anthy_utf8_hiragana"))
;; Set Hiragana input mode at activating uim with mozc.
;(setq uim-default-im-prop '("action_mozc_hiragana"))

Please see Official wiki for more detail.

You may need to add the following to disable xim on Emacs into your テンプレート:Filenames or テンプレート:Filename.

Emacs.UseXIM: false

トラブルシューティング

Opera で日本語入力ができない

If you use Opera and cannot input Japanese with uim, try to edit environment variable as follows:

export QT_IM_MODULE='xim'

uim-toolbar-gtk-systray: トレイアイコンがクラッシュする

uim-toolbar-gtk-systray isn't compliant with freedesktop.org system tray specs so some icons are shown in one icon space by default. Choose just one of them to solve it. The steps to display only 'Input mode' icon for example as follows:

  1. Run テンプレート:Codeline.
  2. Click 'Toolbar' on 'Group' list.
  3. Take the all checkmarks off.
  4. Click 'Anthy', 'Anthy (UTF-8)' or 'Mozc' which you are using on 'Group' list.
  5. Click Edit button in 'Toolbar' box -> 'Enable toolbar buttons' line.
  6. Enable only 'Input mode' and click 'Close' button.
  7. Click 'OK' button to close uim-pref-gtk.

The tray icon will be displayed "あ" (Hiragana mode) or "ー" (Direct mode).

暗いテーマを使用しているので uim モードのアイコンが見えません

Modify icons in accordance with your theme (e.g. invert the colors). The icons which should be modified will be as follows:

There is a sample PKGBUILD to apply it. See above.

関連文献

uim
uim official document
uim on wikibooks
Fonts
Japanese fonts showcase
modified Japanese fonts