Multilingual WordPress – Localising themes

Multilingual wordpress

Where exactly is the é on this keyboard?

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.

Using Poedit

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.

Get Adobe Flash player

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.

Next instalment…

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.

Comments

  1. hello.

    something did not work out in terms of translating text inside the template files on my site – http://www.crativeroad.us … any ideas how to solve it ?

    • Hi,

      No way for me to tell from here, I’m afraid.

      Assuming you created your .mo file OK, named it correctly, are running WP in the same language, and you’ve added the necessary code to load your textdomain in functions.php, I suggest you look at the other articles in the series, especially the ones on setting up WP and internationalisation. There’s probably a step you’ve missed.

  2. Andy Welch says:

    Hi, you may want to mention that the .mo filenames should be for example: ru.mo rather than ru_RU.mo. I just spent the last hour working that out. It’s on the poplar language switcher plugin site documentation, but I think your description is a little misleading over that. Anyhow, otherwise, great work, thanks a lots! The site I’ve used your tutorial for is http://www.openmapscaucasus.org.

    Cheers

    Andy

  3. I found a better tool than poedit. It sounds similar but it’s better: https://poeditor.com/. It’s an online service that has a very friendly interface for translators and helpful functions such as API or translation memory. I’m sticking to it for the moment and I recommend it.

    • Thanks for the tip! But please don’t spam my site with multiple comments promoting the same thing. Next time – I delete the one plug I’ve let through. ;-)

Leave a Comment

*


× 3 = twelve

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>