Create a Multi-Language wordpress Blog

October 8, 2008 · Print This Article

Using WordPress plugins to automatically translate blog content

This is the easiest solution. A few WordPress plugins allows you to put some clickable flags in your sidebar, that will automatically translate your content to another language using, for example, Google Translate.
This is a great solution if you’re looking for a way to make your content available for people that doesn’t speak your language, but you guessed it, the automatic translation isn’t as good as a human translated text.

Using categories and a few hacks

If you’re a perfectionist, you probably don’t really like the automatic translations provided by Google. In my opinion, if it’s okay for a personal blog, but automatic translations should be avoided on a professional blog.

For this hack, we will use categories. Go to your dashboard and create categories/sub-categories following the example below:

    One category
    Two categories
    Une catégorie
    Deux catégories
    Eine kategorie
    Zwei kategorien

Of course this is just an example, you can add as many categories as you want. The thing to remember here is that we’re using top level categories for languages, each of them having sub-categories organized by topics.

Now, you should post at least one example post in each sub-category. Once you’re done, we can start editing our header.php template.

The idea is quite simple: First, we must display the available languages, and then, a menu with the sub-category related to the current language. We must also think about defining a default language, which will be English in this example.

1 – Creating the language menu
Insert the following code where you want the language selection menu to appear:
$lang = 1; // Sets the default language

As you can see, we just need the good old wp_list_categories() function to get our available languages.
Then, we have to keep a php variable containing the id of the top level category, in order to display the navigation menu in the selected language. We must give a default value to the $lang variable. This default value will be the category id of the language you want to set as default.

2 – Navigation menu
Now, we got a php variable containing the id of the mother category. As the top-level categories are languages, we know which language the user is using.

We simply have to display second-level categories.

3 – Retrieving category
Here’s a sample code you can use to automatically list posts from a category. This code get the current category (in this example, the language) and then displays the related posts.
<?php foreach((get_the_category()) as $category) {
$thecat = $category->cat_ID . ' ';
if (have_posts()) : while (have_posts()) : the_post();
//Classic WP loop

Your choice for site templates and wordpress themes


Got something to say?

You must be logged in to post a comment.