Main Menu

Creating a New Language File for a Theme Translation

Recently, I’ve had a lot of customers asking me about creating a theme translation file for some of my themes. What I always assumed was a straightforward process actually has a few little kinks that could confuse most people. It takes a couple of steps, but once you get the hang of it, it won’t seem so difficult.

First off, let’s discuss the software I use to translate my themes.

Working with PoEdit

PoEdit is free, though there is a premium version you could buy. I opted for the premium version since I use it all the time and those extra features do really come in handy.

Once you load up a POT file, you will see all the translatable strings. Select your language and translate away. Once the strings have all been translated, click save and PoEdit will create the PO and MO theme translation files you need with the appropriate filenames.

You can see on that page that a Canadian English language file should be named en_CA.po and a French language file should be named fr_FR.po. Look through the list to see the correct name for your language.

Switching WordPress into your language

This step of the process has become easier ever since the setting option was added to the General admin page. Before you had to edit wp-config.php but now you can just select your language from the drop down list.

Adding your theme translation file to the right folder

This is the one step that I actually didn’t really know much about. I thought you just had to add the new theme translation file to the theme’s languages folder. Though, this creates an issue if you ever update, since that folder is replaced and the custom language files are deleted.

The correct and safe way to store a language file is to create a languages folder in your wp-content folder. The hierarchy should look like this:

- wp-content
- - languages

Since you’re creating a translation for a theme, you need one more folder.

- wp-content
- - languages
- - - themes

We’re almost there. The languages folder we’re going to use is now outside of the theme folder, so we need to let WordPress know which files link to which themes. That means we have to change up the naming convention a little to connect things.

If you’re creating a French language file for the theme Arcade, this is how the folder/file setup should look:

This is really a nice tutorial as translation plays a big role in current time. Most of the sites are ranking in any country and in that case translation feature will definitely add value to users point of view.

Really good article. Have been looking around for a straight forward answer and this helped. Occasionally we get clients looking for a website in the UK which can also be translated overseas and this will make life a lot easier. Thank you.

I’m wondering, though, why the context defined in _x or _nx don’t show in POEdit.
When you open the PO file in a conventional text editor, you can see the context, but not in POEdit itself.
Any ideas for another program that does?

Best!

c.bavota

August 3, 2016 at 9:14 am

PoEdit can detect _x and _nx, you just need to set it up first. I found this online:

You need to tell POEdit which keywords to look for when scanning our files. Enter the following:

__
_e
_n:1,2
_x:1,2c
_ex:1,2c

The :1,2 extension tell POEdit that these keywords have two parts to them. By default, the second argument is the plural unless you include the c which mean the second argument is a comment.