Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translate pattern metadata (title & description) #40047

Merged
merged 5 commits into from
Apr 6, 2022

Conversation

oandregal
Copy link
Member

@oandregal oandregal commented Apr 5, 2022

Related wp-cli/i18n-command#312

What?

#36751 introduced the ability to automatically register patterns from the /patterns directory of the theme. This PR enables translation for the title & description of the pattern.

Why?

Users expect patterns metadata to be translated.

How?

This PR uses translate_with_gettext_context to pull the strings provided by the theme in the correct user locale before the pattern is registered.

Testing Instructions

1 - Create the pattern

  • Install and activate the TwentyTwentyTwo theme.
  • Add the following pattern under patterns/my-test-heading.php:
<?php
/**
 * Title: My test title
 * Description: My test description
 * Slug: twentytwentytwo/my-test-heading
 * Categories: text
 */

?>
<!-- wp:heading -->
<h2>Hello!</h2>
<!-- /wp:heading -->
<!-- wp:paragraph -->
<p>2 + 2 = <?php echo 2 + 2; ?></p>
<!-- /wp:paragraph -->

2 - Provide a translation

  • Go to "Settings > General" and set the language of your site to "Spanish".
  • Go to "Dashbord > Updates" and make sure you have the translations section updated (it contains the TwentyTwentyTwo strings in Spanish).
  • Unzip the twentytwentytwo-es_ES.mo.zip attached to this PR into wp-content/languages/themes/.
Alternatively, you can create the .mo file yourself for any language, here's how:
  • Go to wp-content/languages/themes/ and paste the following at the end of the twentytwentytwo-es_ES.po file:
#: patterns/my-test-heading.php
msgctxt "Pattern title"
msgid "My test title"
msgstr "Mi título de test"

#: patterns/my-test-heading.php
msgctxt "Pattern description"
msgid "My test description"
msgstr "Mi descripción de test"
  • Run the wp i18n make-mo <path-to-your-po-file> <path-to-the-directory> command to convert the .po file into the .mo one in the same directory.

3 - Do the testing

  • Go to an inserted and search for "test".
  • Verify that the pattern title is translated accordingly to the site language (switch between English and Spanish).

@oandregal oandregal self-assigned this Apr 5, 2022
@oandregal oandregal added Internationalization (i18n) Issues or PRs related to internationalization efforts [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced labels Apr 5, 2022
@oandregal
Copy link
Member Author

@mcsf @youknowriad @swissspidy I've addressed all the feedback and this is now ready.

Copy link
Contributor

@mcsf mcsf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good as far as the original functionality is concerned (thanks for taking care of this!). A separate 👍 on the translation technique would be good.

@oandregal
Copy link
Member Author

Given the time-sensitive period we're in, I'm going to take this comment by Pascal as an "approval for direction" in terms of translation. It's also the same approach we follow to translate strings coming from theme.json (see).

@oandregal oandregal merged commit 10d4367 into trunk Apr 6, 2022
@oandregal oandregal deleted the update/translate-patterns-metadata branch April 6, 2022 07:38
@github-actions github-actions bot added this to the Gutenberg 13.0 milestone Apr 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced Internationalization (i18n) Issues or PRs related to internationalization efforts
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants