admin管理员组

文章数量:1122832

How to fulfill this requirement for FSE theme "All theme text strings are to be translatable." ?

I am using esc_html_x() to translate string in my patterns

Example

<?php esc_html_x('Download Lexia', 'Sample heading', 'lexiadesign');?>

When outputting this in the Block Editor, the wording Download Lexia doesn't appear.

I checked TwentyTwentyFour theme and it uses esc_html_x as well. The content is outputted when using the pattern in Block Editor. There is no translation file when downloading TwentyTwentyFour theme. Yet the translation works.

What is the right way to translate string in FSE theme ?

How to fulfill this requirement for FSE theme "All theme text strings are to be translatable." ?

I am using esc_html_x() to translate string in my patterns

Example

<?php esc_html_x('Download Lexia', 'Sample heading', 'lexiadesign');?>

When outputting this in the Block Editor, the wording Download Lexia doesn't appear.

I checked TwentyTwentyFour theme and it uses esc_html_x as well. The content is outputted when using the pattern in Block Editor. There is no translation file when downloading TwentyTwentyFour theme. Yet the translation works.

What is the right way to translate string in FSE theme ?

Share Improve this question edited Jul 10, 2024 at 19:33 Stephen Paul Samynathan asked Jul 10, 2024 at 9:35 Stephen Paul SamynathanStephen Paul Samynathan 213 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Could you please cross check lexiadesign is the correct Text Domain of your FSE theme.

Agter this you can use given functions for Internationalization of Strings of your theme or plugin.

  1. esc_html__() : This is used to translate and escape HTML attributes. For Ex. <?php echo esc_html__('Download Lexia', 'your-theme-textdomain'); ?>

  2. esc_html_e() : This is used to translate and echo translated text. For Ex. <?php echo esc_html_x('Download Lexia', 'Sample heading', 'your-theme-textdomain'); ?>

WordPress uses Gettext for translation.

In order to generate translation files (.pot, .po, .mo), we can use tools like Poedit.

These files have the translations of all translatable strings of our theme.

Also you need to load these .po and .mo file by adding the given code to functions.php file of the theme.

function fse_theme_load_textdomain() {
    load_theme_textdomain( 'your-theme-textdomain', get_template_directory() . '/languages' );
}
add_action( 'after_setup_theme', 'fse_theme_load_textdomain' );

Inside language folder we need to keep our language .po .mo files.

本文标签: How to add translation for FSE theme