Quite often, I do get emails from people who wants a version of my theme, ported to their language. I always thought it is a cumbersome job to make the theme internationalized.
but recently my opinion got changed by a Danish guy.
Henrik from http://henrik.schack.dk/ recently contacted me asking me if it is OK to release the Danish version of MistyLook that he worked on.
I had a little chat with him over the email and this is what I learned.
Step 1: Prepare your WordPress Theme:
You have to wrap all your text within the theme, inside a
<?php _e('some text goes here', 'ml') ?>
It means if you want the sidebar’s heading to have
<h3>Pages</h3>
you should actually be coding it as
<h3><?php _e('Pages','ml'); ?></h3>.
You should do this everywhere the theme emits any text.
Next thing we have to do is, add a line in the functions.php.
<?php load_theme_textdomain('ml'); ?>
where ‘ml’ is the short form of the theme name ‘MistyLook’.
Step 2: Create a .POT file
The next step is to create a .POT file. This file is the catalog of all the places in the theme files, that we want the text to be translated.
something like
#: archive.php:36 search.php:19
msgid "Read Full Post »"
msgstr ""
which specifies the line number 36 in the archive.php file and the line number 19 in the search.php has the text “Read Full Post »” which needs to be translated.
Similarly it has entries for each of the text items that has to be translated.
Step 3 : Translating the theme
This .POT file we created in the previous step, is the starting point for our translation effort.
Now somebody has to say if it is “Permanent Link” in english, it is called “Lien Permanent” in french or “Eslabón Permanente” in Spanish [I just used an online translator for arriving at this text].
So if somebody wants to translate the theme to Spanish, they will simply load the .POT file that we have for the theme into a software like PO Edit and enter the equivalent Spanish strings for each of the English string we have provided.
From this tool, we can generate a .MO file for Spanish translation or a .MO file for French etc.
Once a .MO file is created, it should be placed within the theme folder.
How does WordPress know to apply this .MO file?
Ok. We have a .MO file which contains the translated text for German, for example.
but for the WordPress to load this file, you need to change the wp-config.php file.
Look for
define ('WPLANG', '');
and change it to
define ('WPLANG', 'de');
This is for when you have a German Translated file. If your language is different, you should use your language code instead of ‘de’.
Thats it.
If a language file is found, then it will be used or otherwise it will use the text in English.
[This article is a draft of what I have understood so far, about making the theme ready for translation. As I learn more, I will update this post.
First Posted on : April 01 2008.
]
