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 430 forks source link

Wrongly named languages included with custom download? #611

Open tomslominski opened 8 years ago

tomslominski commented 8 years ago

Hi. I've recently downloaded the latest version of TGMPA (2.6.1) from the custom downloader on your site and included it with my theme (distributed outside of WP/ThemeForest). I'm a bit confused about how the newly supplied language files work. I read through the instructions and the text domain loading code, and it seems to me that these are named wrongly.

Here's what WordPress tries to load for your plugin (debugged using the Display text domains plugin):

/Applications/MAMP/htdocs/wordpress-generic/wp-content/themes/theme-name/inc/plugins/languages/de_DE.mo (FILE NOT FOUND)
/Applications/MAMP/htdocs/wordpress-generic/wp-content/languages/themes/tgmpa-de_DE.mo (FILE NOT FOUND)

Since I am including TGMPA with a plugin (inside the theme-name/inc/plugins/ directory), the file should be found in the first directory. However, since the files supplied in the TGMPA package are named tgmpa-de_DE.mo, not de_DE.mo as load_theme_textdomain() (invoked here) expects, the language file isn't found, and the translation doesn't work.

I see that there is some attempt made to correct the filename using correct_plugin_mofile(), but this works only for plugins.

Am I misunderstanding something here, or is this genuinely a bug?

Anyway, thanks for a great plugin!

d79 commented 8 years ago

I think the tgmpa- prefix should be removed from the .mo file names, because the Internationalization paragraph of the Theme Handbook says:

You can load the MO file by calling the function load_theme_textdomain(). This call loads {locale}.mo from your theme’s base directory or {text-domain}-{locale}.mo from the WordPress theme language folder.

I did it on my theme and now the MO file is corretly loaded.

GaryJones commented 8 years ago

TGMPA is also used in plugins as well though.

RichardCoffee commented 7 years ago

Here is a suggestion that would load the correct mo file no matter where TGMPA is used, and remove the need for the custom generator to change the text domain strings.

I suspect that implementing this would require other changes of which I am unaware, which is why I am offering it here rather than as a PR. It is just that it seems to me that simplifying the code is a good direction to go in.

jrfnl commented 7 years ago

remove the need for the custom generator to change the text domain strings.

@RichardCoffee Unfortunately the Theme Review Team at WordPress.org demands that the text domain is changed as well as some other things. The text-domain change has to do with being able to (re-)use translations offered by their own theme/plugin translation platform GlotPress. The Custom Generator was created as too many theme authors apparently know so little of PHP that they were doing blanket search & replace actions, breaking TGMPA and giving it a bad reputation. So independently of the changes you suggest - which are similar to #601 -, the Custom Generator will still need to be used for themes.

For full info on what the Custom Generator does, see the original PR for it: https://github.com/TGMPA/TGM-Plugin-Activation/pull/519