How to Generate a .POT File Using Poedit

poedit

Introduction

Have you ever used WordPress for your own website or for your clients? Have you ever looked for and installed plugins for it? I guess that your both answers are YES.

So far so good, but what do you do if you need to translate your theme or plugin in your language? You may say that exists a file as .PO which is used especially for that reason. For example by using Poedit and .PO it’s pretty easy to make your translation.

Well, you’re right, but tell me the truth? Have you ever searched for that .PO file within the theme directory or plugin only to find that it’s not there? And if this is your case, what would you do then? Please don’t tell me that you would edit or change the theme… Of course you can use a child theme for that reason, but still it’s not the correct and easy way for that.

The right and professional way is to generate a .POT file. What a pity that the theme author hasn’t created it along with the theme. At least we hope that he had developed it in the correct way, so that to generate a .POT file would make any sense. Here I point to the use of translatable strings.

What is .POT File Used For?

First of all let us clear out what does the abbreviation POT means. Actually it stands for Portable Object Template. This is the file that you get when you extract texts from the application. Normally, you send this file to your translators.

The tool (in our case Poedit) that scans your PHP source will produce a .POT file. This file includes only the original texts, which needs translation.

What is Poedit?

Poedit is a software that offers the best way to translate apps and sites (that use gettext). Thanks to its distraction-free approach, you’ll translate faster and easier with it. Get your hands dirty and download it for free.

10 Steps to Generate a .POT File Using Poedit

Step 1

Download and install Poedit on your machine. My Poedit version is 1.6.7.

Step 2

  • Start Poedit
  • File -> Catalogs manager
  • New – create new translations project
  • Project name – put the name of the main folder of your theme/plugin
  • Browse – select the main folder of your theme/plugin and click OK
  • Close the Catalogs manager

poedit-2-1

poedit-2-2

Please take into consideration that all the entered data is just for example. You must put your own instead. As a matter of fact the entered data is not a dummy one, but these are the steps I followed to create a .POT file for my new WP Plugin “GSY Ajax Recent Posts”.

Step 3

  • File -> New
  • Select “English (United States)”
  • Click OK

poedit-3

Step 4

  • Catalog -> Properties
  • Project name and version – put here the name of your theme/plugin. Here I don’t mean the name of a folder or file, but the actual name. For example the name of my plugin is “GSY Ajax Recent Posts”.
  • Source code charset – select “UTF-8 (recommended)”
  • Click OK

poedit-4

Step 5

  • File -> Save
  • File name – put “en_US.pot”. I know that the .POT file extension is not listed. Instead you will find only .PO. Don’t worry about that, simply type it yourself as “en_US.pot”.
  • Check the directory you’re going to save it in. Must be in the main folder of your theme/plugin.
  • Click Save

poedit-5

Step 6

  • Check your main folder of your theme/plugin. There must be two new files created: “en_US.pot” and “en_US.mo”.
  • Delete the second one “en_US.mo”.

Step 7

  • Catalog -> Properties
  • Go to “Sources paths” tab
  • On the “Paths” section click on “New item”
  • Simply put a dot “.” and press ENTER to make sure it’s saved there

poedit-7

 Step 8

  • Go to “Sources keywords” tab
  • Click on “New item”
  • Type in as much new items as you wish. In my case I used only two because those are used on the plugin only. For more information see “Strings for Translation” in I18n for WordPress Developers.
  • Click OK

poedit-8

Step 9

  • Catalog -> Update from sources
  • If a small window appear asking you to save changes – click on Save

poedit-9

  • Now on your screen you’ll see that the .POT file is filled with all the data that need to be translated.
  • Click on the big button “Save” as shown below:

poedit-9-2

Step 10

  • Close the program Poedit
  • In the main folder of your theme/plugin you’ll see that the file “en_US.mo” is created again. Delete it again.
  • The very much desired and completed file is there: “en_US.pot”.

From now on it’s very easy to start Poedit, open this .POT file and make your translations i.e. your .PO and .MO files.

One thing to pay attention is that if you want to use those files in a plugin and not a theme they must be renamed like that: my-plugin-{locale}.mo where the locale is the language code and/or country code you defined in the constant WPLANG in the file wp-config.php.

Summary

I hope that the current tutorial is clear enough and you learned how in 2 minutes to generate a .POT file using Poedit. I wish I had such a tutorial before I made my first .POT file. Of course I googled a lot and read many articles, but to tell you the truth none of them was that much explainable. If I found an article it was either with an old version of Poedit or missed some key steps. Honestly speaking it took me many ours to find my way.

I’ll be happy to hear your comments and if you do have any advices concerning the topic feel free to share them.

Resources

FacebookTwitterGoogle+LinkedIn

18 Comments:

  1. You are my hero. I was looking such a simple tutorial for our company site. I hope my translation will finaly work. I have no PHP and Word Press experience. Translating the theme was the last thing to do. Thanks to you i think I will do it.

    1. mario says:

      thx man, you are the Best :)

  2. Hadorn says:

    Thanks a lot for this detailed tutorial! I have used POEdit for a while for various theme translations, but I had no idea I could generate a POT file like this. This is very helpful, bookmarked!

  3. jan says:

    thanks very much. what a pitty that i found your tutorial so late. its so good! and its unbelievable how bad the usability of poedit is. spend half a day getting it to work. your tutorial is great.

  4. keren says:

    Well done, I sure it wasn’t simple but it is priceless

  5. Charles Zhu says:

    This is one of the most detailed tutorials I’ve ever read online. Thanks so much!

    However, I sometimes encounter errors Step 9 with PoEdit version 1.7.1. My solution is to add one more path “..” in Step 7. Just in case someone else has the same problem.

    1. Georgi Yankov says:

      Thank you Charles! Your solution to add one more path “..” in Step 7 might be very helpful to someone as in this tutorial I’m using an older Poedit version 1.6.7.

  6. prabin says:

    really it was so helpful for me and thanks a lot.

  7. Marco says:

    Thank you very much for the step by step article!

    If I may add something, if you want to put the .pot and .po/-mo files inside a “languages” folder in your theme directory, you need to specify that folder in the catalog manager and then set “../” as base path in the Catalog Properties > Source Paths panel.

    1. Georgi Yankov says:

      Thank you, Marco!

  8. Md Fakrul Islam says:

    Fantastic tutorial, worked perfectly!

  9. papi Jo says:

    A splendid tutorial. Makes one wonder why such detailed instructions are not part of the POEdit Help files. Thanks a lot.

  10. David Casas says:

    Muchas pero muchas gracias, *****

  11. eli says:

    thank it works

  12. CK MacLeod says:

    Excellent tutorial. Kind of silly how non-intuitive the POEDIT interface is for this very basic process. I’ll not say more on the subject, but, specifically on your tutorial, you advise the user to create the POT file in the main folder of the plug-in, when in most translation-ready plugins, it will reside in a “languages” or sometimes “translations” folder.

    Any reason not to start in one of those? Any problem with following your instructions, and simply moving the POT file once created?

  13. Lautaro says:

    2 years later this is still the best tutorial on this.

  14. Ricardo Martínez says:

    When I started to plan how to manage all translations in my projects I was expecting a tool or process just like this.

    Your tutorial is very simple and easy to understand.

    Thanks a lot.

    Regards.

  15. Josh says:

    After spending HOURS trying to find a clear explanation about this, this is the first and only tutorial that has all steps accurately described. It’s 2017 and I cant believe that most sources are so incomplete. Most of them assume you have the .po file, or dont care to explain that you need to place the .po file in the root folder instead of /languages. Poedit navigation is non-intuitive and it doesnt clearly tell you that you need to create a catalog first before creating a new file. Duh!

    Thanks so much for this!!

Leave a Reply

Your email address will not be published. Required fields are marked *

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