Setting Up Fcitx for Chinese and Japanese Language Input on Ubuntu Xenial 16.04

I recently decided it was time to upgrade to the latest Ubuntu LTS (Long Term Support) release. The transition was straightforward, but setting up Fcitx, my preferred input method for Chinese and Japanese, wasn't quite as simple as I had hoped. Here's what I had to do to get it to work.px.gif

  1. Install the following packages via the Ubuntu Software Centre or apt-get: fcitx fcitx-sunpinyin fcitx-mozc
  2. Head over to System Settings –> Language Support and select “fcitx” from the drop-down menu at the bottom of the window.
  3. After logging out and logging back in (or better yet, giving your machine a quick reboot), you should spot a little Fcitx icon in your system tray. Click it and choose “Configure Fcitx”. Now, click the “+” sign in the lower left corner to open up a dialogue for adding new input methods. Uncheck the box that says “Only Show Current Language”, then add the input methods you need. Personally, I go with “Mozc” for Japanese and “Sunpinyin” for Chinese. Make sure to put your preferred default at the top of the list.

Advanced configuration for Unity and LXDE users

If this is all you need, you're good to go! But if you're like me and prefer locking input methods to their native keyboard layouts, things are a tad more intricate.

If you're on Unity, you'll need to instruct Gnome not to block external applications from switching keyboard layouts (Ubuntu 16.04 is mostly based on Gnome 3.18, but also uses components from 3.14 and 3.20). Open a terminal and run this: gsettings set org.gnome.settings-daemon.plugins.keyboard active false
Then, head back to the Fcitx configuration window from step 3 above. Select each input method one by one, click the “Settings” button (the one with the gear icon), and choose the keyboard layout you want to associate with that input method.

If you're on LXDE (Lubuntu), the Fcitx configuration window will look slightly different, and you won't find a settings button for assigning keyboard layout overrides. You can achieve the same result by manually editing this Fcitx config file, however: ~/.config/fcitx/data/layout_override
The file should include the name of the input method, followed by a comma and the language tag for the keyboard layout. Here's what mine looks like:

sunpinyin,cn
mozc,jp

Making Fcitx play nice with Firefox and AppArmor

Lastly, if you're planning on using Fcitx in Firefox with AppArmor running in enforce mode, you'll need to tweak the Firefox AppArmor profile that comes with Ubuntu. Add these lines (the first is for Fcitx, the second is for mozc) just before the closing bracket at the end of the file:

#include <abstractions/fcitx>
#include <abstractions/mozc_server>