Hello World, the en_US Version

Today I’m starting an English version of my blog, on the purpose of translating some of my discoveries and configuration stanzas into English so more people on the random Internet can find it.

The I18n Problem for WordPress

Although WordPress core has supported native i18n via gettext for a long time, there is still no native way to create a blog of multiple languages. The easy way to blog in multiple languages is just to write all the articles on one WordPress site. This might seem to be feasible for one article or two, but its drawbacks are just too painful for me to suffer in the long run:

  • You can’t automatically link translated posts together
  • The UI text will only be in one particular language
  • Font fallback is going to be cursed (If you use CJK languages, you know what I’m talking about)
  • I wrote Twenty Twelve zh-CN subtheme to fix most of the Chinese font rendering issues brought by the default themes, and these fixes are not going to work well with an English post

So I’ve chosen the hard way to actually install an i18n plugin on my blog. There are 2 major ways to achieve i18n as a plugin:

  1. Just stack all different versions of a post into one post in the database, then display them individually in the frontend (e.g. WPML)
  2. Utilize WordPress Multisite to create sites in different languages then link them together (e.g. MultilingualPress and Multisite Language Switcher)

Both ways come with their pros and cons. The first method has a painless setup process, but if you want to opt-out one day, you’ll be left with only a bunch of unusable posts and you have to clean up all these posts by hand. The second method requires a much more complicated setup but you are free to opt-out at any time. I’ve worked with both WPML and MultilingualPress 2 at work, and I do like the latter more. MultilingualPress 3 does not have a free version as of now (although they said they will release one at the end of 2019), and MultilingualPress 2 has some compatibility issues with the new Gutenberg editor, so I decided to try Multisite Language Switcher this time. The choice is risky since Multisite Language Switcher does not seem to be maintained very actively, but at least it is free and open-sourced.

A Conversion to WordPress Multisite

Multisite is a handy way of creating multiple isolated blogs in one WordPress installation which has existed since I started to use WordPress. Still, converting a blog with 9 years of history is risky. Multisite provides 2 ways to access a site, either via a path prefix ( https://blog.example.com/custom-path/ ), or a subdomain ( https://custom-subdomain.blog.example.com ). The subdomain way seems to be too overkill for just i18n use and I’ll have a painful time setting up my SSL offloading reverse proxy, so a path prefix seems to be the best choice here. But here comes with the biggest problem: WordPress simply doesn’t allow you to choose the path prefix installation method if your blog already has content in it! The limitation comes with a reason: a new site’s path might be the same as one of your article’s slug. Assured of this shall not happen in my blog, I hacked my way through it.

First Things First

Backup, backup, backup. Backup your WordPress installation folder and your database. Multisite installation is one-way and if you lose data you lose data permanently.

Before Conversion

Disable all your plugins for now.

Add the following line to the top of wp-config.php :

Add the following line to the end of your active theme’s functions.php :

This is going to allow path prefix based multisites.

The Conversion

Log in your WordPress dashboard and go to Tools -> Network Setup. Double-check the options you choose, then click Install.

Post-Conversion Tasks

You’ll be instructed to paste something to both wp-config.php and .htaccess . Do it, then click the “Log In” link. If everything went well, then you’ll be prompted to log in and then redirected to the new WordPress Network dashboard.

Now you can re-enable your favorite plugins, either network-wide or on a per-site basis.

After the conversion, a prefix blog might be added to your first site (a.k.a. your original blog). To remove the prefix so all your old permanent link still work:

  1. Go to Network Admin -> Sites -> All Sites, find your main site, then click Edit, find “Permalink Structure” under “Settings” tab and remove the /blog part, click Save Changes
  2. Go to your main site’s dashboard, go to Settings -> Permalinks, verify the permalink settings are correct, then click Save Changes

Multisite Language Switcher

Compare to other commercial solutions, Multisite Language Switcher is not very user-friendly if you are a new user. After some tinkering around I’ve successfully got it working. Here are some things that you need to watch out:

  • You need to add yourself as an admin of all the sites (make sure they all show up on the top of the Multisite Language Switcher settings page)
  • You need to individually set up Multisite Language Switcher in all sites
  • Either click the little link icon in All Posts list to start a new translation, or type the original post’s title in the Multisite Language Switcher side widget in the post editor
  • You need to add a widget to your theme individually for every site to display a language selector
  • Categories and Tags might go wrong on the new sites, please manually check them
  • The edit permalink button might not work if you imported the post; use the Slug field on the bottom of the editor

References:

2 thoughts on “Hello World, the en_US Version

Leave a Reply

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