WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.58k stars 4.23k forks source link

Pattern localisation doesn't work #42561

Open sebastienserre opened 2 years ago

sebastienserre commented 2 years ago

Description

Hello,

@MarieComet (@chaton666 on wp.org ) has reported a bug on wordpressfr.slack.com (French WordPress community Slack) and first thought if was a Polylang (I'm working at Polylang support) issue. This is why I'm opening this issue.

I've reproduced its issue without any plugin.

I'm attaching a plugin to reproduce the issue and also a video to understand it as English is not my native language.

When you create a pattern using register_block_pattern() the strings, even if they translated and the .po/.mo well loaded (load_plugin_textdomain() is returning true + the plugin is translated in the list of plugin) are not translated when we add the pattern in a post. This should use the user profile language.

Step-by-step reproduction instructions

Screenshots, screen recording, code snippet

https://user-images.githubusercontent.com/3902621/179994259-289c9e5f-2f5b-4505-ba1c-c9e810cbfabd.mp4

1-register-pattern.zip

Environment info

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

Chouby commented 2 years ago

IMHO, the localization of patterns may be even trickier than what it reported by @sebastienserre. When I read the plugin code:

register_block_pattern(
    'wpdocs/my-example',
    array(
        'title'         => __( 'My First Block Pattern', 'textdomain' ),
        'description'   => _x( 'This is my first block pattern', 'Block pattern description', 'textdomain' ),
        'content'       => '<!-- wp:paragraph --><p>'. __( 'My paragraph', 'textdomain' ).'</p><!-- /wp:paragraph -->',
        'categories'    => array( 'text' ),
));

I expect that the title and description should indeed be in the backend language. But the content should be in the site's language. Since WP 4.7 the site's language is not necessarily the backend language of the content writer (typically I write in French and my theme is displayed in French but I keep the WordPress backend in English).

krokodok commented 9 months ago

The same happens with patterns dynamically added from the patterns directory.

alex-borto commented 1 week ago

Glad to find this issue. I believed something wasn't right with our code!

Hope that could be fixed soon as lots of non-English speaking people use WP. 😬