0

I'm gonna deploy my first plugin but the _e() and __() functions seem don't work.

In my comments header:

Text Domain: add-to-post-footer
Domain Path: /languages

I created .po and .mo files with poedit and put them in /languages in my plugin. I translated to portuguese and named as 'pt_BR.po/mo'. In my option page I have some texts as follows:

<?php echo __( 'With ', 'add-to-post-footer').ATPF_PLUGIN_NAME.__(' you can add some content at the final of all your posts without care about forget some of them, or the need to copy and paste boring proccess. Just go to Posts >> ', 'add-to-post-footer').ATPF_PLUGIN_NAME.__(', insert the content and save it. The proccess is the same to change the content. You just have to care about other stuff of your site/blog now', 'add-to-post-footer'); ?>

But when I put in my localhost wordpress installation, language brazilian portuguese, nothing happens (just the save button, because Save is already translated by default on WP)

What am I doing wrong?

2

You have to load text domain in your plugin:

<?php
function my_load_textdomain() {
    load_plugin_textdomain( 
        'add-to-post-footer', // text domain identifier
        false, // deprecated parameter
        plugin_basename(dirname( __FILE__ )) . '/languages' ); // path to the languages directory
}

add_action('plugins_loaded', 'my_load_textdomain');
  • Something is going wrong: define('ATPF_LANGUAGES_PATH',plugin_basename(dirname( __FILE__ )) . '/languages'); and my code just change from your by this constant and I put the function in the functions file. Not working. – Enrique René Mar 26 '16 at 20:05
  • You should copy the code to your plugin file, not theme's functions.php. – Max Yudin Mar 26 '16 at 21:55
  • Yes, I did it. I'm at Street now. When home I send my whole code – Enrique René Mar 26 '16 at 22:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.