title: How to make custom Wordpress plugin aware of .po and .mo files?
body: <p>I am trying to add a translation to a plugin I wrote from scratch but after experimenting a while I'm not sure how to make Wordpress aware that there's a translation available for my plugin. </p>
  
  <p>I'm not sure what else to try so I thought that someone more experienced could point out things I might need to change.</p>
  
  <p><strong>What I did so far:</strong></p>
  
  <ol>
  <li>Added either <code>_e()</code> or <code>__()</code> to the sentences I want to be translated in my plugin files.</li>
  <li>Used <a href="https://en-gb.wordpress.org/plugins/loco-translate/" rel="nofollow noreferrer">Loco Translate</a> plugin to generate a <code>.pot</code> file.</li>
  <li>Opened <code>.pot</code> file in Poedit, (it displayed a list of all the strings I wanted to translate) translated plugin and generated <code>.po</code> and <code>.mo</code> files from it.</li>
  <li>Moved <code>.pot</code>, <code>.po</code> and <code>.mo</code> to <code>my-plugin/languages/</code>.</li>
  <li>Renamed files to <code>my-plugin-pt.po</code> and <code>my-plugin-pt.mo</code>.</li>
  <li>Changed Wordpress site language to translated language. Language changed everywhere else but the <em>plugin still renders in english.</em></li>
  </ol>
  
  <p><strong>Not really sure what to do next.</strong></p>
  
  <p>I've created a method that runs <code>load_plugin_textdomain()</code> <a href="https://developer.wordpress.org/plugins/internationalization/how-to-internationalize-your-plugin/" rel="nofollow noreferrer">while following these instructions from Wordpress</a> and have added it as an action to <code>my-plugin</code> <code>__construct()</code>:</p>
  
  <p><em>my-plugin.php</em></p>
  
  <pre><code>public function __construct() {
    // Other filters and actions...
    add_action( 'plugins_loaded', array( $this, 'translation_init' ) );
  } // __construct
  
  function translation_init() {
      load_plugin_textdomain( 'my-plugin', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );
  }
  </code></pre>