Skip to content

Instantly share code, notes, and snippets.

@phirebase
Last active January 17, 2025 12:24
Show Gist options
  • Save phirebase/ab9e06cab5df97e2a80efd49f6b49c98 to your computer and use it in GitHub Desktop.
Save phirebase/ab9e06cab5df97e2a80efd49f6b49c98 to your computer and use it in GitHub Desktop.
How to Initialize and Update `/languages` for a WordPress Plugin using WP-CLI

How to Initialize and Update /languages for a WordPress Plugin using WP-CLI

1️⃣ Create a .pot File

Generate the .pot file to include all translatable strings:

wp i18n make-pot . /languages/my-plugin.pot --domain=my-plugin
  • .: Root directory of your plugin.
  • /languages/my-plugin.pot: Destination for the .pot file.
  • --domain=my-plugin: Text domain of your plugin.

2️⃣ Update .pot File

When adding new strings, run the same command to update the .pot file:

wp i18n make-pot . /languages/my-plugin.pot --domain=my-plugin

3️⃣ Structure Example

For a plugin structure like:

my-plugin/
  includes/
  templates/
  languages/

Run:

wp i18n make-pot my-plugin/ my-plugin/languages/my-plugin.pot --domain=my-plugin

Notes

  • Ensure your text domain matches your plugin name.
  • Use translation functions: __(), _e(), _x(), etc.
  • Backup .po and .mo files before updating .pot.

Quick and easy for handling translations!

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