wp-cli / i18n-command

Provides internationalization tools for WordPress projects.
MIT License
96 stars 52 forks source link

Extract pattern metadata (title & description) #312

Closed oandregal closed 2 years ago

oandregal commented 2 years ago

In https://github.com/WordPress/gutenberg/pull/36751 Gutenberg added the ability to automatically register patterns that live in the /patterns directory. These patterns provide metadata via headers in the PHP file as in:

<?php
/**
 * Title: My heading
 * Description: My pattern description.
 * Slug: my-theme/my-heading
 * Categories: text
 */

From the existing metadata, we need the Title to be translatable. This PR adds support for looking up those patterns and extracting the Title string into the pot file.

How to test

style.css with at least these contents:

/*
Theme Name: foo theme
*/

patterns/my-pattern.php with at least these contents:

<?php

/**
 * Title: My pattern title.
 * Description: My pattern description.
 */
composer install
vendor/bin/wp i18n make-pot foo-theme
# some other file header metadata

#. Theme Name of the theme
msgid "foo theme"
msgstr ""

#: patterns/my-pattern.php
msgctxt "Pattern title"
msgid "My pattern title."
msgstr ""

#: patterns/my-pattern.php
msgctxt "Pattern description"
msgid "My pattern description."
msgstr ""
swissspidy commented 2 years ago

From the existing metadata, we need the Title to be translatable

For this to be actually useful, Gutenberg should also actually translate the title. I don't see any $pattern_data['title'] = translate_with_gettext_context( $pattern_data['title'], 'Title of the pattern' ); call in https://github.com/WordPress/gutenberg/pull/36751

oandregal commented 2 years ago

For this to be actually useful, Gutenberg should also actually translate the title. I don't see any $pattern_data['title'] = translate_with_gettext_context( $pattern_data['title'], 'Title of the pattern' );

Yeah, I need to follow-up with that as well :)

oandregal commented 2 years ago

I've prepared the Gutenberg PR that uses this data at https://github.com/WordPress/gutenberg/pull/40047 but I'm having some trouble to get the translated strings.

swissspidy commented 2 years ago

Pending some tests this looks good to go! 👍

oandregal commented 2 years ago

Pending some tests this looks good to go! +1

Tests would need to wait until tomorrow morning :)

oandregal commented 2 years ago

@swissspidy pushed the test.