Ubuntu – How to switch input modes in mozc without going to the IBus menu

ibusmozc

I have installed mozc on Ubuntu 14.10. It is working fine – I am able to write in Japanese by going to the icon in the upper-right-hand corner of my screen (what do you call this?) and selecting Hiragana or Katakana from the "Input mode" menu, as in the picture below (ignore the low opacity; I can't figure out how to make PrtSc not close the menu):

mozc Input Mode menu

However, this is a very slow process. I imagine there has to be a faster way to switch input modes – a keyboard shortcut or something (like on Windows with Google Japanese Input [to which mozc is related], Alt+` switches between Hiragana and Direct Input). What shortcuts are there for switching input modes, and can they be configured?

Best Answer

TLDR

Abstract

Steps to create the Japanese Mozc key bindings, to switch the input modes:

  1. Open a text editor (e.g. Gedit).
  2. Click on Gnome Status menu (Gnome's top-left bar) > IBus menu (i.e. keyboard/input language selector) > Select Japanese Mozc input method.
  3. Again, click on Gnome Status Menu > IBuz > tools > Properties > Mozc Settings window.
  4. From Keymap style section > click on customize button (first one).
  5. Create new entries with your personal shortcuts to duplicate the japanese keys binding: hankaku/zenhankaku, muhenkan, eisu.
  6. If messed things up, click on reset to defaults button from Mozc Settings window.

That's all!

Graphical abstract

Steps to create the key bindings to toggle Japanese syllabaries input mode.

Graphical Abstract to set up MOZC keys

Introduction:

The problem: how to type Japanese using a non-Japanese keyboard?

In Japanese (日本語, nihongo), you need to write using a lot of different symbols-sets. A informal categorization of these sets can be like:

  • all alphabets syllabaries (ひらがな hiragana, かたかな katakana, 漢字 kanji, ローマ字 romaji),
  • (han)dakuten, contractions, combinations and variants (e.g. ゜maru, ゛tenten, uppercase, lowercase, full-width, half-width etc),
  • symbols in Japanese style (e.g. Japanese period。, 「Japanese quote」, Japaneseーhiphen etc).

So, dedicated keys exists on Japanese keyboards to toggle between them. An analogy with occidental keyboard are the Capslock key to upper/lower-case or, Shift key to insert symbols. But the occidental keyboard hasn't these Japanese keys. So how to type in Japanese using a non-Japanese keyboard?

Solutions

Basically, two solutions can be listed:

  1. install a Japanese keyboard or,
  2. binding Japanese keys, by software level, in your non-Japanese keyboard.

Solution 1: Install a Japanese keyboard

Easiest solution so far. Acquire one Japanese keyboard, install and configure on your Operation System. But you need access to one, maybe buying one (with international credit card, taxes, waiting for shipping and so on).

Solution 2: Binding Japanese keys in your non-Japanese keyboard.

It is a cheap solution and you can use it in any keyboard you have. But you need to install software, configure, and memorize MANY key combinations. It is basically "a sea of shortcuts" to emulate the Japanese keyboard. Linux have some software to simulate a Japanese keyboard for using a non-Japanese keyboard.

Let's implement the solution 2.

Theoretical background

Linux input software layers

Our computer can receive inputs from many talked/typed languages and hardware (i.e. different keyboards and layouts). So it needs to organize the configurations and permit to the user choice between different languages. For example, a user can type one document in Italian AND English languages, at alternating times. So the software needs to show the user a way to change the language to be inputted.

The Linux user have 2 layers of software to configure the input method by keyboard:

  • Input Method Framework (IMF): a class of software that organize the inputs (from keyboard, mouse etc), send to the correct destination (software, systems etc), and configure them.
  • Input Method Editor/Engine (IME): a class of software that receives the inputted characters (from a keyboard), translate them to the desired input (i.e. idiom, language) and, send them to the Input Method Framework (IMF) to handle them. Basically, we have: from keyboard > (typed/inputted keys) > IME (receives and translate them) > (translated inputted keys) > IMF (handle translated inputted keys to destinations).

For the Linux user, an example o IMF is IBus; an a example of IME is MOZC. The first one will switch between all installed IMEs and switch between all idioms/languages installed too. The second one, if selected, will send to the IMF only Japanese keys, even if you typed in a non-Japanese keyboard. About Japanese IMEs, you can read more about here, and visualize the states/events in these diagrams:

Diagram 1: IME states 1

Diagram 2: IME States 2

Japanese keyboard

Layout

The Japanese keyboard layout (キーボード) is established by Japanese International Standard (JIS). First of all, let's contemplate the Japanese keyboard! Watch an open box video. You can see the vector draw bellow, showing clearly the Japanese keys:

Japanese keyboard layout

Finally, some real pictures bellow:

Japanese keyboard layout 1 Japanese keyboard layout 2

Try to identify each key, slowly.

We have:

  • Roman letter (QWERTY).
  • Hiragana symbols.
  • Small hiragana symbols.
  • Han-dakuten symbols (maru, tenten).
  • Arithmetic symbols.
  • Capslock, shift, super, alt, tab, Ctrl, Enter, Backspace.
  • Punctuation with Japanese style (period, quotes etc).
  • and some special keys with Japanese words:
    • muhenkan 無変換: don't convert kana to kanji.
    • henkan 変換: convert kana to kanji.
    • hiragana/Katakana/romaji カタカナ / ひらがな / ローマ字:
    • hankaku/zenkaku 半角 / 全角: switch between half-width or full-width
    • kanji 半角 / 全角 / 漢字: switch between kanji or English characters.
    • eisū 英数: switch to alphanumeric characters.

You can have more description of these specific keys here. And read about the text frequency of hiragana, katakana e kanji and here.

Typing

How a Japanese user type on this keyboard?

  • Answer 1: type phonetically, using romaji mode. Yes, they use romaji!
  • Answer 2: it can type in kana mode, too, using hiragana keys.

For example, lets type "kakikukeko" in romaji mode:

  1. First, select romaji mode.
  2. Typing, in a QWERTY keyboard:
    1. type k, outputs: .
    2. type a, outputs: (ka).
    3. type k, outputs: かk.
    4. type i, outputs: かき (kaki).
    5. type k, outputs: かきk.
    6. type u, outputs: かきく (kakiku).
    7. type k, outputs: かきくk.
    8. type e, outputs: かきくけ (kakikuke).
    9. type k, outputs: かきくけk.
    10. type o, outputs: かきくけこ (kakikukeko).
    11. type ENTER, outputs: かきくけこ (kakikukeko ).

Another example, type "kakikukeko" in hiragana mode.

  1. First, select kana mode.
  2. Typing, in a QWERTY keyboard:
    1. type t, outputs: (ka).
    2. type g, outputs: かき (kaki).
    3. type k, outputs: かきく (kakiku).
    4. type :, outputs: かきくけ (kakikuke).
    5. type b, outputs: かきくけこ (kakikukeko).
    6. type ENTER, outputs: かきくけこ (kakikukeko ).

And to convert to katakana or kanji is the same thing. You can toggle to katakana mode or kanji mode and type on romaji or hiragana. And the computer will pop up an autocomplete window to you select your desired word.

Method

Now, we will use software to type Japanese in a non-Japanese keyboard. My system when I create this text was:

  • My OS: Ubuntu 18.04.4 LTS
  • My Japanese IME: Mozc 2.20.2673.102
  • My IMF: Ibus 1.5.17
  • My keyboard: Latin keyboard (with ç, ~, ^ and so on).

Install

Ubuntu came with the IMF IBus (like a built in). But if you need to install IBus:

sudo apt install ibus

Next, let's install our Japanese IME MOZC:

sudo apt install ibus-mozc

Observation: look at the name of the package ibus-mozc. Its our IMF + IME names. So, in future we can search on APT repositories for IMF and Japanese IME alternatives, like ibus-*, or *-mozc.

Installations completed!

Configurations

A Japanese keyboard has many different keys, to switch:

It is necessary to edit and memorize the Japanese input software's (binding) shortcut keys. Hiragana, katakana, kanji, romaji, upper/lower-case, full/half-width, Japanese symbols (period, quote, maru, tenten etc). So, you need to memorize/edit the keys to (des)activate the switches.

See the screenshots from before to get a hint of where the MOZC keymap is. To edit/read these keys on your Mozc:

  1. Open a text editor (e.g. Gedit) and stay with it in foreground.
  2. Select Mozc input mode: Hold Super and press Space as many times as to select Mozc option. Or click on: IBus (at GNOME Status Menu) > Japanese (Mozc).
  3. To read/edit these Japanese key bindings, click on: IBus (at GNOME Status Menu) > Tools > Properties.
  4. After Mozc Setting window popped up, click on: General tab > Keymap section (at bottom) > Keymap Style customize button (first one).
  5. After Mozc keymap editor window popped up, click on: Scroll up and down to memorize and edit the Japanese keymap (bindings).
  6. Probably, you may will toggle between all Mozc's input modes (hiragana, katakana, romaji etc) if you duplicate and edit these binding keys for your chosen shortcuts. Basically, to switch between syllabaries using MOZC, you need to memorize/edit/press:
  • hankaku/zenhankaku key: to turn IME on/off.
  • muhenkan key: to toggle kana syllabaries.
  • eisu key (or shift+muhenkan keys) to toggle latin input (i.e. romaji).

From MOZC's source-code, see the table with all matches to the Japanese JIS special keys, as bellow:

...
Composition Eisu    ToggleAlphanumericMode
Conversion  Eisu    ToggleAlphanumericMode
DirectInput Eisu    IMEOn
Precomposition  Eisu    ToggleAlphanumericMode
...
Composition Hankaku/Zenkaku IMEOff
Conversion  Hankaku/Zenkaku IMEOff
DirectInput Hankaku/Zenkaku IMEOn
Precomposition  Hankaku/Zenkaku IMEOff
...
Composition Muhenkan    SwitchKanaType
Conversion  Muhenkan    SwitchKanaType
Precomposition  Muhenkan    InputModeSwitchKanaType
...

You can consider to study/test other MOZC keys too, like:

...
DirectInput F13 IMEOn
...
Composition Ctrl i  ConvertToFullKatakana
Conversion  Ctrl i  ConvertToFullKatakana
...
Composition Ctrl o  ConvertToHalfWidth
Conversion  Ctrl o  ConvertToHalfWidth
Composition Ctrl p  ConvertToFullAlphanumeric
Conversion  Ctrl p  ConvertToFullAlphanumeric
...
Composition Ctrl t  ConvertToHalfAlphanumeric
Conversion  Ctrl t  ConvertToHalfAlphanumeric
Composition Ctrl u  ConvertToHiragana
Conversion  Ctrl u  ConvertToHiragana
...
Composition F10 ConvertToHalfAlphanumeric
Conversion  F10 ConvertToHalfAlphanumeric
DirectInput F13 IMEOn
Composition F2  ConvertWithoutHistory
Composition F6  ConvertToHiragana
Conversion  F6  ConvertToHiragana
Composition F7  ConvertToFullKatakana
Conversion  F7  ConvertToFullKatakana
Composition F8  ConvertToHalfWidth
Conversion  F8  ConvertToHalfWidth
Composition F9  ConvertToFullAlphanumeric
Conversion  F9  ConvertToFullAlphanumeric
...
Composition Henkan  Convert
Conversion  Henkan  ConvertNext
DirectInput Henkan  Reconvert
Precomposition  Henkan  Reconvert
...
Composition Hiragana    InputModeHiragana
Conversion  Hiragana    InputModeHiragana
DirectInput Hiragana    IMEOn
Precomposition  Hiragana    InputModeHiragana
...
Composition Katakana    InputModeFullKatakana
Conversion  Katakana    InputModeFullKatakana
DirectInput Katakana    IMEOn
Precomposition  Katakana    InputModeFullKatakana
...
Composition Shift Muhenkan  ConvertToFullAlphanumeric
Conversion  Shift Muhenkan  ConvertToFullAlphanumeric
Precomposition  Shift Muhenkan  ToggleAlphanumericMode
...
Composition Kanji   IMEOff
Composition OFF IMEOff
Composition ON  IMEOn
Conversion  Kanji   IMEOff
Conversion  OFF IMEOff
Conversion  ON  IMEOn
DirectInput Kanji   IMEOn
DirectInput ON  IMEOn
Precomposition  ASCII   InsertCharacter
Precomposition  Kanji   IMEOff
Precomposition  OFF IMEOff
Precomposition  ON  IMEOn
...

So, we need to create new shortcuts similar with these, like bellow (these are my shortcut sugestions):

...
Composition Ctrl j  IMEOff
Conversion  Ctrl j  IMEOff
DirectInput Ctrl j  IMEOn
Precomposition  Ctrl j  IMEOff
Composition Ctrl b  SwitchKanaType
Conversion  Ctrl b  SwitchKanaType
Composition Ctrl y  ToggleAlphanumericMode
Conversion  Ctrl y  ToggleAlphanumericMode
DirectInput Ctrl y  IMEOn
Precomposition  Ctrl y  ToggleAlphanumericMode
...

If you are interested, you can read MOZC's romaji-hiragana conversion table.

  1. If you mess the things, click on reset to defauts button at Mozc setting window (opened in Step 3).

If you edit these shortcuts, please consider conflicts with your existing shortcuts from:

  • Operating system shortcuts (Ubuntu).
  • Graphical shell shortcuts (Gnome, KDE).
  • App shortcuts (firefox, gedit, libreoffice, gimp).
  • Personalized shortcuts (your personal shortcuts).

With these key bindings you can type very well in a non-japanese keyboard. We didn't binding the others japanese keys to let you study the subject.

Alternative solutions

Similar softwares

Im using IBus to be my input method editor (IME). But you can switch to other IMF/IME if you desire. Others IMEs are:

  • Anthy: sudo apt install ibus-anthy.
  • KKC: sudo apt install ibus-kkc.
  • SKK: sudo apt install ibus-skk.

The same as to input method framework (IMF), like:

  • Fcitx: sudo apt install fcitx.
    • and you need to change the IME when installing like:
      • sudo apt install fcitx-mozc.
      • sudo apt install fictx-kkc.
      • sudo apt install fictx-skk.

A list of IMF can be found List of input methods for Unix platforms and Linux input method framework brief summary.

Edit keymap file by a text editor

You can manage the keymap saving, editing, import/export and so on. To do that, read the file at source-code. If you wanna, you can download this file and edit it to be imported into your MOZC software.

So, to import/export the keymap file:

  1. At GNOME Status Menu, select MOZC input method.
  2. Again at GNOME Status Menu, select Tools > Properties.
  3. After Mozc Setting window popped up, click on: General tab > Keymap section (at bottom) > Keymap Style customize button (first one).
  4. And after Mozc keymap editor window popped up, click on: Edit button menu (at bottom) > click import from file... or export from file.... With that you can save (export) your keymap editions. And you can to insert a new keymap edited by importing it.

That's all!

References

You may be interested in read this MOZC issue about how to switch between MOZC j-sylabaries. A good answer about MOZC inputs can be found here. A brief about MOZC input at askubuntu. A lot of questions commented about MOZC and input method. Answers to start MOZC in Hiragana mode.

Related Question