Hey i’m trying to localize a plugin called Donate Plus ( which locallized technicly).
the plugin came with en_CA and de_DE files, i’ve tried creating a he_IL file without success.
So i’ve tried with the de files came with the plugin but didn’t work.
I’ve set the WPLANG in wp-config.php to de_DE yet that dosen’t change the code.
this is the setting code :
load_plugin_textdomain( 'dplus', '/wp-content/plugins/donate-plus' );
And i did check that all the string are set to be localized.
Anyone has a clue?
I just was with a similar isue, did you try to rename your files from de_DE.po and de_DE.mo to name-of-plugin-de_DE.mo and name-of-plugin-de_DE.po (changing name-of-plugin with yours, of course)?
dplus-de_DE.mo and dplus-de_DE.po It must work 😉
load_plugin_textdomain takes three parameters.
In your case it would be something like this (assuming the .po and .mo files are located in a subdir called ‘languages’)
I checked the source of DonatePlus Plugin and I found that the Plugin is doing localization wrongly.
The load_plugin_textdomain() call is made inside the DonatePlus classes constructor. But it should be present inside the ‘init’ hook. Trying adding the following code (which is at the of the file) inside the init function.
Where are all the .po and .mo files stored? Are they inside the /wp-content/plugins/donate-plus folder itself? If not then change the path or move the files.
I had a similar issue where I was loading the translation files with the
load_plugin_textdomain
function from within a service class using PSR-4. This meant that thedirname( plugin_basename( __FILE__ ) )
string returned the wrong path.your-plugin/languages
(assuming you are loading the translation files from the/languages
directory)./var/www/html/wp-content/plugins/my-plugin/languages
won’t work.My plugins file structure looks something like this:
Since my Translation service is placed in the
/services/Base/
directory, this worked for me:Also, I used no action hook at all instead of
init
orplugins_loaded
and fired theload_plugin_textdomain
function at the beginning of the plugin, since the hooks don’t fire early enough for the admin menu and action links to get translated.Use:
load_textdomain( TEXT_DOMAIN , WP_PLUGIN_DIR .’/’.dirname( plugin_basename( FILE ) ) . ‘/languages/’. get_locale() .’.mo’ );