Converting a Website to Traditional Chinese

Recently, I took on a project from Hong Kong that required the entire website to be in Traditional Chinese. After analyzing the source code and project requirements in detail, I found that I only needed to convert the simplified Chinese text on pages and handle Traditional Chinese conversion for user search queries. Two challenges — not too difficult, but with a few pitfalls to note here.

Source File Conversion to Traditional Chinese

This was relatively simple — just write a script for batch processing, and it should be fine. There ought to be ready-made wheels for this by now. Sure enough, I found a great conversion tool: ConvertZ.

The software not only supports batch conversion but is also blazing fast — processing hundreds of files in just seconds. Even better, it supports multiple encoding formats. Unfortunately, I was using UTF-8 exclusively, so I didn’t encounter any issues (except for one iconfont glyph that got garbled… just one).

Some pages required database data. No choice there — I exported the SQL file and used the software to convert it, which was quite convenient since the data volume wasn’t large.

Search Conversion

The pages were converted to Traditional Chinese, but user input was in Traditional while the corresponding resources were in Simplified…

The resources couldn’t be changed, so I had to convert user input to Simplified Chinese.

I found a wheel: opencc, along with its PHP extension opencc4php (both available on GitHub).

The installation instructions are clearly written in the project README, so I won’t repeat them here. Just a few pitfalls to note:

  1. Before installing, read every line of the installation documentation carefully. It seems to be a personal project, so the README is quite concise. If you compile and install directly according to the instructions, you may encounter some dependency issues. Choose flexibly based on your system — below are the Ubuntu and CentOS (both 64-bit) systems I used.

  2. Installing the doxygen dependency — compiling and installing this also has many issues. If you don’t want the hassle, for CentOS, go directly to findrpm to get the RPM package; for Ubuntu, simply use apt-get. This will save you a lot of trouble.

  3. If opencc --version throws an error after installation:

libopencc.so.2: cannot open shared object file: No such file or directory

Solution:

Terminal window
# Find libopencc.so.2
$ sudo find / -name libopencc.so.2
/usr/lib/libopencc.so.2
...
# Create a symlink for libopencc.so.2 in /usr/lib64/
$ sudo ln -s /usr/lib/libopencc.so.2 /usr/lib64/libopencc.so.2

Finally, use the functions as documented where needed!