Atom and Emacs, how to support Chinese

I decided to write a Chinese article in my previous post. However, I had a hard time viewing and typing chinese. In Atom, all the Chinese characters are rendered as blocks. Whereas in Emacs, I can view Chinese without problem but I cannot type in anything in Chinese. After spending sometime on the internet, I finally figured out how to enable Chinese support for both of them.

  • Atom

In the Chinese Atom community, several people claimed that Chinese stopped working after an update. I started using Atom pretty late so I didn’t experience the transition. Here are some steps to enable Chinese:

  1. Add 文泉驿正黑 font to your system, in ubuntu
1
sudo apt-get install ttf-wqy-zenhei
  1. In atom, go to preference -> Settings, change Font Family to
1
DejaVu Sans Mono,文泉驿正黑
  1. Now you should be able to view and edit Chinese in text editor, however there is still problem with plugins, such as markdown-preview. We need final touch to enable Chinese for all. To do this we need to change the styles.less. To do this hit Ctrl + Shift + p and type in “Open your stylesheet”. Past the following code into the text editor:
1
2
3
4
5
6
7
8
9
/*
替换 sans-serif
*/

@font-face {
font-family: sans-serif;
src: local("文泉驿正黑");
/*no unicode-range; default to all characters */
}

If you have any open markdown-preview window, you should see the change immediately!
你好世界!

  • Emacs

    1. First need to install language pack:
1
2
cd /usr/share/locales
sudo ./install-language-pack zh_CN
  1. Run emacs with the following command LC_CTYPE='zh_CN.UTF-8' emacs. You may want to create an alias for this command in your .bashrc.