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 badges1 Answer
Reset to default 0Could 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.
esc_html__()
: This is used to translate and escape HTML attributes. For Ex.<?php echo esc_html__('Download Lexia', 'your-theme-textdomain'); ?>
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
版权声明:本文标题:How to add translation for FSE theme? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736301087a1931055.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论