admin管理员组文章数量:1134239
I have no idea what is wrong here. First I would like to share probably all required info.
Plugin tree:
$ tree
.
├── classes
│ ├── database
│ │ ├── plugin-auth.php
│ │ ├── plugin-user.php
│ │ └── wp-user-x.php
│ ├── main
│ │ └── plugin.php
│ └── woocommerce
│ └── plugin-order.php
├── config.php
├── plugin.php
├── languages
│ ├── plugin-shop-en_US.mo
│ ├── plugin-shop-en_US.po
│ ├── plugin-shop-pl_PL.mo
│ └── plugin-shop-pl_PL.po
└── templates
└── register.php
plugin.php
contains Text Domain: plugin-shop
.po
and .mo
files were generated with Poedit
plugin contains similar code which is executed as first:
class Plugin
{
const TEXT_DOMAIN = 'plugin-shop';
public function initHooks()
{
add_action('plugins_loaded', array($this, 'load_textdomain'));
}
public function load_textdomain() {
load_plugin_textdomain( self::TEXT_DOMAIN, false, basename( dirname( __FILE__ ) ) . '/languages' );
}
...
}
classses/woocommerce/plugin-order.php
contains by example
function order_status_completed()
{
wp_mail( $to, __('Something bought', $this->_textdomain ), $body, $headers );
}
where 'Something bought' were successfully indexed by Poedit
Problem happens when I'm trying to send mail to user on such an action.
add_action( 'woocommerce_order_status_completed', array($this, 'order_status_completed'), 10, 1 );
mail is sent but with english text.
- Locale for WordPress are set to pl_PL - tested by sending in mail
subject
locale()
result. Why is it sending original text? - By the way. I want to send mail with text basing on user locale received by
get_user_locale()
method. How to deal with it?
I have no idea what is wrong here. First I would like to share probably all required info.
Plugin tree:
$ tree
.
├── classes
│ ├── database
│ │ ├── plugin-auth.php
│ │ ├── plugin-user.php
│ │ └── wp-user-x.php
│ ├── main
│ │ └── plugin.php
│ └── woocommerce
│ └── plugin-order.php
├── config.php
├── plugin.php
├── languages
│ ├── plugin-shop-en_US.mo
│ ├── plugin-shop-en_US.po
│ ├── plugin-shop-pl_PL.mo
│ └── plugin-shop-pl_PL.po
└── templates
└── register.php
plugin.php
contains Text Domain: plugin-shop
.po
and .mo
files were generated with Poedit
plugin contains similar code which is executed as first:
class Plugin
{
const TEXT_DOMAIN = 'plugin-shop';
public function initHooks()
{
add_action('plugins_loaded', array($this, 'load_textdomain'));
}
public function load_textdomain() {
load_plugin_textdomain( self::TEXT_DOMAIN, false, basename( dirname( __FILE__ ) ) . '/languages' );
}
...
}
classses/woocommerce/plugin-order.php
contains by example
function order_status_completed()
{
wp_mail( $to, __('Something bought', $this->_textdomain ), $body, $headers );
}
where 'Something bought' were successfully indexed by Poedit
Problem happens when I'm trying to send mail to user on such an action.
add_action( 'woocommerce_order_status_completed', array($this, 'order_status_completed'), 10, 1 );
mail is sent but with english text.
- Locale for WordPress are set to pl_PL - tested by sending in mail
subject
locale()
result. Why is it sending original text? - By the way. I want to send mail with text basing on user locale received by
get_user_locale()
method. How to deal with it?
- Your second question should be a separate one. – cjbj Commented May 9, 2018 at 12:49
1 Answer
Reset to default 1This problem looks a bit too complicated and localized to come up with a definitive answer, but it looks like an execution order issue. Here are some suggestions what you could check:
- You are using a variable in your translation function. Do not do this.
- I'm not sure where that Woocommerce-action is executed, but it might be executed before WP gets to the
load_textdomain
hook. Not very likely, but not impossible either if it tries to send the mail immediately after the plugin is loaded. - Your
add_action
uses the default priority. Higher or lower might help. - Check the global
$wp_filter
variable to see of some plugin is messing with the locales.
本文标签: woocommerce offtopicwordpress plugin translation not working
版权声明:本文标题:woocommerce offtopic - wordpress plugin translation not working 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736795914a1953287.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论