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?