WordPress Plugin Localization - wordpress

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:
every text line is inside a gettext function ( __ and _e )
using poedit I created the .po and .mo file scanning the plugin directory (everything went ok), then i added translations on that file.
I named the .po file like that NAME-OF-THE-PLUGIN-it_IT.po (the .mo file was generated with the same name)
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)
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?

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

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.

Related

How to make custom Wordpress plugin aware of .po and .mo files?

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.
I'm not sure what else to try so I thought that someone more experienced could point out things I might need to change.
What I did so far:
Added either _e() or __() to the sentences I want to be translated in my plugin files.
Used Loco Translate plugin to generate a .pot file.
Opened .pot file in Poedit, (it displayed a list of all the strings I wanted to translate) translated plugin and generated .po and .mo files from it.
Moved .pot, .po and .mo to my-plugin/languages/.
Renamed files to my-plugin-pt.po and my-plugin-pt.mo.
Changed Wordpress site language to translated language. Language changed everywhere else but the plugin still renders in english.
Not really sure what to do next.
I've created a method that runs load_plugin_textdomain() while following these instructions from Wordpress and have added it as an action to my-plugin __construct():
my-plugin.php
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/' );
}
The language code at the end of the .po and .mo files was incorrect.
Changed from -pt.po to -pt_PT.po (did the same for .mo file) and it started working perfectly.
There's a list of the available language codes for Wordpress which I should have had a look before naming the files in the first place.

Half of the po/mo file strings are working, Wordpress Localization

I'd like to change theme (Flatsome) language on admin control panel site. One of the page UX Builder that i can...but the customizer page (..>appereance>customize)
does not change.
I made the localization:
define('THEME_PATH', get_template_directory());
load_theme_textdomain( 'flatsome', THEME_PATH . '/languages' );
$locale = get_locale();
$locale_file = THEME_PATH . "/languages/$locale.php";
if ( is_readable( $locale_file ) ) require_once( $locale_file );
I've change all the string like I want with __() and _e()
Then I scanned the project, locally (with POedit) and created the POT and PO files.
I did my translation. After finished, I transfered the PO and MO files to FTP. Like I said, half of them has changed. I tried so many things now I think totally stuck.
Yes, I solved the problem. If anyone come across this kind of problem. After WP updated 3.7, the main folder for themes is under wp-content/languages/themes/
And also if you are translating plugin it is wp-content/languages/plugins/
if your theme mo file doesn't work or half of them is working then take your po mo files to these directories, but this time make theme {text-domain}-{locale}.mo and {text-domain}-{locale}.po

Translate plugin and wordpress and the same time

I have seen many questions and answers but none that fit the bill. So here is my issue.
I have a plugin that I have localized which works fine on it's own when you add
define('WPLANG', 'my-plugin-name-de_DE');
to the wp-config file. But then when someone try's to translate the rest of the wp site it will not show the languange.
What am I missing here? I even tried naming the files I added the the wp-content folder to be the same name as my plugin... for example my-plugin-name-de_DE.po and .mo and no luck.
ANSWER
Ok so in wordpress 4.0 you can now select your language from the settings /general page.
My plugin was localized using the code
function plugin_action_init()
{
// Localization
load_plugin_textdomain('my-plugin-name', false, basename( dirname( __FILE__ ) ) . '/languages' );
}
// Add actions
add_action('init', 'plugin_action_init');
Example of a string that would get translated.
_e('Simple text example', 'my-plugin-name');
SO all that needed to be done to get my plugin's and wordpress's translation to work at the same time was to upload the wp language that I want to the wp-content/languages folder. Making sure the file name was simply de_DE.mo and de_DE.po
Such a simple mistake :)

Trouble Translating a WordPress theme

I've created an Arabic website and I am using the zippy theme from MageeWP the things is that I am trying to translate some strings in the theme, but I don't seem to get it working well.
In the theme functions file, there is a specification for the folder location for .PO and .MO files
I created a file ar.mo and put it there, but it still not working, can anybody guide to a clue?
I checked in wp_config.php and indeed the WPLAND is set to ar
I also used the CodeStyling plugin to make the translation, and it didn't work, although the plugin does not problem a .po or .mo files for ONLY ar.
Additionally
the source code of the zippy theme is here: http://themes.svn.wordpress.org/zippy/1.0.9/
Looks like the theme is doing it wrong (simplified code):
define( 'ZIPPY_THEME_BASE_URL', get_template_directory_uri() );
$lang = ZIPPY_THEME_BASE_URL. '/lang';
load_theme_textdomain( 'zippy', $lang );
It's passing an URL and it should be a path, change the load_theme_textdomain line to:
load_theme_textdomain( 'zippy', get_template_directory() . '/lang');
I had a look at the Zippy theme. There are a template called en_US.po inside the lang folder. I had a look at that as well.
If you don't have poedit installed, download poedit now and install it on your computer. Now, make a copy of en_US.po and rename it ar.po. Open ar.po with poedit. Now you can do all your translations in this template. When you're done, just click save in poedit. Poedit will automatically create a ar.mo template when your ar.po is saved.
Note, this is just a quick way of doing it, as there are already a language file available that isn't yet translated.
Hope this helps

Overwrite plugin files?

I want to overwrite the file plugins/the-events-calendar/tickets/meta-box.php of the plugin The Events Calendar.
I followed the tutorial Overwrite Plugin Files but this is not working for me.
How can I overwrite this file?
i want to add new metabox in evetns Ticket section how can i do without edit the plugin file other wise overwrite that plugin files.
I don't have the paid Ticket plugin you refer to, but I took a bit of time to skim through the available GitHub code:
https://github.com/moderntribe/the-events-calendar/
It looks like the overwrite option (i.e. moving a file from the plugin folder to the tribe-events/ folder within your current theme directory) only applies to the views templates in:
https://github.com/moderntribe/the-events-calendar/tree/master/views
You can see for example the definition of the getTemplateHierarchy() function here.
But this overwrite option doesn't apply to the /admin-views/tickets/meta-box.php file, since it's included here with the default PHP include():
include $this->path . 'admin-views/tickets/meta-box.php';
through this method call here:
TribeEventsTicketsPro::instance()->do_meta_box( $post_id );
where the metabox comes from:
add_action( 'add_meta_boxes',
array( 'TribeEventsTicketsMetabox', 'maybe_add_meta_box' ) );
Looking at the source of this file, I found this part:
<?php do_action( 'tribe_events_tickets_metabox_advanced',
get_the_ID(), NULL ); ?>
This might be what you are looking for, if you want to add some extra tickets UI to the event editor. Try to hook into this tribe_events_tickets_metabox_advanced action to add your extra UI.
Hope this help.

Resources