How-to: Generate a POT file for a WordPress Theme or Plugin

Translation files are a very important part of the WordPress ecosystem. They allow your plugin or theme to be used by people in all languages. So, you need them.  It’s less of a suggestion and more of a requirement 😉

If you are a plugin developer or theme developer and use a Javascript Task Runner like Gulp or Grunt, it’s super easy to add a task there to do it automatically:

Grunt has the grunt-wp-i18n plugin available.
Gulp has the gulp-wp-pot plugin.

That’s the easy way if you already use a task runner.  You load up the dependency, create a task, and you run the task!  Here’s a good tutorial on using Grunt with WordPress Development:–cms-21743 (A little old, 2014, but still good).

If you don’t use a task runner, I would suggest using the WordPess i18n Library of tools and specifically makepot and a neat little Bash script to do the hard work for you.  Here’s how you can do it:

  1. You’ll need to clone the SVN repo to your computer first
    sudo svn co
  2. Install gettext using Homebrew:
    brew install gettext

    If you don’t have Homebrew installed, you should install it.

  3. Then you will need to link it
    brew link gettext --force
  4. Now go into your .bash_profile or .zshrc and make sure to add the Path to where the library is
    # Path to WP_I18N_LIB
    export WP_I18N_LIB="/Users/mikeyarce/repos/WP_I18N_LIB"
  5. Now you can clone this little Bash script to make it easier for you to call makepot from any directory:
  6. Rename to makepot and move it into /usr/local/bin so that it’s globally accessible.

Now, to make a pot file, you can just navigate to the Plugin or Theme directory via Terminal, and just type in makepot.

Leave a Reply

%d bloggers like this: