Set up Fcitx for Chinese and Japanese language input on Ubuntu Xenial 16.04
It was time to update to the latest Ubuntu LTS (Long Term Support) release again recently, and it turned out that setting up Fcitx wasn’t quite as simple this time around. Here is what I had to do to get it to work.
- Install the following packages via the Ubuntu Software centre or apt-get:
fcitx fcitx-sunpinyin fcitx-mozc
- Go to System Settings –> Language Support and select “fcitx” from the drop-down box at the bottom of the window.
- After logging out and logging back in again (or better yet, rebooting), you will find an Fcitx icon in your system’s tray. Click the icon and choose “Configure Fcitx”. Now click the “+” sign in the lower left corner of the window to open a small dialogue to add new input methods. Uncheck the box saying “Only Show Current Language” and add the input methods you need. I typically choose “Mozc” for Japanese and “Sunpinyin” for Chinese. Leave whatever you want to be the default in first place.
All is well if this is everything you need. Personally, I also like to lock input methods to their language’s native keyboard layout. This is where things got a little more complicated this time.
If you are using Unity, you will first have to tell Gnome not to block external applications from changing keyboard layouts (Ubuntu 16.04 uses mostly Gnome 3.18, but also has components from 3.14 and 3.20). Run this in a terminal:
gsettings set org.gnome.settings-daemon.plugins.keyboard active false
Then, in the same window as for step 3 above, select each input method in turn and click the “Settings” button at the bottom of the window (the gear symbol in Ubuntu’s default icon set). Select the keyboard layout you want to be associated with that input method in the dialogue box that comes up.
If you are using LXDE (Lubuntu), the Fcitx configuration window will look slightly different and there will be no settings button to assign keyboard layout overrides. You can achieve the same by manually editing this Fcitx config file, however:
The file needs to contain the name of the input method, followed by a comma and the language tag for the keyboard layout. In my case:
Finally, if you plan on using Fcitx in Firefox with AppArmor enabled in enforce mode, you will have to modify the Firefox AppArmor profile that ships with Ubuntu by adding the following line(s) (the first line is for Fcitx, the second line is necessary if you plan on using mozc) before the closing bracket at the end of the file:
<a href="https://stefan.angrick.me/tag:include" class="hashtag"><span>#</span><span class="p-category">include</span></a> <abstractions/fcitx> <a href="https://stefan.angrick.me/tag:include" class="hashtag"><span>#</span><span class="p-category">include</span></a> <abstractions/mozc_server>