Generate and update translation files (.pot) for WordPress i18n. Use before creating PRs to ensure all translatable strings are captured. Required workflow before any PR submission.
WHY: If you don't regenerate the .pot file before a PR:
# From plugin root directory
wp i18n make-pot . languages/contact-form-to-api.pot --domain=contact-form-to-api
# Include specific headers
wp i18n make-pot . languages/contact-form-to-api.pot \
--domain=contact-form-to-api \
--package-name="CF7 to API" \
--headers='{"Report-Msgid-Bugs-To":"https://github.com/SilverAssist/contact-form-to-api/issues"}'
# Exclude vendor and node_modules (usually automatic)
wp i18n make-pot . languages/contact-form-to-api.pot \
--domain=contact-form-to-api \
--exclude=vendor,node_modules,.git
Before creating any PR, run these commands:
# 1. Regenerate .pot file
wp i18n make-pot . languages/contact-form-to-api.pot --domain=contact-form-to-api
# 2. Check if .pot was modified
git status languages/
# 3. If modified, commit the changes
git add languages/contact-form-to-api.pot
git commit -m "chore: update translation template"
Always use the literal string 'contact-form-to-api':
// β
CORRECT - Literal string (extractable)
__('Text here', 'contact-form-to-api');
// β WRONG - Variable (NOT extractable)
__('Text here', $text_domain);
__('Text here', CONSTANT);
// Basic translation
__('Text', 'contact-form-to-api');
_e('Text', 'contact-form-to-api');
// With escaping (preferred for output)
esc_html__('Text', 'contact-form-to-api');
esc_html_e('Text', 'contact-form-to-api');
esc_attr__('Text', 'contact-form-to-api');
esc_attr_e('Text', 'contact-form-to-api');
// Plurals
_n('One item', '%d items', $count, 'contact-form-to-api');
_n_noop('One item', '%d items', 'contact-form-to-api');
// Context for ambiguous strings
_x('Post', 'noun', 'contact-form-to-api');
_x('Post', 'verb', 'contact-form-to-api');
// β
CORRECT - Translator comment explains placeholders
sprintf(
/* translators: %1$s: form name, %2$d: submission count */
__('Form "%1$s" has %2$d submissions', 'contact-form-to-api'),
$form_name,
$count
);
// β WRONG - No translator comment
sprintf(__('Form "%1$s" has %2$d submissions', 'contact-form-to-api'), $form_name, $count);
languages/
βββ contact-form-to-api.pot # Template (source of truth)
βββ contact-form-to-api-es_ES.po # Spanish translation
βββ contact-form-to-api-es_ES.mo # Compiled Spanish
βββ README.md # Translation guide
# Install WP-CLI globally (macOS)
brew install wp-cli
# Or download directly
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
Add this to your PR preparation routine:
./scripts/run-quality-checks.sh)wp i18n make-pot ...)