0

I built a simple localization plugin to suit some specifications needed by my orgnanization. For each language there is a single .mo file that contains both the theme translations as the page content translations. The .mo files are located in myplugin/languages/en_US.mo. I'm trying to use these .mo files for all gettext calls however I cannot get them to work.

Here is the code I'm using to load the text domain:

echo get_locale(); // es_ES
$directory = dirname(plugin_basename(__FILE__)) . '/lang/';
load_plugin_textdomain('localization-v', false, $directory); 
_e("English");
  • Curiously from quick look I don't see why would theme version not work for plugin. Note that unless in your example if run verbatim your echo will run before text domain is really loaded and single underscore is wrong function. – Rarst Mar 10 '14 at 21:38
2

You are completely loading your language file wrong in your plugin, and your file naming is also wrong.

load_theme_textdomain('my_plugin', plugin_dir_path( __FILE__ ) . '/languages');

should be

load_plugin_textdomain('my_plugin', false, dirname(plugin_basename(__FILE__)) . '/lang/');

Also, your mo and po files should be named my_plugin-en_US.mo and my_plugin-en_US.po. Go have a look at this tutorial also, this will help you out a lot.

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.