Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WordPress Plugin Localization

I've just built my first plugin for WordPress, 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 (everything 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 functions... just because I'm still not so good in coding.

But I've put the load_plugin_textdomain inside an init add_action, 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?

like image 253
bluantinoo Avatar asked Mar 23 '11 11:03

bluantinoo


People also ask

How do you localize in WordPress?

Go to your WordPress dashboard, then into Plugins → Add New and enter TranslatePress into the search box. Next, click on Install Now and then on Activate. Go to Settings → TranslatePress and add new languages to your site.


2 Answers

My mistake was on language files path declaration.

this fixed:

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

this was wrong:

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

I was answered on Wordpress Stack Exchange

like image 167
bluantinoo Avatar answered Nov 06 '22 10:11

bluantinoo


Contrary to my previous statement, I've succeeded using this filename: gallery-view-for-wp-it_IT.mo

Strange, though - themes use just it_IT.mo.

like image 44
Nikolay Yordanov Avatar answered Nov 06 '22 08:11

Nikolay Yordanov