Skip to content

Commit

Permalink
Use translate_with_gettext_context rather than translate
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo committed Jan 14, 2021
1 parent 7f3762c commit b35353a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/wp-includes/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ function register_block_type_from_metadata( $file_or_folder, $args = array() ) {
switch ( $key ) {
case 'title':
case 'description':
// phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText,WordPress.WP.I18n.NonSingularStringLiteralDomain
$settings[ $mapped_key ] = translate( $value, $textdomain );
// phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText,WordPress.WP.I18n.NonSingularStringLiteralContext,WordPress.WP.I18n.NonSingularStringLiteralDomain
$settings[ $mapped_key ] = translate_with_gettext_context( $value, sprintf( 'block %s', $key ), $textdomain );
break;
case 'keywords':
$settings[ $mapped_key ] = array();
Expand All @@ -259,7 +259,7 @@ function register_block_type_from_metadata( $file_or_folder, $args = array() ) {

foreach ( $value as $keyword ) {
// phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText,WordPress.WP.I18n.NonSingularStringLiteralDomain
$settings[ $mapped_key ][] = translate( $keyword, $textdomain );
$settings[ $mapped_key ][] = translate_with_gettext_context( $keyword, 'block keyword', $textdomain );
}

break;
Expand All @@ -272,7 +272,7 @@ function register_block_type_from_metadata( $file_or_folder, $args = array() ) {
foreach ( $value as $style ) {
if ( ! empty( $style['label'] ) ) {
// phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText,WordPress.WP.I18n.NonSingularStringLiteralDomain
$style['label'] = translate( $style['label'], $textdomain );
$style['label'] = translate_with_gettext_context( $style['label'], 'block style label', $textdomain );
}
$settings[ $mapped_key ][] = $style;
}
Expand Down
Binary file modified tests/phpunit/data/languages/plugins/notice-pl_PL.mo
Binary file not shown.
8 changes: 7 additions & 1 deletion tests/phpunit/data/languages/plugins/notice-pl_PL.po
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: 2015-12-31 16:31+0100\n"
"PO-Revision-Date: 2021-01-14 17:44+0100\n"
"PO-Revision-Date: 2021-01-14 18:26+0100\n"
"Language: pl_PL\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
Expand All @@ -18,20 +18,26 @@ msgstr ""
"Language-Team: \n"
"X-Poedit-SearchPath-0: .\n"

msgctxt "block title"
msgid "Notice"
msgstr "Powiadomienie"

msgctxt "block description"
msgid "Shows warning, error or success notices…"
msgstr "Wyświetla ostrzeżenie, błąd lub powiadomienie o sukcesie…"

msgctxt "block keyword"
msgid "alert"
msgstr "ostrzeżenie"

msgctxt "block keyword"
msgid "message"
msgstr "wiadomość"

msgctxt "block style label"
msgid "Default"
msgstr "Domyślny"

msgctxt "block style label"
msgid "Other"
msgstr "Inny"
2 changes: 1 addition & 1 deletion tests/phpunit/tests/blocks/register.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ function test_block_registers_with_metadata_fixture() {
}

/**
* @ticket 000
* @ticket 52301
*/
function test_block_registers_with_metadata_i18n_support() {
function filter_set_locale_to_polish() {
Expand Down

0 comments on commit b35353a

Please sign in to comment.