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
- 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
- Go to Tools, then Localization.
Step 3. Create the languages folder
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
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
- Choose the language you want.
- Click create-po-file
Step 6. Rescan the po file
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.
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.
- 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.
- 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
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.
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.
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
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.
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
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.
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
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.
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.
Sometimes the context is located in more than one file. For example, the word "Register" is used in 5 different php files.
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.