admin管理员组文章数量:1122832
I'm trying to set up language translations based on the Wordpress language setting. I feel like I've done all the steps outlined in / but my translations are returning the base translation.
I have a /languages
folder with a .pot
file that, among other things contain this:
#: header.php:26
msgid "Skip to content"
msgstr ""
In the same folder there's a .po
file called {text_domain}-{locale}.po
that contains
#: header.php:26
msgid "Skip to content"
msgstr "Skip to content but a different language"
I've opened the .po file with poedit and it's compiled a .mo file inside the same folder
my style.css
file includes:
Text Domain: my-theme
Domain Path: /languages
Inside functions.php
I've added the snippet
function my_theme_load_theme_textdomain() {
load_theme_textdomain(_TEXT_DOMAIN, get_template_directory() . '/languages' );
}
add_action( 'after_setup_theme', 'my_theme_load_theme_textdomain' );
On a product page I'm running
echo get_locale(); // The correct locale string
echo _TEXT_DOMAIN; // The correct text domain
e_('Skip to content', _TEXT_DOMAIN) // The wrong string: "Skip to content"
Can anyone figure out what I'm doing wrong?
I'm trying to set up language translations based on the Wordpress language setting. I feel like I've done all the steps outlined in https://developer.wordpress.org/themes/functionality/internationalization/ but my translations are returning the base translation.
I have a /languages
folder with a .pot
file that, among other things contain this:
#: header.php:26
msgid "Skip to content"
msgstr ""
In the same folder there's a .po
file called {text_domain}-{locale}.po
that contains
#: header.php:26
msgid "Skip to content"
msgstr "Skip to content but a different language"
I've opened the .po file with poedit and it's compiled a .mo file inside the same folder
my style.css
file includes:
Text Domain: my-theme
Domain Path: /languages
Inside functions.php
I've added the snippet
function my_theme_load_theme_textdomain() {
load_theme_textdomain(_TEXT_DOMAIN, get_template_directory() . '/languages' );
}
add_action( 'after_setup_theme', 'my_theme_load_theme_textdomain' );
On a product page I'm running
echo get_locale(); // The correct locale string
echo _TEXT_DOMAIN; // The correct text domain
e_('Skip to content', _TEXT_DOMAIN) // The wrong string: "Skip to content"
Can anyone figure out what I'm doing wrong?
Share Improve this question asked Sep 13, 2024 at 13:55 FluxianFluxian 1809 bronze badges1 Answer
Reset to default 2The issue was that for themes the .mo and .po files needs to be called {locale}.mo or .po
not {textDomain}-{locale}.mo/po
本文标签: phpi18n in Wordpress Theme
版权声明:本文标题:php - i18n in Wordpress Theme 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736292895a1929032.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论