japanese-input-method-on-linux.mdx
1 --- 2 title: Setting up Japanese input method on Linux 3 date: 2020-06-05 4 description: Installing fcitx and mozc for Japanese input method so you can type 日本語 on Linux 5 tags: 6 - linux 7 - japanese 8 --- 9 10 import Update from "~/components/Update.astro"; 11 12 # Introduction 13 14 So I've been learning Japanese lately then I came across this question, "How do I input a japanese character on my laptop?" I use a 12-keys layout to insert japanese characters on my phone. It takes time to adapt but eventually I got comfortable enough with it. 15 16 At first, I tried to change the keyboard layout but it doesn't work. I then came across this combination, **Fcitx** and **Mozc**. It's been a great experience using them, it's also very easy to set up and use. 17 18 # Fcitx 19 20 ## What Is Fcitx? 21 22 According to [Wikipedia](https://en.wikipedia.org/wiki/Fcitx), **Fcitx** is an input method framework with extension support for the X Window System that supports multiple input method engines. 23 24 It supports multiple input engines like `fcitx-hangul` for Korean, `fcitx-mozc` for Japanese, `fcitx-googlepinyin` for Chinese, and more. 25 26 It also has a lot of addons that you can use like `clipboard` for clipboard management, `spell` for spellchecking, and many more. 27 28 ## Installation 29 30 Installing Fcitx is pretty simple. It's available on most Linux distro official repository. I use Archlinux so mine will looks like this, you might use another distro but it's basically the same. 31 32 ```bash 33 # Arch 34 $ sudo pacman -S fcitx5 fcitx5-gtk fcitx5-qt fcitx5-configtool 35 36 # Fedora 37 $ sudo dnf install fcitx5 fcitx5-gtk fcitx5-qt fcitx5-configtool 38 ``` 39 40 > We're using Fcitx5 since it's the newer version of fcitx 41 42 After installing it, we need to set some variables for it to work. 43 44 ## Configuration 45 46 To set our input method to `fcitx`, we need to change our environment variable. 47 I set it on `~/.profile`, but you can set it on `~/.xprofile`, `~/.pam_environment`, `~/.xinitrc` or anything that gets sourced on login. You ned to set these variables 48 49 - `~/.pam_environment` 50 51 ```bash 52 GTK_IM_MODULE DEFAULT=fcitx 53 QT_IM_MODULE DEFAULT=fcitx 54 XMODIFIERS DEFAULT=\@im=fcitx 55 SDL_IM_MODULE DEFAULT=fcitx 56 IBUS_USE_PORTAL=1 57 ``` 58 59 - `~/.profile` or anything that uses shell syntax 60 ```bash 61 export GLFW_IM_MODULE="ibus" 62 export GTK_IM_MODULE="fcitx" 63 export QT_IM_MODULE="fcitx" 64 export XMODIFIERS="@im=fcitx" 65 export SDL_IM_MODULE="fcitx" 66 export IBUS_USE_PORTAL=1 67 ``` 68 69 # Mozc 70 71 ## What Is Mozc? 72 73 According to the project [home page](https://github.com/google/mozc) itself, Mozc is a Japanese input method editor (IME) designed for multi-platform such as Android OS, Apple OS X, Chromium OS, GNU/Linux and Microsoft Windows. This OpenSource project originates from [Google Japanese Input](http://www.google.com/intl/ja/ime/). 74 75 We need this for `fcitx` that we've installed previously to be able to input Japanese characters. 76 77 ## Installation 78 79 We are using Fcitx as our input method framework so what we need to install is `fcitx5-mozc`. It's also available on most Linux distro official repository. 80 81 ```bash 82 # Archlinux 83 $ sudo pacman -S fcitx5-mozc 84 85 # Fedora 86 $ sudo dnf install fcitx5-mozc 87 ``` 88 89 After installing it, it will be available to Fcitx as an input method. 90 91 ## Configuration 92 93 Now what we need to do is set Mozc as Fcitx input method. To do that, open up the `fcitx5-configtool`. It will roughly look like this, it may look different because of your theme. 94 95  96 97 Make sure the checkbox for `Only Show Current Language` is unchecked, otherwise you won't find mozc. 98 99  100 101 Find mozc, click it, then press the top button. Not sure why the icon is missing, probably some weird QT and GTK compatibility issue. 102 103 After clicking apply, execute `fcitx5` on startup depending on your DE/WM. I put it in `~/.xinitrc` like so. 104 105 ```bash 106 fcitx5 --replace -d & 107 ``` 108 109 If you put it on `~/.xinitrc`, it will get executed when you log in into xorg. 110 111 Fcitx is toggleable using a keybind that you can change from the `fcitx5-confgitool` which looks like this. 112 113  114 115 You can change the `Trigger Input Method` to whatever key you like. I personally use `alt+space`. 116 117 ## Usage 118 119 If you've done configuring it, try to activate it by pressing the keybind that you've defined before then try to type on something. It will look like this. 120 121  122 123 It looks like an autocomplete from a text editor. The way it works is if you write `romaji`, it auto converts it to `hiragana` which you can then press `TAB` to scroll the options. 124 125 For example, if you write `watashi` then it will show `わたし` and if you continue pressing `TAB` it will be the kanji form of it which is `私`. This also applies to `katakana`. 126 127 # Closing Note 128 129 All in all, I'm pretty satisfied with this setup. I don't have to learn a new keyboard layout to insert Japanese characters. I can just write romaji and it will turn into hiragana, katakana, or kanji. 130 131 Anyway, thanks for reading this post. I hope you find this post useful and have a good day!