Generally speaking, task runners like Gulp or Grunt are best for generating translation files on a continuous basis, but what if you need to just generate a quick translation file once? You can easily do so with WP-CLI.
Generating POT Translation Files
To generate a POT translation file for your WordPress plugin or theme, you can use this command:
wp i18n make-pot wp-content/plugins/my-plugin-dir
Defining a Destination
By default, WP-CLI will place the resulting POT file into the languages/plugin-name.pot. If you want to place it inside a different location, you can define it as an additional option after the source directory like this:
wp i18n make-pot wp-content/plugins/my-plugin-dir destination/plugin-name.pot
Including Specific Files
What if you want to generate translation strings for only a specific file or set of files? By using the --include option, only those files will be used for generating your POT file.
wp i18n make-pot . --include"only/scan/this/dir,and/this/file.php"
Simple glob patterns can also be used like in the following example:
wp i18n make-pot . --include"included-*.php"
If you want to exclude certain files from being scanned for translation strings, you can provide them by using the --exclude option like this:
wp i18n make-pot . --exclude="ignored-dir,ignored-file.php"
The --exclude option also has the ability to use simple glob patterns like this:
wp i18n make-pot . --exclude="ignored-*.php"
The following files are always excluded, unless otherwise included:
wp i18n make-pot wp-content/plugins/my-plugin-dir --skip-js