In this fourth part of my series of articles on setting up a Multilingual WordPress site, we’ve looked at the basic requirements for setting up a Multilingual WordPress site, how to set up the Language Switcher plugin to allow us to create multilingual content and let the site visitor switch between the languages, and how to internationalise the theme files.
The next steps are to:
- Localise our theme files – which means translating English text in the theme files into our second language, which is the subject of this article
- Set up WordPress to run in the two languages
Localising theme files using Poedit
Localisation of theme files means translating the “internationalised” text that we implemented in the previous article in this series.
In order to do this, we need software which will scan our theme files and find all the text in gettext format, and allow us to translate this text and save the translation files in the appropriate format. My preferred choice is Poedit, a free software, and pretty much the standard for this job. So, grab a copy of Poedit and install it on your computer.
Work on a local copy of your theme files
Copy your theme folder to your desktop – or somewhere else where you can find it easily.
In your theme folder, create a sub-directory called languages. This is where we will store the translation files once they have been created.
I have to say that using Poedit for the first time is not very intuitive, so here’s a video to show you how to do it.
Tips for using Poedit
A brief list of the main points covered in the video:
- Create a new translation with File > New Catalog
- In the New Catalog dialogue box, give the catalogue a name.
- In the same dialogue box, in the Paths tab, add the path to your theme folder
- In the Keywords tab, add two keywords: _e and __ (the latter is two underscores).
- Click OK. You will now be prompted to save the .po file. Use the xx_XX.po format discussed in a previous article in this series, ie fr_FR.po for French, de_DE.po for German, etc.
- Poedit will start parsing the files. Click OK when the parsing is finished, which will take you back to the main translation screen.
- Translate all the strings. Don’t forget to include punctuation in the translation if it exists in the original string (subject to any specific conventions of the second language).
- Click File > Save to save your translation in the .po and .mo formats.
- If at a later date you change any of the original strings in the theme files, run Poedit again, this time opening the existing xx_XX.po file created previously. Then select Catalog > Update from sources to re-run the parser. The parser will notify you of any new strings found and any obsolete strings. Obsolete strings can be deleted, or left alone. Translate the newly added strings and re-Save the xx_XX.po file.
Upload the translation files to your server
Once you are happy with your translation, upload the xx_XX.po and xx_XX.mo files to a folder called languages, within your theme’s folder on your server. The location of the files is important, as they need to be referenced by code in the theme’s functions.php file, as discussed in the previous article Multilingual WordPress – Internationalising Themes.
In the next, and final, part of this series we shall look at configuring WordPress to work with both languages, and dealing with any troubleshooting that may be required – especially with plugins.
- Setting up a multilingual Wordpress site
- Multilingual Wordpress - Language Switcher plugin
- Multilingual Wordpress - Internationalising themes
- Multilingual Wordpress - Localising themes
- Multilingual Wordpress - Setting up Wordpress