0

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 ?

New contributor
Stephen Paul Samynathan is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

1 Answer 1

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.