Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to auto-generate POT file from a Wordpress plugin PHP file?

I am working on a Wordpress plugin and noticed that the main PHP file - let's just call it blah.php - contains calls such as:

100: <?php _e('Foo', 'blah'); ?>
101: <?php _e('Bar', 'blah'); ?>
...

It is accompanied by a blah.pot file in languages subfolder, with code such as:

#: blah.php:100
msgid "Foo"
msgstr ""

#: blah.php:101
msgid "Bar"
msgstr ""

Suppose I want to add a new piece of text, in between the above two pieces, in the PHP:

100: <?php _e('Foo', 'blah'); ?>
101: <?php _e('Baz', 'blah'); ?> <!-- New -->
102: <?php _e('Bar', 'blah'); ?>
...

Wouldn't this mean that I would have to re-number blah.pot, like so?

#: blah.php:100
msgid "Foo"
msgstr ""

#: blah.php:101
- msgid "Bar"
+ msgid "Baz"
msgstr ""

+ #: blah.php:102
+ msgid "Bar"
+ msgid "Bar"
+ msgstr ""

What if there are hundreds of such items? Won't this be time-consuming?

Is there a faster way to, say, automatically generate the pot file from the PHP, with correct line numbers?

like image 655
Jonathan Avatar asked Sep 13 '18 19:09

Jonathan


People also ask

What are WordPress pot files?

POT (Portable Object Template) files This file contains the original strings (in English) in your plugin.


1 Answers

Typically POT (Portable Object Template, .pot) files are edited by a gettext catalog editor like Poedit or Easy Po or similar program. The files themselves act as a template of what needs to be translated, and are often generated by the same gettext program by scanning PHP files and looking for gettext functions, or can be generated by another plugin (e.g. WPML will generate these files).

I am not aware of a way to do this in PHP stand-alone. I would suggest trying out a translator program to see which works best for you. I've used Poedit with success in the past. It is free.

Check out the official Localization documentation for additional info about how these gettext files work together to create translations.

like image 86
incredimike Avatar answered Sep 29 '22 14:09

incredimike