TGMPA / TGM-Plugin-Activation

TGM Plugin Activation is a PHP library that allows you to easily require or recommend plugins for your WordPress themes (and plugins). It allows your users to install, update and even automatically activate plugins in singular or bulk fashion using native WordPress classes, functions and interfaces. You can reference bundled plugins, plugins from the WordPress Plugin Repository or even plugins hosted elsewhere on the internet.
http://tgmpluginactivation.com/
GNU General Public License v2.0
1.76k stars 431 forks source link

Only translates "Dismiss this notice" #692

Open MatteoN81 opened 7 years ago

MatteoN81 commented 7 years ago

Hi, I have a problem with setting the language. I put the language file in the theme / plugin, renamed tgma-it_IT in it_IT, and in the message that appears to tell me to install X plugin, only translates "Dismiss this notice". The rest remains in English.

I've tried everything, but I do not understand why.

MatteoN81 commented 7 years ago

The problem depends on the load_textdomain() function in the TGMPA class, which does not load the language file correctly. In this point

https://github.com/TGMPA/TGM-Plugin-Activation/blob/90957570c2c6e883bffb36b66359e7c9900f5814/class-tgm-plugin-activation.php#L481

are compared constants FILE and WPMU_PLUGIN_DIR to see if TGMPA is integrated into a plugin or a theme. The path to FILE (Ex: C: \ xampp \ htdocs \ wordpress \ wp-content \ plugins \ my-plugin \ class-tgm-plugin-activation.php) has slash / or backslash \ depending on the operating system running the server, instead WPMU_PLUGIN_DIR (Es. C:\xampp\htdocs\wordpress/wp-content/plugins) has a part with always slashes /. This depends on wordpress, which when declaring paths, takes the initial part from dirname (FILE), while the rest adds it using always the slash (Ex. Define ('WP_PLUGIN_DIR', WP_CONTENT_DIR. '/ Plugins');). This is not a big problem, since Windows, even if it uses backslashes \ in the paths, recognizes the slash / separator, but in comparisons between paths it will always return false, as in my case that I have a local server on Windows as a test environment, this is because they are different text strings, as one uses the slash / and the other backslah. To solve this problem, just replace the if with:

if ( false !== strpos( __FILE__, str_replace('/', DIRECTORY_SEPARATOR, WP_PLUGIN_DIR) ) || false !== strpos( __FILE__, str_replace('/', DIRECTORY_SEPARATOR, WPMU_PLUGIN_DIR) ) ) {

This will replace the slah / with the base separator of your system.

franzarmas commented 6 years ago

I have exactly the same problem.

It also runs the plugin in a local environment in Windows.