This article will show you how to run WordPress in two or more languages. Visitors can select the language of their preference and it will be displayed accordingly.
Making your WordPress Multilanguage basically consists out of two types of changes.
1. The addition of a second or third language by downloading and installing a WordPress language file.
2. Making your theme suitable for more than 1 language.
The wordpress language file
To get this one running you have to get your hands on translated version of all WordPress terms and words that are used in the frontend and the backend. This is a file with the extension *.pot. You can get a start by looking at the localization pages of wordpress. What’s an even better idea is if you get the same file in *.mo format and install a PO Editor. The MO file is basically the finished version of a MO file. If you have a good MO file, you won’t need the *.POT or PO.
Installing a language switcher plugin
Now you have the translated version of WordPress in a *.MO file, it’s time you also install a plugin that is able to switch your language for you and remember it. The plugin I prefer is “Language Switcher”, which you can download here on this page. It also has excellent information on the subject.
Configuring the plugin and placing the language file
You will find the plugin under Options -> Language Switcher. This will basically point itself out. You need to upload the MO file under wp-includes/languages for it to function. You will also need to edit wp_config.php in the root directory of WordPress to add additional languages. Change the following line:
into
So now we have all configured, but you have yet to see an option at the frontend of your blog to select a language. You may insert the following code anywhere in your template to show the language switcher menu:
-
langswitch_list_langs(true, true);
-
}?>
If all went well you are now able to switch between two languages both frontend and backend.
Making the rest of your theme multilanguage
As you have noticed, only everything translated in the WordPress MO file will show up as the second or third language. Your theme will still show parts in your primary WordPress language. You can fix this by making a theme MO file.
This theme MO file you place in your themes directory. It HAS to be named nl_NL.mo or it won’t work! Any other language code should also be done in this manner. de_DE.mo and so on. Just make sure the names are the same as they have been used in wp-config.php.
What you have to do is look at the texts in your theme that need to be translated and use PO Edit to create the MO file for the theme. PO Edit is a confusing tool if you’ve never used it before. You will need to place your entire theme in a directory on your hard disk and create a new catalog in PO Edit. For this new catalog you must explain PO Edit where the catalog would find the source files (your theme). If you save the PO/MO in the root directory of the theme, use a dot to indicate the location. Secondly, you must tell PO Edit what to look for in your theme that needs to get translated. Create two entries: e_ and __. Click here for an explanation. Here are the screenshots for POEdit:
In order for POEdit to pick up things that need to be translated you must now edit your themefiles to look up words that need to be translated and indicating them by using the GETTEXT php function. e_ and __ are used in places to indicate it needs to switch languages. But first, you must tell WordPress what the name is of the language file you’d like to include. Add this in functions.php of your theme:
-
< ?php load_theme_textdomain(‘afad’); ?>
After this, you will need to gettext everything you’d like to translate in your theme files:
example index.php
-
-
// Show the last 5 posts in any category.
-
-
$secondpost = TRUE;
-
query_posts(‘showposts=5′);
-
-
if (have_posts()) :
-
while (have_posts()) : the_post();
-
if ($secondpost) {
-
?>
-
-
<div class="trans1">
-
<table width="581" border="0" cellspacing="0" cellpadding="0">
-
<tr>
-
<td></td>
-
<td class="title">
-
<h1><a href="<?php the_permalink(); ?>#top3" rel="bookmark" title="< ?php printf(__(‘Permanent Link to ‘,’afad’));?>< ?php the_title(); ?>">< ?php the_title(); ?></a></h1>
-
</td>
-
</tr>
-
<tr>
-
<td class="date">
-
<span class="date_month">< ?php the_time(‘m’); ?></span>
-
<span class="date_year">< ?php the_time(‘Y’); ?></span>
-
-
< ?php edit_post_link(__(‘Edit’,‘afad’)); ?>
-
-
-
-
</td>
-
-
<td valign="top">
-
-
<div class="entry">
-
-
< ?php the_excerpt(__(‘Continue reading »’,‘afad’)); ?>
-
-
<div class="comments"><img src="<?php bloginfo(‘stylesheet_directory’); ?/>/images/view_comment.gif"><p class="commenttext">< ?php comments_popup_link(__(‘» No Comments’, ‘afad’), __(‘» 1 Comment’, ‘afad’), __(‘» % Comments’, ‘afad’)); ?></p></div>
-
</div>
-
-
</td>
-
</tr>
-
</table>
-
-
</div>
-
-
< ?php
-
}
-
?>
-
< ?php endwhile; ?>
-
-
< ?php else : ?>
-
-
<h2>Not Found</h2>
-
<p>< ?php _e("Sorry, but you are looking for something that isn’t here."); ?></p>
-
-
< ?php endif; ?>
In the example file some lines become php _e and some printf(__(. I still haven’t quite understood why to use one or the other, but trying them out will usually get you there.
Et voila~ A fully multilingual wordpress!
But wait? How to blog in more than one language?
When you type up an entry you can use these tags: [lang_nl]Tekst hier[/lang_nl]. An english language version can be placed below that [lang_en]Text here[/lang_en]. This also works for the title field and various other fields.
End conclusion
However cool it looks to have a multi-lingual blog, it’s a horrid process to get done. This is not something you do within 5 minutes! Also know, that whatever you do with plugins or themes; at some point they may conflict when you decide to upgrade your WordPress installation. Just know what you’re getting into.
Pingback: ALTERNATE-REALITY.NET » Blog Archive » Article updated on multilanguage