Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

i've just built my first plugin for wp, and even if it's not a great "code poetry" ;) it works as it should. It's a plugin that transform the default wp gallery using the GalleryView 3.0 jquery plugin (http://spaceforaname.com/galleryview).

The only thing i'm not able to do is localization. Localization for this plugin in means translating the admin interface, where someone can configure the jquery plugin options to change the aspect of the resulting gallery.

I've tried to follow the millions of tutorials present on the web, read a lot of posts about this issue on forums and followed the guidelinees of codex... but still with no luck.

This is what i've done:

  1. Every text line is inside a gettext function ( __ and _e )
  2. Using poedit i created the .po and .mo file scanning the plugin directory (everythig went ok), then i added translations on that file.
  3. I named the .po file like that NAME-OF-THE-PLUGIN-it_IT.po (the .mo file was generated with the same name)
  4. I've put the translations files inside the plugin folder /languages (name of the folder is the same of the plugin and of the translations files)
  5. Then i've tried to add the load_plugin_textdomain function inside the main plugin file. I've tried because there's no way to get it working.

The only thing on which i'm not sure is the fact that the plugin i've created is not under a class + constructor funcions... just because i'm still not so good in coding.

I've put the load_plugin_textdomain inside an add_action on init, like this:

add_action('init', 'gw_load_translation_file');

function gw_load_translation_file() {
    // relative path to WP_PLUGIN_DIR where the translation files will sit:
    $plugin_path = dirname(plugin_basename( __FILE__ ) .'/languages' );
    load_plugin_textdomain( 'gallery-view-for-wordpress', false, $plugin_path );
}

The lines above are not inside a logic, they are just in the main plugin file, like that.

This is an example of my use of gettext functions:

<h3><?php _e('Panel Options', 'gallery-view-for-wordpress') ?></h3>

What did i not understand?

share|improve this question
1  
What are you expecting to happen, unless you're running your installation in another language/locale you're not going to see anything getting translated. Perhaps my translatable plugin might be of use to you for testing locale changes. –  t31os Mar 23 '11 at 11:43
    
can you describe what's going wrong? Is it just that nothing is being translated? If so, do you have more than one language set up? (It sounds like you might, but it's not clear from the question). If not, are there any errors? Is WP_DEBUG set to true in your wp-config.php? That might help shed light on things. –  Gavin Anderegg Mar 23 '11 at 23:07
    
@t31os I'm obviously running an Italian version of WP. (i've already looked at your nice translatable plugin, but to use it i shoudl actually start again my plugin because I do not use classes) –  bluantinoo Mar 25 '11 at 15:55
    
@Gavin Anderegg my problem is that just my plugin oprions page is not translated. So the problem must be in my plugin. I've tried to set WP_DEBUG to true, but i have no errors related to my scripts. I have just this advice on front end (i'm using basic twentyten template): Notice: register_uninstall_hook was called incorrectly. Only a static class method or function can be used in an uninstall hook. (This message was added in version 3.1.) in D:\[...]\wp-includes\functions.php on line 3422 And a lot of others advices of deprecated funcions in admin, but nothing pointing at my scripts :( –  bluantinoo Mar 25 '11 at 15:56

1 Answer 1

up vote 4 down vote accepted

$plugin_path = dirname( plugin_basename( __FILE__ ) ) . '/languages/';

share|improve this answer
    
adding the last slash does not change: nothing seems to be translated –  bluantinoo Mar 25 '11 at 15:53
    
I'm not just adding the trailing slash. Just replace (copy paste) the line with what I wrote above. –  zeo Mar 25 '11 at 19:04
    
you're right, i've tried... but it does not work :((( –  bluantinoo Mar 26 '11 at 13:19
    
Odd, because that will fix your plugin path. Originally it was wrong. Can you upload your latest work so that I can download. –  zeo Mar 26 '11 at 13:21
    
Why do you comment line 47? add_action('init', 'gw_load_translation_file'); Uncomment it. –  zeo Mar 26 '11 at 16:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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