How to Change Language Strings in WordPress

tutuploadstutuploadsStep_1_e89acfc2fe27842b99ab66e9ed625e0c.png

WordPress has language files that hold all of the messages and labels you see while using your site. You can change this text if you need to.

If you want to change any of this default WordPress text you’ll need to work with something called a Portable Object Template file, or POT.

For the geeks amongst us, it uses the GNU gettext framework to manage all the messages. There are two other file types involved, PO and MO as well. Towards the bottom of the page we explain more about how these files work.

Fortunately for the non-geeks amongst us, there is an ingenious plugin that makes editing it’s all very simple. The plugin is called CodeStyling Localization.  

If you’re lookng to translate your site, try our other tutorial on multilingual plugins. Here we’re only going to show you how to edit small amounts of text.

Step 1. Install the Codestyling Localization plugin

tutuploadstutuploadsStep_1_e89acfc2fe27842b99ab66e9ed625e0c.png
  • Go to Plugins, then Add New, Search for codestyling localization.
  • Click Install Now to install the plugin.

Step 2. Access the plugin from the Tools Menu

tutuploadstutuploadsStep_2._Access_it_from_the_Tools_Menu.png
  • Go to Tools, then Localization.

Step 3. Create the languages folder

tutuploadstutuploadsStep_3._Create_the_languages_folder.png

If you see this message, click the button to create the directory. If that fails, use a file manager and create the languages directory wp-content/languages (languages should be plural).

Step 4. Create the PO and MO files for WordPress in your language

tutuploadstutuploadsStep_4._Create_the_PO_and_MO_files_for_WordPress_in_your_.png

Click Add New Language.

If the All Translation tab is active, you will see a all of the possible places you would need to edit the language files. The WordPress section will be most likely be blank. So you will need to add your language.

Notice that there are tabs across the top. These will take you directly to the ones for specific plugins and themes. You may have to add this language to all the PO files for every element of the site, so you will be repeating this procedure. Scroll down this page and you’ll see the plugins and the themes. Add your language to each that you want to change.

Step 5. Choose the correct language

tutuploadstutuploadsStep_5._Choose_the_correct_language.png
  • Choose the language you want.
  • Click create-po-file

Step 6. Rescan the po file

tutuploadstutuploadsStep_6._Rescan_the_po_file.png

Click Rescan.

Once the PO file is created you’ll see a green box for the po and a white box for the mo. Clicking rescan will get all the information from the POT file and make it available in the interface.

If the mo box is red, it means you do not have proper permissions for writing to the file. Clicking the red box should fix it, but if it doesn’t, you can chmod the permissions manually.

tutuploadstutuploadsmedia_1328656746186.png

Be patient. This may take some time. You’ll get a finished button to click when the process is completed. Don’t navigate away from the page until it the process is done.

tutuploadstutuploadsmedia_1328655758505.png
  • Click Edit on the original page.
  • You’ll see the list of all language strings similar to the image below. You might not see the list or be able to edit anything until you do the rescan. After it’s done, you can search and find whatever string you need to change.

tutuploadstutuploadsmedia_1328655876098.png
  • Here is a menu for refining the search.
  • A speed bar with the pages, there may be many of them.
  • A search box for finding the one you want.
  • Mousing over the little icon at the left pops up the context – or the file that calls the string and wraps it with php and html.
  • The Edit link is on the right.

Step 7. Make a change

tutuploadstutuploadsStep_7._Make_a_change.png

You won’t be able to create the mo file until you’ve made at least one change here. Let’s make a simple one. Scroll down the list, and find the string “Remember Me” and click the edit button on the right side of the row.

tutuploadstutuploadsmedia_1328657992710.png

In the popup editor, you will only be able to make changes in the Translation box. Change the string to what you want and then click Save.

tutuploadstutuploadsmedia_1328658150086.png

Now you’ll see the original and the translation on the list. Scroll up to the top of the page.

Step 8. Generate the mo-file

tutuploadstutuploadsStep_8._Generate_the_mo-file.png

Click generate mo-file. You can leave the Textdomain: as default.

Note the back to overview page button. You’ll need it in a few seconds.

tutuploadstutuploadsmedia_1328658298082.png

You will get date-time confirmation of when it was last written. Go back the top of the page and find the back to overview button.

Step 9. Rescan to enable the change

tutuploadstutuploadsStep_9._Rescan_to_enable_the_change.png

Click Rescan when you return to this page.

The mo box will be filled in. If it’s green everything is good. If it’s red, it means that the directory permissions are wrong. Clicking the box will attempt to fix it. If it doesn’t fix it, then you can use a file manager and chmod it manually to something writable – 644, 666, 755 would probably all work.

tutuploadstutuploadsmedia_1328659263541.png

The result of the change.

POT-PO-MO What are these special files and what do they do?

This is explained really well in the WordPress Codex, so I’m going to quote from the codex,

“There are three types of files used in the gettext translation framework. These files are used and/or generated by translation tools during the translation process, as follows:”

POT (Portable Object Template) files
The first step in the localization process is that a program is used to search through the WordPress source code and pick out every message passed into a __() or _e() function. This list of English-language messages is put into a specially-formatted template file (POT file) that forms the basis of all translations. Generally, you can download a POT file for WordPress, so you shouldn’t have to generate your own. Separate POT files can also be made for themes and plugins, if the theme/plugin developer has enclosed all text in __() or _e() functions. “

PO (Portable Object) files
The second step in the localization process is that the translator translates all the messages from the POT file into the target language, and saves both English and translated messages in a PO file. “

MO (Machine Object) files
The final step in the localization process is that the PO file is run through a program that turns it into an optimized machine-readable binary file (MO file). Compiling the translations to machine code makes the localized program much faster in retrieving the translations while it is running. “

The nature of a POT file

tutuploadstutuploadsThe_nature_of_a_POT_file.png

The process using the plugin is extremely simple, but it can be a large tedious process. Often times you change something and the typeface is the wrong size or it doesn’t fit the theme. If you understand the way the file works and the context you’ll be able track down the problems.

If you ever need to do this manually or create a language file for a plugin you write, start by downloading this file from http://svn.automattic.com/wordpress-i18n/pot/trunk/wordpress.pot

Here’s what’s inside:

At the top of the file you’ll see the version. Be sure the version matches the version of WordPress you are using. Below that you will see the actual language strings in three lines (or more).

Line 1 is the location of the file and the line number where you can find it used. Referred to as the context.
Line 2 is the actual text that is displayed. Sometimes it’s a variable or more than plain text.
Line 3 is where you can type a translation if you are creating a multilingual site or doing this manually.

tutuploadstutuploadsmedia_1328649482931.png

Above you can see line 43 of wp-activate.php. This is where you will find the html for this message. This is the context.

tutuploadstutuploadsmedia_1328650551309.png

Sometimes the context is located in more than one file. For example, the word “Register” is used in 5 different php files.

tutuploadstutuploadsmedia_1328650786112.png

And a word may be used in several different strings, so using a global search and replace utility won’t work really well unless you understand how to search and replace regular expressions. Notice also that there is some markup included in the POT file itself such as the span tags in the second example. The second example also shows you that there are two translations needed one for singular and one for plural.

Not to over complicate this process, but the first time you try editing this you most likely will not get the result you want. Sitewide changes may require more than simply replacing the words or messages.

It pays to work slowly and check your work to make sure you do a thorough job.

Author

0 0 votes
Article Rating
Subscribe
Notify of
14 Comments
Oldest
Newest
Inline Feedbacks
View all comments
Gapp
Gapp
11 years ago

Thanks for this awesome article!

Made my life a lot easier.

ngaosyvathn
ngaosyvathn
11 years ago

hello, bonjour, very very very very useful, i was lost in translation; TRES TRES utile, vraiment pas à pas, sans de blabla inutile, une illustration, une action, une illustration, une action ainsi de suite: un enfant de un moins pourrait le faire. J’étais désespéré avant!!! Thank you very very much, merci infiniment.

Andrey
Andrey
10 years ago

Great tutorial! Thanks a lot!

Done it step by step. Nothing can be easier.

kpax2012
kpax2012
10 years ago

Thank you, Thank you, Thank you, Thank you, Thank you, Thank you,THANK YOU for writing this tutorial. I was struggling so badly with this.

steve
steve
10 years ago
Reply to  kpax2012

Happy to help, kpzx2012 🙂

summ3r
summ3r
10 years ago

If you’re interested in a tool to easily translate WordPress strings, have a look at the online localization platform [url=https://poeditor.com/]https://poeditor.com/[/url]

It’s even got a plug-in you can use with it to integrate its API to your WordPress so that you save more time with the file management process. You can find it here: [url=http://wordpress.org/extend/plugins/poeditor/]http://wordpress.org/extend…[/url]

Pool Liners HQ
Pool Liners HQ
10 years ago

Same here, thanks for this very clear overview! Localization is definitely not the most user friendly part of WordPress. 🙂

Prometheus
Prometheus
9 years ago

Thanks you soooooooo so so so much!!!! you just save my day!

Mariano
Mariano
8 years ago

It looks like this plugin is no longer in the wordpress repository:

[url=http://wordpress.org/plugins/codestyling-localization/]http://wordpress.org/plugin…[/url]

RG
RG
8 years ago

All of that and not once did you say how to actually APPLY the mo file to the site.

Philippe Lhoste
Philippe Lhoste
7 years ago

Yes, this plugin seems to have disappeared, although the part about translation file format is still useful.

I have found [url=https://wordpress.org/plugins/loco-translate/]https://wordpress.org/plugi…[/url] which seems to do the same thing and worked beautifully for me: I could easily change WP-Members translation for my language, which was my main goal. Works on WordPress itself, plugins, themes… Generates MO automatically when saving the PO: fast and transparent.

Srikanth Ganta
Srikanth Ganta
7 years ago

Very useful information..but looking for similar article for Drupal 7/8

daniel-pickering
7 years ago
Reply to  Srikanth Ganta

Hi Srikanth,
You mean like this post [url=https://www.ostraining.com/blog/drupal/d8-multi-lingual/]https://www.ostraining.com/…[/url] ?

alexander
alexander
6 years ago

Thankyou for sharing this great article as you defined the steps perfectly that anyone can understand. I have also gone through one of the article changing WordPress language on WPblog as they have also provide steps by steps guidance for audience and this is a good way for people to understand the article.

14
0
Would love your thoughts, please comment.x
()
x