Skip to content

Instantly share code, notes, and snippets.

@UVLabs
Last active July 16, 2024 04:58
Show Gist options
  • Save UVLabs/acd63b7ffe01d677f58c7bbb73a48ed3 to your computer and use it in GitHub Desktop.
Save UVLabs/acd63b7ffe01d677f58c7bbb73a48ed3 to your computer and use it in GitHub Desktop.
Using WordPress makepot.php to generate pot file used for the internationalization of your plugin or theme.
#!/bin/bash
php path/to/makepot.php wp-plugin /path/to/your/plugin pluginname.pot
#php path/to/makepot.php wp-theme /path/to/your/theme themename.pot

All the tutorials online seem to be missing something. I was able to put them together. The following requires you being able to use wget and php commands inside your terminal. You can use svn in place of wget.

Step 1:

Download the i18n files from: http://i18n.svn.wordpress.org/tools/trunk/

You can do this using wget by running the following command in your terminal:

wget -r -np -R "index.html*" http://i18n.svn.wordpress.org/tools/trunk/

Step 2:

Download the WordPress development trunk: http://develop.svn.wordpress.org/trunk/

Again you can do this using wget by running the following command in your terminal:

wget -r -np -R "index.html*" http://develop.svn.wordpress.org/trunk/

Step 3:

Navigate the contents of the development trunk folder which you downloaded in Step 2 and copy the pomo folder located in trunk/src/wp-includes/ and paste it inside the i18n folder which you downloaded in Step 1, located in /tools/i18n

At the end your i18n folder should have both the makepot.php file as well as the pomo folder and the other files that were already present inside the i18n folder.

Step 4:

Now you just need to run the command so that your pot file can be generated.

If you want to generate a plugin pot file, run(while inside i18n folder):

php makepot.php wp-plugin /path/to/your/plugin pluginname.pot

If you want to generate a theme pot file, run(while inside i18n folder):

php makepot.php wp-theme /path/to/your/theme themename.pot

You can go further by creating a bash script to always run the command and move the i18n folder out of your working directory.

Note: After running command you might get the message sh: 1: msguniq: not found inside your terminal. That just means it worked :)

@jviseur
Copy link

jviseur commented Jul 15, 2024

Thank you for providing this information.
I originally downloaded the i18n files from: http://i18n.svn.wordpress.org/tools/trunk/ which incidentally included the pomo folder and when run generated the error message

Warning: PO::export_entry(): Argument #1 ($entry) must be passed by reference, value given in F:\xampp\htdocs\ptv\wp-content\themes\tools\pomo\po.php on line 52

When I then deleted the pomo directory and replaced it with the one in trunk/src/wp-includes/ and the errors went away (except for the one you mentioned).

How ever for some reason it did not include any text in the Settings fields and also it ignored any text output to the dashboard that was in html code. Is there anyway those can be included and if so how do I do that?

Regards

@UVLabs
Copy link
Author

UVLabs commented Jul 15, 2024

Thank you for providing this information. I originally downloaded the i18n files from: http://i18n.svn.wordpress.org/tools/trunk/ which incidentally included the pomo folder and when run generated the error message

Warning: PO::export_entry(): Argument #1 ($entry) must be passed by reference, value given in F:\xampp\htdocs\ptv\wp-content\themes\tools\pomo\po.php on line 52

When I then deleted the pomo directory and replaced it with the one in trunk/src/wp-includes/ and the errors went away (except for the one you mentioned).

How ever for some reason it did not include any text in the Settings fields and also it ignored any text output to the dashboard that was in html code. Is there anyway those can be included and if so how do I do that?

Regards

I actually haven't used this script in years...I currently just use Loco Translate plugin: https://wordpress.org/plugins/loco-translate/ to generate the .pot file for me when I change or add strings

@jviseur
Copy link

jviseur commented Jul 16, 2024 via email

@jviseur
Copy link

jviseur commented Jul 16, 2024 via email

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