admin管理员组文章数量:1316307
I used the following code in functions.php
to translate some text:
add_filter('gettext', 'aad_translate_words_array');
add_filter('ngettext', 'aad_translate_words_array');
function aad_translate_words_array( $translated ) {
$words = array(
// 'word to translate' = > 'translation'
'Place Name' => 'Artist Name',
'Add Your Place' => 'Add Your Artist Practice'
);
$translated = str_ireplace( array_keys($words), $words, $translated );
return $translated;
}
This code is not producing any text changes.
Why is this the case? Help appreciated.
I used the following code in functions.php
to translate some text:
add_filter('gettext', 'aad_translate_words_array');
add_filter('ngettext', 'aad_translate_words_array');
function aad_translate_words_array( $translated ) {
$words = array(
// 'word to translate' = > 'translation'
'Place Name' => 'Artist Name',
'Add Your Place' => 'Add Your Artist Practice'
);
$translated = str_ireplace( array_keys($words), $words, $translated );
return $translated;
}
This code is not producing any text changes.
Why is this the case? Help appreciated.
Share Improve this question edited Jun 28, 2017 at 11:03 Steve asked May 11, 2017 at 3:40 SteveSteve 1,75719 gold badges66 silver badges115 bronze badges 5 |2 Answers
Reset to default 8 +25The code you have is correct and will handle the wording even if the case does not match.
Your problem is probably that wherever Place Name
is being output, it is not being passed through a WordPress translation function, __( 'Place Name' )
or _e( 'Place Name' );
Either that, or what you're trying to translate is being dynamically generated ... you gave zero details as to where Place Name
is originating from, and as such, there's nothing we can do besides tell you the code is correct.
If you're not comfortable with using PHP to do this, you should use a plugin like Say What: https://wordpress/plugins/say-what/
Here's a tutorial I put together a while back on changing wording on any WordPress site: https://plugins.smyl.es/docs-kb/how-to-change-button-or-other-text-on-entire-wordpress-site/
as a default, in WP there is the following:
add_action( 'after_setup_theme', your_theme_setup_function() );
inside that setup function there should be the following call:
load_theme_textdomain( your_theme_domain, get_template_directory() . '/languages' );
it appears that the 'after_setup_theme' call makes that functions inside 'functions.php' itself don't recognize the domain.
solved it by moving the call:
load_theme_textdomain( your_theme_domain, get_template_directory() . '/languages' );
to the root of 'functions.php'
本文标签: textstring translation in functionsphp not working
版权声明:本文标题:text - string translation in functions.php not working 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742000371a2410888.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
add_filter('gettext', 'aad_translate_words_array', 20 );
– hwl Commented Jun 28, 2017 at 11:24echo __( 'Place Name' );
or_e( 'Place Name' );
? If you do, it has to work. Tested it. – Frank P. Walentynowicz Commented Jun 28, 2017 at 12:04