Translation with POEdit - Internationalize / Localize WP Themes Guide -Part 3
Now that you made your theme translatable, let's do the necessary to translate it.
For that you will have to use a translation software, in this guide we'll use POEdit, so go ahead and download then install it.
We will use POEdit to create a PO (Portable Object) file which will contain all the translatable words & phrases and optionally their translation for a specific language. If you add a translation to the PO file, you can setup POEdit to create a MO (Machine Object) file, which is the machine-readable file (the one we need to upload to the server with the theme).
Note: PO files have
Launch POEdit & before anything else make sure it will automatically save a MO file every time we make or modify & save a PO file: Go to File > Preferences..., in the Preferences box choose the Editor tab, under Behavior see if "Automatically compile .mo file on save" is checked, check it if not.
Now let's start making the PO file, go on File > New Catalog...
A box will pop-up with 3 tabs:
The first one (Project info) is for general information, enter utf-8 for "Source code charset" & you may want to give your project a name (theme's name maybe). Fill the other fields if you wish ...
The second tab Paths is to give POEdit the path of your theme's directory (on your hard drive), bad thing is that you can't just click on browse & find the directory of your theme. To get the path, use Windows Explorer, browse till you enter your theme's folder then copy the path from the Address Bar, the path may look a bit like this:
Click the "New item" button (graphic icon of a little square & star), a field will be created, paste in your path & hit Enter.
Go to the third tab named Keywords, there you tell POEdit about the two GetText functions "_e" & "__". Click the "New item" button, a field will be created, type in "_e" (without the quotes), press Enter then click again on "New item" & type "__" (2 underscores without the quotes). Hit Enter again then click on OK. You'll be asked to give your catalog (PO file) a name, since we'll use it for a specific language, use the two letters ISO Code of that language, for example "ar" for Arabic or "fr" for French (without the quotes). A long list of ISO codes here on Wikipedia. Once the name given click on OK.
Note: POEdit will create a MO file named just like your PO file (ar.po & ar.mo for example).
If you did everything correctly, POEdit should start scanning the theme's files then show you a box with the results, click on OK.
In POEdit now you can see three rows:
The first one has two columns, one for original strings, the ones in the theme's files that you wrapped in the second step, the second column is for translation, would be empty still. In this first row you can click & select the strings you want to translate (or change translation later).
The second row shows the original string selected in the 1st row (not editable).
The 3rd row is where you will enter the translation for the string selected.
You know what to do now, make your translation for each string then when finished save your catalog (File > Save or Ctrl+S).
After you edit the files, POEdit allows you to update the translatable strings: Open your PO file then go to Catalog > Update from sources, POEdit will scan the files again & pop-up a box with a list of "New strings" & a list of "Obsolete strings" (the one that you may have removed), you click on OK to update the catalog.
OK, now rest to upload the theme to the server with the MO file included in the directory. Make sure you use Wordpress translated to the same language, most likely you will find it in the WordPress in Your Language page.
For that you will have to use a translation software, in this guide we'll use POEdit, so go ahead and download then install it.
We will use POEdit to create a PO (Portable Object) file which will contain all the translatable words & phrases and optionally their translation for a specific language. If you add a translation to the PO file, you can setup POEdit to create a MO (Machine Object) file, which is the machine-readable file (the one we need to upload to the server with the theme).
Note: PO files have
.po
extension & MO files have .mo
as extension.In this guide we will create the MO file in one go with the PO file for a specific language:
Launch POEdit & before anything else make sure it will automatically save a MO file every time we make or modify & save a PO file: Go to File > Preferences..., in the Preferences box choose the Editor tab, under Behavior see if "Automatically compile .mo file on save" is checked, check it if not.
Now let's start making the PO file, go on File > New Catalog...
A box will pop-up with 3 tabs:
The first one (Project info) is for general information, enter utf-8 for "Source code charset" & you may want to give your project a name (theme's name maybe). Fill the other fields if you wish ...
The second tab Paths is to give POEdit the path of your theme's directory (on your hard drive), bad thing is that you can't just click on browse & find the directory of your theme. To get the path, use Windows Explorer, browse till you enter your theme's folder then copy the path from the Address Bar, the path may look a bit like this:
C:\Documents and Settings\Something\Desktop\theme-directory
Click the "New item" button (graphic icon of a little square & star), a field will be created, paste in your path & hit Enter.
Go to the third tab named Keywords, there you tell POEdit about the two GetText functions "_e" & "__". Click the "New item" button, a field will be created, type in "_e" (without the quotes), press Enter then click again on "New item" & type "__" (2 underscores without the quotes). Hit Enter again then click on OK. You'll be asked to give your catalog (PO file) a name, since we'll use it for a specific language, use the two letters ISO Code of that language, for example "ar" for Arabic or "fr" for French (without the quotes). A long list of ISO codes here on Wikipedia. Once the name given click on OK.
Note: POEdit will create a MO file named just like your PO file (ar.po & ar.mo for example).
If you did everything correctly, POEdit should start scanning the theme's files then show you a box with the results, click on OK.
In POEdit now you can see three rows:
The first one has two columns, one for original strings, the ones in the theme's files that you wrapped in the second step, the second column is for translation, would be empty still. In this first row you can click & select the strings you want to translate (or change translation later).
The second row shows the original string selected in the 1st row (not editable).
The 3rd row is where you will enter the translation for the string selected.
You know what to do now, make your translation for each string then when finished save your catalog (File > Save or Ctrl+S).
What if for some reason you decided later to modify the strings to translate, create new strings or delete strings? (by editing the PHP files of the theme)
After you edit the files, POEdit allows you to update the translatable strings: Open your PO file then go to Catalog > Update from sources, POEdit will scan the files again & pop-up a box with a list of "New strings" & a list of "Obsolete strings" (the one that you may have removed), you click on OK to update the catalog.
OK, now rest to upload the theme to the server with the MO file included in the directory. Make sure you use Wordpress translated to the same language, most likely you will find it in the WordPress in Your Language page.
I've followed these posts and others I've found on the subject but always run into an issue of Wordpress not rendering or finding my MO file. I do not no where to put the MO file so the load_theme_textdomain() can find it? Can you outline the directory structure of wordpress, your theme and where the MO will go in each?
ReplyDeleteHi, damn sorry for the late reply, being too busy,
ReplyDeleteFor the WP core MO should be here:
/ public_html / your-site-folder / wp-content / languages / ll.mo
You have to create that languages folder
Actually for some reason the ar.mo is working for me but not fr.mo, didn't have time to try to solve that
For the MO of the theme, should be in the theme's directory:
/ public_html / your-site-folder / wp-content / themes / your-theme / ll.mo
I'm using the Language Switch plugin & all languages work fine there.
[...] - bookmarked by 1 members originally found by kevjumba15 on 2009-01-01 Translation with POEdit - Internationalize / Localize WP Themes ... [...]
ReplyDelete[...] activated the use of .mo files (instead of .po) for the internationalization [...]
ReplyDeleteHi!
ReplyDeleteNice tutorial and also very clear.
I have followed the steps from the first to the end but I can't see the theme translated. I don't know where to start searching for some error.
Any ideas?
Thx
it seems that it has something to be with the fact that I am using multiuser version.
ReplyDeleteAnybody has any idea?
A good tutotial
ReplyDeleteBut like Jason says, I as well often find Wordpress not rendering or finding my MO file.
@Jason Darrow
ReplyDeleteYou will need to edit the wp-config.php file to define the WP_LANG constant for the language you want wordpress to use, apart from having the language files as MuMu said.
@MuMu
Try renaming fr.mo to fr_FR.mo and see if that works.
Ciao
[...] Next Part : Translation with POEdit [...]
ReplyDelete[...] Parte III [traduzindo com Poedit - já temos outro tutorial aqui mesmo] https://gettingeek.com/translation-with-poedit-internationalize-localize-wp-themes-guide-part-3-74.ht... [...]
ReplyDeleteYour defining work of localization and internalization really sets me up on the work.
ReplyDeleteGreat guide.
[...] This post was mentioned on Twitter by sheldonrampton. sheldonrampton said: How to do a language translation project with Poedit: http://bit.ly/aSfdxj http://bit.ly/5BrzRk http://bit.ly/buaXNP [...]
ReplyDelete[...] activated the use of .mo files (instead of .po) for the internationalization [...]
ReplyDeleteIf you plan to drink this detox drink on the day of the drug test, try starting your regime a few hours earlier. Abstaining from weed and drinking detox drinks are known to bring great results, but if you are a chronic smoker, you might want to consider a few extra tips to avoid any trouble: Even though abstaining from cannabis and a toxic environment is highly recommended, some consumers are reported to have tested negative just by drinking the Mega Clean Detox drink even while smoking pot. This goes to show how the test results vary from person to person and the efficacy of this detox drink truly depends on many external factors too. If we talk about difficulty levels, passing a urine test is relatively easier than passing a blood or saliva test. Make sure you properly investigate any shampoo you're contemplating to verify that it adequately removes drug residues from your hair. Online user reviews and product descriptions can be extremely useful sources of information.
ReplyDelete