Skip to content

Instantly share code, notes, and snippets.

Created August 23, 2012 13:55
Show Gist options
  • Save johnpbloch/3436835 to your computer and use it in GitHub Desktop.
Save johnpbloch/3436835 to your computer and use it in GitHub Desktop.
A bash script to make .pot files for WordPress plugins


To install, you need to have the WordPress i18n library on your computer. Check it out using SVN:

sudo svn co /usr/lib/wpi18n

You don't have to put the library in /usr/lib/wpi18n, but if you don't put it there, make sure to set the $WP_I18N_LIB environment variable in your .bashrc file (with no trailing slash):

export WP_I18N_LIB="/path/to/i18n/lib"

Put anywhere in your path (I put mine in /usr/local/bin) and rename it to makepot. Make it executable by running

chmod +x makepot


To use the script, simply go to the plugin's directory and run


You may specify the plugin directory as an extra argument:

makepot path/to/plugin

The script will use the name of the plugin directory as the .pot file's name and will look first for a directory called languages, then for lang and put the file in whichever it finds. If neither of those directories exists, it will put the .pot file in the base plugin directory.


GPLv2 or Later

Copyright (C) 2012 Avendi Media, Inc.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

if [ ! -z "${WP_I18N_LIB+xxx}" ] || [ ! -d "$WP_I18N_LIB" ]; then
if [ $# -lt 1 ]; then
if [ -d "$pluginDir/languages" ]; then
pluginBasename=$(basename "$pluginDir")
php "$WP_I18N_LIB/makepot.php" wp-plugin $pluginDir "$pluginDir/languages/$pluginBasename.pot"
elif [ -d "$pluginDir/lang" ]; then
pluginBasename=$(basename "$pluginDir")
php "$WP_I18N_LIB/makepot.php" wp-plugin $pluginDir "$pluginDir/lang/$pluginBasename.pot"
php "$WP_I18N_LIB/makepot.php" wp-plugin $pluginDir
Copy link

r-a-y commented Apr 11, 2013

Nice work! I added a second parameter so one can set the textdomain (or filename) for the output:

Copy link

Thank you for this!
I make both themes and plugins so I modified it a bit with inspiration from @r-a-y so I can use the script for both.

makepot wp-theme textdomain path/to/dir

Just made my life a bit more easer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment