I'm trying to localize my plugin and with a plugin called CodeStyling Localization, I succeeded to create a .po file. However, the words used in my plugin remain in English although the default language is set to Japanese as defined in wp-configdefine('WPLANG', 'ja');

Other localized plugins are properly translated including, Yet Another Related Posts Plugin and WP Multibyte Patch.

This is a sample plugin I wrote to test plugin localization. I kept it as simple as possible.


    Plugin Name: Localization Sample Plugin
    Version: 1.1
    Author: Teno

// Localization
add_action('init', 'localizationsample_init');
function localizationsample_init() {
    $loaded = load_plugin_textdomain('localizationsample', false, dirname( plugin_basename( __FILE__ ) ) . '/lang/');

// Add Admin Menu 
function localizationsample_menu() { 
        'Localization Sample Plugin',   
        'Localization Sample Plugin',       
function localizationsample_adminpanel() {
    echo '<div class="wrap"><div id="icon-themes" class="icon32"></div>';
    echo '<h2>' . __('hi!', 'localizationsample') . '</h2>';    // "hi!" should be translated.
    echo '</div></div>';


msgid ""
msgstr ""
"Project-Id-Version: Localization Sample Plugin v1.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2012-08-17 20:23+0900\n"
"PO-Revision-Date: 2012-08-17 11:27:39+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Poedit-Language: \n"
"X-Poedit-Country: \n"
"X-Poedit-SourceCharset: UTF-8\n"
"X-Poedit-KeywordsList: __;_e;__ngettext:1,2;_n:1,2;__ngettext_noop:1,2;_n_noop:1,2;_c,_nc:4c,1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2;\n"
"X-Poedit-Basepath: .\n"
"X-Poedit-Bookmarks: \n"
"X-Poedit-SearchPath-0: Z:/xampp/htdocs/wptest/wp-content/plugins/localizationsample\n"
"X-Textdomain-Support: yes"

#: localizationsample.php:28
#@ LSample
msgid "hi!"
msgstr "やあ!"

Both files are saved as UTF-8 without BOM. What am I doing wrong?

*updated the code but the issue still persists.

1 Answer 1


First make sure the language file is found. In your development environment (and only there!) add the following code:

$path   = plugin_dir_path( __FILE__ ) . 'lang';
$loaded = load_plugin_textdomain( 'LSample', false, dirname( $path );

if ( ! $loaded )
    print "File not found: $path"; 

Then … I would use lowercase text domains only. Not sure if that’s a real issue, but there are some cases where WordPress is setting strings to lowercase automatically. Strings not visible to the end user should stay lowercase.

The po file will not be used, you have to create a mo file after translation. Make sure to click the button. :)

enter image description here

Then reload, the strings should be translated now.

  • Okey, I created a .mo file as well but it doesn't translate. I also tried lowercase text domain. It did not help either. Also there was an error in my code: add_action('int', 'localizationsample_init'); had to be corrected to add_action('init', 'localizationsample_init'); Also load_plugin_textdomain() does not return a value so checking if it is loaded with your suggested method does not seem to work.
    – Teno
    Commented Aug 17, 2012 at 23:34
  • Was the correct file found? load_plugin_textdomain() returns a boolean value.
    – fuxia
    Commented Aug 17, 2012 at 23:44
  • load_plugin_textdomain() always seems to return false. According to the documentation of the function, "On failure returns null and also on success returns nothing." Does this mean that if it loads a language file then returns true? "returns nothing" mean returns true, not false?
    – Teno
    Commented Aug 17, 2012 at 23:51
  • Don’t know where you read that. It returns TRUE on success and FALSE on failure. Look at the source. :)
    – fuxia
    Commented Aug 17, 2012 at 23:53
  • Ah, that's for load_textdomain() but the documentation of load_plugin_textdomain() also says "This function does not return a value." codex.wordpress.org/Function_Reference/load_plugin_textdomain
    – Teno
    Commented Aug 17, 2012 at 23:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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