admin管理员组文章数量:1122846
I have been handed an existing WP plugin for translation. I am using the WP __() function, which works fine in all cases, except for the following. (This is the relevant part of the code, of course, not all of it.)
class Co_product_configurator_Public {
private $ins_banister_right;
private $ins_banister_left;
private $ins_none;
public function __construct( $plugin_name, $version ) {
$this->ins_banister_right = __( "Rampe d'escalier à droite", 'co_product_configurator');
$this->ins_banister_left = __( "Rampe d'escalier à gauche", 'co_product_configurator');
$this->ins_none = __( 'Aucun', 'co_product_configurator');
}
public function copc_get_banister_product_by_height( $height = ''){
$select_html .= '<div class="copc_banister_field"><label>'. $this->ins_banister_left .'</label><select name="copc_banister_left">';
$select_html .= '<option value="">'. $this->ins_none .'</option>';
$select_html .= '<div class="copc_banister_field"><label>'. $this->ins_banister_right .'</label><select name="copc_banister_right">';
$select_html .= '<option value="">'. $this->ins_none .'</option>';
}
}
My .po file contains: (line numbers are accurate)
#: public/class-co_product_configurator-public.php:64
msgid "Rampe d'escalier à droite"
msgstr "Trapleuning rechts"
#: public/class-co_product_configurator-public.php:65
msgid "Rampe d'escalier à gauche"
msgstr "Trapleuning links"
#: public/class-co_product_configurator-public.php:66
msgid "Aucun"
msgstr "Geen"
Problem is, the original French strings are showing up, (msgid) not the translated variants (msgstr).
My .po file is functioning, as strings anywhere else in the plugin are correctly translated.
Any help would be appreciated!
I have been handed an existing WP plugin for translation. I am using the WP __() function, which works fine in all cases, except for the following. (This is the relevant part of the code, of course, not all of it.)
class Co_product_configurator_Public {
private $ins_banister_right;
private $ins_banister_left;
private $ins_none;
public function __construct( $plugin_name, $version ) {
$this->ins_banister_right = __( "Rampe d'escalier à droite", 'co_product_configurator');
$this->ins_banister_left = __( "Rampe d'escalier à gauche", 'co_product_configurator');
$this->ins_none = __( 'Aucun', 'co_product_configurator');
}
public function copc_get_banister_product_by_height( $height = ''){
$select_html .= '<div class="copc_banister_field"><label>'. $this->ins_banister_left .'</label><select name="copc_banister_left">';
$select_html .= '<option value="">'. $this->ins_none .'</option>';
$select_html .= '<div class="copc_banister_field"><label>'. $this->ins_banister_right .'</label><select name="copc_banister_right">';
$select_html .= '<option value="">'. $this->ins_none .'</option>';
}
}
My .po file contains: (line numbers are accurate)
#: public/class-co_product_configurator-public.php:64
msgid "Rampe d'escalier à droite"
msgstr "Trapleuning rechts"
#: public/class-co_product_configurator-public.php:65
msgid "Rampe d'escalier à gauche"
msgstr "Trapleuning links"
#: public/class-co_product_configurator-public.php:66
msgid "Aucun"
msgstr "Geen"
Problem is, the original French strings are showing up, (msgid) not the translated variants (msgstr).
My .po file is functioning, as strings anywhere else in the plugin are correctly translated.
Any help would be appreciated!
Share Improve this question edited May 29, 2024 at 17:10 Bart asked May 29, 2024 at 17:07 BartBart 11 bronze badge1 Answer
Reset to default 0I'm still not sure why this problem occured. I'm guessing the class loads before the Wordpress translation functions do.
I ended up circumventing the problem by using functions instead of variables:
function ins_banister_right(): string {
return __( "Rampe d'escalier à droite", 'co_product_configurator');
}
function ins_banister_left(): string {
return __( "Rampe d'escalier à gauche", 'co_product_configurator');
}
function ins_none(): string {
return __( "Aucun", 'co_product_configurator');
}
$select_html .= '<div class="copc_banister_field"><label>'. $this->ins_banister_left() .'</label><select name="copc_banister_left">';
$select_html .= '<option value="">'. $this->ins_none() .'</option>';
More details can be found in this post.
本文标签: translationStrings in class not being translated (All other strings are)
版权声明:本文标题:translation - Strings in class not being translated. (All other strings are.) 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736304989a1932431.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论