On Bilingual Weblog II, how to set up a bilingual blog

Ok, in this part, we will starting the actual work of setting up an English and Chinese weblog use WordPress 2.1.3, just like this weblog you are reading right now. This article here provides my own experience with some graphical demonstration, and I also provided my gettexted theme of TypoXP-Reloaded ( with Google Adsense optimized :) ). And I am pretty sure that the methods used in this article will also apply to set up other bilingual blog in general.

But first, I want to give special thanks to the author of the Language Switcher plugin, Jennifer Hodgdon , for her patient answering my e-mails and the improvements she made into this great plugin. Actually, this article is based on the original article published on the poplarware.com, Creating a Multilingual Blog with WordPress

Ok, let’s begin with:

How Language Switcher works and A Brief Guide line
I think I may first introduce the way the Language Switcher works. Basically, besides let your interface shown in the language you selected by make use of the WordPress built in multi-language localization support through the language files, it also provide a set of “language tags” to let you use within your content, so you can easily add many language version of your content. Language Switcher handles all other works of getting the right language content shown on the page, set the default language of your blog and so on. You’ll need find out the the ISO code of the languages you want to use(just do a Google search if you don’t know), for example, the ISO code of English language is “en”(without quotes); and the Chinese language is “zh”(without quotes). The language tags will make use of the ISO code to determine which language is in using for the content, for example: <lang_en>internet is so great</lang_en><lang_zh>互联网是如此的美妙</lang_zh>,will indicate that in English, it is “internet is so great”; in Chinese, it is “互联网是如此的伟大”, and Language Switcher will apply the language filter on the fly according which language is currently selected on the the blog.

Summary of the process to set everything up:
I will assume you already have a WordPress 2.1.3 installed on your hosting server and on your local development machine, because you really better have a local version of your weblog installed as a test base for your website. Here is the steps we need go through:

  1. Make change to your database on the categories title field.
  2. Download the modified WordPress core files on poplarware.and extract them to override the existing files.
  3. “gettext” your theme.
  4. Get your language files and use poedit tool to modify the language files and translate your theme as you need.
  5. Download and install the Language Switcher plugin.
  6. Testing.
  7. Upload necessary files to you hosting server.
  8. Post, and start building your bilingual blog!

Make changes to your database.
The reason to make this change to your database is obvious. When you add more than one language version of your categories title, plus the language tag, such as <lang_en>–YOUR TITLE–</lang_en><lang_zh>–你的标题–</lang_zh>, the length of the title must be get very long, and the default value of the length of the cat_name field in the wp_categoires table will not be suitable anymore, especially consider when the “–YOUR TITLE–” value not short. To change your database, I recommend use phpmyadmin (a great MySQL Database Administration Tool). First, fire up your phpmyadmin use your browser, and navigate to the database your blog is using, click the wp_categories (mostly your table prefix should be “wp_”, if yours is not or you changed it to a different prefix when you install your WordPress, just replace yours with the “wp_” here, you should have no difficulty to find the categories table) table, then at this screen, as the picture shows, choose the “change”caction to the cat_name field.

change cat_name field

then, you enter the value in the length/value text box, recommend 200, on the next screen. Next, click “save”, and you are done.

set the value

Download the modified WordPress core files
At least right now, this step is necessary, unless you have a great amount knowledge on PHP programming, because in order to let the Language Switcher plugin works properly and get every thing appear in the correct language, many WordPress core files need be modified. As on the poplarware says:

When I originally got my bilingual blog working, I had to do quite a bit of PHP programming and sleuthing to get everything to appear in the right language. With Version 2.1 of WordPress, things are not quite so bad, but there are still a few modifications to core WordPress files that you will want, if you want everything in your blog to be multi-lingual (posts, categories, links, link categories, RSS feeds, etc.), and if you want the WordPress admin pages to display correctly. When WordPress 2.2 comes out (April 2007), these changes are scheduled to be integrated into the core WordPress files, but until then, if you want your multi-lingual blog to work correctly, you’ll need to download and install the modifications.

After download the zip file, just extract all the files within to your WordPress installation root directory. In case you have difficulty access the poplarware website, I have also uploaded the file here (but you should always try to download there first, I make no guarantee this file will always update with those files at the original location) .

Other plugins, theme, and Gettexted
Although this article assume that you are adding additional language option to your already existing blog, you can, at anytime, download and install other plugins you need. There are just so many plugins out there on WordPress Plugin List and other places. But you need make sure you theme support the plugin you will use, sometimes it requires modify your theme as well. Of coures, there are no reason to prevent you downloading other themes and active the one you like most. For those interested in the theme used on this weblog, I have uploaded my “gettexted” theme, TypoXP Reloaded here(special thanks go to the theme’s original author and Connected Internet ). You may want to use this theme because it is Google Adsense Optimized :) .

To ensure that your account is credited for any clicks you must put your publisher id between the quotes in the following line google_ad_client = ; in each of the files: adsensensecontent.php, adsensemiddle.php, adsenseskyscraper.php, adsensetop.php, adsenseupdates.php, and linkad.php. And I also add my Google Analytics code in the footer.php file, if you don’t have Google Analytics account, please remove it there.

Gettexted theme
So, what in the world is “gettexted”? Gettext means GNU gettext localiztion framework. According to the Translating WordPress:

gettext is a mature, widely used framework for modular translation of software, and is the de facto standard for localization in the open source/free software realm.

For more about gettext, please visit Translating WordPress and GNU gettext.

The actual work you do is to enclose all text printed on the screen by your themes and plugins in one of the two WordPress “gettext” functions: “_e” and “__” (two underscores). The “_e” function used for those text directly printed onto the screen, that is to say, they are not in a PHP expression (thing about those static html documents in your head right now :) ), for example, in your archive.php file, you may see:

<h2 class="pagetitle">Blog Archives</h2>

and you need change it to this:

<h2 class="pagetitle"><?php _e("Blog Archives"); ?></h2>

Please note you need escape into PHP, that is use <?php and ?> each time you use “_e” function, and don’t forget the semicolon at the end of every PHP statement!
The “__” (double underscores) function is used when the text printed on the screen is got return from another PHP function. For example, you may see the following code in your archive.php file:

<?php the_excerpt('Read the rest of this entry »'); ?>

and you need change it to:

<?php the_excerpt(__('Read the rest of this entry »')); ?>

So, actually, you will need find all the text in single or double quotes that will eventually be printed on the screen, and which is inside PHP functions, and then put “__(” and “)” aroung the text; and you will also need find all the text that is directly put onto the screen, and escape into PHP first then add “_e” function around them.

Things you need to watch out:

  1. Please pay attention to the use of single quotes and double quotes used in your theme files; sometimes you may need to break the original text apart use the “.” in order to use the “__” function.
  2. Remember that the PHP “echo” is also a function.
  3. Mostly, you will only need modify your theme files. Because most installed plugins will require modification to you theme files in order to invoke the functions or hooks added by the plugins, and do not do change the look and feel kind thing by themselves. However, there are maybe some plugins will define how they output text on the screen in their own plugins file.
  4. Remeber use <?php and ?> when you use “_e” function, also don’t forget the final “;”.
  5. You better keep a copy of the original files.

Language files and poEdit tool
The next step is to get the Chinese language file for WordPress and use poEdit to add new translated terms into the language file. As we have discussed in previous article, it is the good idea to get the language file other people have already translated other than you reinvent the wheel. There are more than one version of Chinese language file available on the WordPress in Your Language page, I recommend the one on WordPress-Simplified Chinese Localization because this is what this blog based on and I found it have little places need to be adjusted. The language file or files, usually include one or two files. It at least includes one file callled MO file; this is the final file you want to use. And also, it should includes a file called PO file, this file is used for poEdit tool. Think about PO file is the source code file for your language, and MO file is the complied version of you language file which can be used for the WordPress software. Normally, if you just need localize you original WordPress, just download the MO file and put under wp-includes/languages directory in your WordPress root, and change the define ('WPLANG', '');in your wp-config.php file. But in this case using Language Switcher to set up your bilingual blog, you should download both two files put them in wp-includes/languages and don’t need change wp-config.php file.

Use the poEdit
Please download poEdit at poedit.net or the famous sourceforge.net. If you are on windows, just install this software after downloaded the setup.exe file. Fire up the poEdit, you will see following screen:

poEdit startup

Then, go to File->Open (or hit the “Open catalog” button) , navigate to your WordPress root directory, then wp-includes/languages/, open the PO file, in this case, it is the zh_CN.po file. Now, here is the two important things for those of you who first use the poEdit tool: 1. Go to File->Preference, then go to Editor tab, make sure the option “Automatically compile .mo file on save” is checked.

poEdit Preferences

2. Go to Catalog->Settings, then under Paths tab, make sure the paths value is point to your WordPress root directory in your hard drive; for examle, I am using the XAMPP default root directory setting, so my WordPress root is “C:Program Filesxampphtdocswordpress”.

poEdit Catalog Settings

After done these two things, you are ready to add new translated terms and do some modification to the original language file.

The new added terms are just the text that you have added “_e” and “__” function around them in the previous step. So, go to Catalog->Update from source, poEdit will scan all the new text that need be translated in your WordPress php file. The actual translate process I think is very simple, just click the text need be translated, the original string box will change the string to those currently selected, and you just need translate the string in the translated text box.

poEdit Main Window

The translated result will show immediately to the right of the original string.——Well, it is basically how it goes, but sometimes, you will need be familiar with some PHP functions, such as “sprintf”. After you are happy or the translation, click File->Save, this will automatically save your translation and generate the new updated MO file. One more thing need to point out here, in some language, the PO file and the MO file may have other codes in the file name, not just the language ISO code. For example, in Chinese, the Chinese file name will be zh_CN.po or zh_CN.mo indicate that the file is for simplified Chinese, not traditional Chinese. But whatever you use, you should just leave the ISO code in your MO file, that is, you should rename the MO file to zh.mo. Don’t forget this if you want all of your WordPress text shows in correct language!

Please remember, every time you changed some thing in your theme or plugin file, you will need use poEdit re-update from source and add the new transaltion, then re-generate a new MO file. Don’t forget to change the MO file’s name!

Download and install the wonderful Language Switcher plugin
Ok, we are approaching the end of setting up your bilingual WordPress. What you need to do now is go to poplarware to download the Language Switcher plugin. For those of you have difficulty to access the website, I have uploaded my version here (but please acknowledged that this file may not has the latest update). After you download the zip file, extract the files to your wp-content/plugins/, and activate this plugin in your Admin just as you do for the other plugins you have installed.

Before we finally upload our works to our live webserver, we need do some testing and, maybe, trouble shooting. First, we need set the language up in the WordPress Admin, go to Admin->Options->Language Switcher, type the two-letter ISO code for your default language, and enter the language flag file name, the Text Missing Message, the Time Format etc. Then, we need add the Language Option link to the side bar of the blog use the function langswitch_list_langs, and also add the language selection link for each entry or post on our blog which has two language version use the function langswitch_post_other_langs. For more detail information, please reference Language Switcher Home page on Installation and Setup section.

After the Language Switcher was set up, we can begin to add some multi-language content. The “content” which can be not just including the post entry, but also including entry titles, blog name, category title, blog roll links or anything you believe will be finally output as text into the screen; then click the language selection link in the side bar, confirm everything change to the right language; click the language switch link for a multi-language post, to confirm that the post changed into other language; confirm that if a post don’t have the language version, the Text Missing Message set in the Admin shown up on screen; after click the language selection link switched to another language, click another normal link navigate to another page to confirm that the language sticks; check to see if the RSS feed is in the right language. Repeat these tests for a category archive page, a date archive page, a search results page, and a single article page. If you find anything don’t work properly, basically there are two thing you can check: check to see if all the text strings which are printed to screen by your theme and plugins are “gettexted”; check if the content is entered correctly, that is if they are enclosed in the right language tags, i.e. in the <lang_en>, </lang_en> and <lang_zh></lang_zh> tags (please note, you will need go to the Code view of your WordPress text editor when you use these tags; if you in the Visual view, you can use the “[” and “]” replace the “<” and “>”).

Upgrade your live blog to bilingual
Finally, we get the point to upload our changes onto our webserver. If you are setting up your blog from scratch, then you can upload everything onto your hosting server, including your database. The details of how to deploy your local ready to publish weblog to your hosting sever is not in the scope of this article I think. But you can search the Web to get many information on this topic. If you are upgrading your blog to a bilingual, you will need upload following files onto your hosting server:

  1. All the new plugin files, of course including the Language Switcher plugin files
  2. All the theme files which you have “gettexted”
  3. The language MO file
  4. The modified WordPress core files

And also, you will need do the first step of Change your database on your server. Then, set up the settings in the Admin->Option->Languages Switcher.

Starting convert the content into bilingual, and stat to post your bilingual weblog!

Some suggestions while using Language Switcher
The language Switcher is almost perfect. Actually, I want to set up a bilingual website for a long time, but after tried many CMS system, especially on the Drupal’s i8n module, I seem can’t find the right thing for me; until I found the Language Switcher on WordPress. Here is some suggestions from my own experience:

  1. Language Switcher is for manually provide bilingual content. Trying to post every entry in the default langauge first, then provide anther langauge, otherwise, your use first come to you blog will see many of “Sorry the content is not available in English” or something you enter in Text Missing Message.
  2. If you are using the special WordPress <!–more–> tag to tell WordPress to put excerpts on blog pages, you will need to make sure to put text for all of your languages above that tag, because the extraction of the excerpt happens before WordPress sends your post through the Language Switcher filter to choose which language to display.
  3. Due to the internal code logical of the WordPress, at least for now, Language Switcher can’t handle the entry text which is not in the default language with the WordPress special tag, <!–nextpage–> been used. So, please not use the <!–nextpage–>tag in yur article.
  4. Don’t encourage your visitors use language tag when leave comment. It is because the comment content will not be shown if is not in the language is currently selected on the blog, but the information about the comment was left was there.
  5. You need manually specify the Post Slug and Page Slug when you posting or write a new static page. Because, WordPress default behavior is to generate the url links to posts or pages use the Title information. Since the Title include “<lang_en>…” or something like this, the url links will not be nice!

That’s all. I am look forward to see more improvements or enhancements will be added to this really nice plugin. Enjoy your bilingual blog!

9 Comments - Leave a comment
  1. Yangtx says:


  2. David Adam says:

    Hi, 对于最新版的wordpress, 工具和方法差不多,但是,wordpress的数据库结构比以前版本有很大变化。最好参考 http://poplarware.com/languageplugin.html 上面的步骤。 不过,现在,它上面有一点好像说锝不对,就是,我们应该把wp-config.php里的
    define(‘DB_CHARSET’, ‘utf8’);
    define(‘DB_COLLATE’, ”);
    设置成数据库里实际用的值。我的分别是 utf8 和 utf8_unicode_ci.


  3. hello says:

    i can only see the first page of each article. 2, 3 4 do not work. After clicking it, no update. anything wrong?

  4. David Adam says:

    Hi, I am sorry. It seems the tag has some problem with the latest version of wordpress and the language switch plugin. I have remove the multi-page.

  5. li says:

    为何我的poedit中Catalog->Update from source 不可用?

  6. David Adam says:

    检查一下你的settings下的keywords里有没有对应的php函数名: _e 和 __。


  7. li says:

    Update from source解决了,下来又有个问题。
    目前正在实施WP与online store的改造,很大可能用到多语言版本,完成发布后与博主分享。

  8. HYaN says:


  9. quoted on WP升级到2.3 « 云居 says:

    […] 留言本已经清理完毕,以前的页面评论就不改了,不过旧文的Tag还是补上的好,要是还有时间倒想试试阅读网络那样的双语版…… […]

Leave a Reply

Your email address will not be published. Required fields are marked *