• halleluuja

    (@halleluuja)


    Hello,

    I have some problems with translating my plugin because the __() function does not seem to work as it should.

    Here is an example (radically simplifyed version of my plugin’s class):

    class MyClass
    	{
    	var my_var;
    
    	function MyClass()
    		{
    		add_action('init', array($this, 'plugin_lang_init'));
    		add_shortcode('plugin_output', array($this, 'html_output'));
    
    		// Here will also be separated strings concated together
    		// e.q. __('first_str').'<br />'.__('another_str') and so on.
    		$this->my_var = __('My first string', 'my_plugin');
    		}
    
    	function plugin_lang_init()
    		{
    		load_plugin_textdomain('my_plugin', false, dirname(plugin_basename(__FILE__)).'/languages/');
    		}
    
    	function html_output()
    		{
    		$output = ''
    			.'<div>'.$this->my_var.'</div>' // translation DOES NOT work
    			.'<div>'.__('My second string', 'my_plugin').'</div>'; // translation works perfectly
    
    		return $output;
    		}
    	}

    As shown above: if the __() is stored inside the class property, translation does not occur.

    Any ideas why this isn’t working? And what would be the alternatives?

    Thank you.

  • The topic ‘__() does not seem to work’ is closed to new replies.