Make WordPress Core

Opened 4 months ago

Last modified 4 weeks ago

#42747 new enhancement

i18n: Add specific text domain processing to `makepot` tools

Reported by: JPry Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: trunk
Component: I18N Keywords: has-patch
Focuses: Cc:


In the tools/i18n/ directory of the core repo is a great set of tools. As a plugin developer, two of the most useful tools are the makepot.php and add-textdomain.php files.

As an enhancement, it would be nice if the makepot.php file was able to operate on a specific text domain. This obviously wouldn't be necessary for Core, but for plugins and themes it could be quite useful. In particular, it would be great to have in the following cases:

  • When including default WordPress strings in conjunction with custom strings.
  • When including 3rd-party bundled libraries, such as CMB2.
  • When trying to put together a single translation file that spans multiple plugins and even a theme in a single site (this is certainly an edge case, but I have worked with clients who have this need)

I have a working patch that allows passing a textdomain and processing that domain only.

I opened this ticket as the result of a discussion in Slack.

Attachments (1)

42747.patch (3.0 KB) - added by JPry 4 months ago.

Download all attachments as: .zip

Change History (5)

4 months ago

#1 @JPry
4 months ago

  • Keywords has-patch added

#2 @JPry
4 months ago

With the attached patch, here's an example of extracting strings for the example textdomain:

php makepot-textdomain.php example wp-plugin path/to/plugin/root/ path/to/plugin/root/languages/example.pot

Omitting the path to the .pot file will create the file in the current directory.

Note that this works nearly identically to the current makepot.php file, and that file should continue to function without any issues.

Last edited 4 weeks ago by JPry (previous) (diff)

#3 follow-up: @bobbingwide
4 months ago

I'd just like to point out that I raised https://core.trac.wordpress.org/ticket/41551 to officially support use of null for text domain name parameter.

My solution for shared libraries currently relies on the fact that makepot doesn't actually care what text domain you specify in your source. Shared library files use a text domain of null. I've implemented Just Translate It to merge translations into the null domain.

I hope your patch allows me to continue to extract strings regardless of the text domain.

#4 in reply to: ↑ 3 @JPry
4 months ago

Replying to bobbingwide:

I hope your patch allows me to continue to extract strings regardless of the text domain.

This shouldn't break any current functionality, but I'd be grateful if you'd be willing to test my patch with your current workflow to see if it causes an issue.

Note: See TracTickets for help on using tickets.