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.75k stars 431 forks source link

Translation does not work #763

Open Radzio1615 opened 5 years ago

Radzio1615 commented 5 years ago

Hi! Unfortunately, the translation of the plugin does not work. I use TGM in theme. I put class-tgm-plugin-activation.php, plugins.php and language folder in mytheme/tgm/

My functions.php file:

function mytheme_setup(){
  // Theme translation
  load_theme_textdomain('mytheme', get_template_directory() . '/languages');

  // TGM translation
  load_theme_textdomain('tgmpa', get_template_directory() . '/tgm/languages');

  require_once get_template_directory() . '/tgm/class-tgm-plugin-activation.php';
  require_once get_template_directory() . '/tgm/plugins.php';
}

Translation of the theme works properly. I excluded tgm folder from theme translation. Do i have to change something in tgm php files or add some code to functions.php?

Hector1567XD commented 3 years ago

Hi! I just had the same problem, I don't know much about "textdomains" but it seems in current versions "load_theme_textdomain" loads language files of the form $lang.'.mo' and not of the form $domain.'-'.$lang.'.mo',

This is the way TGM Plugin has put them in its "/languages" folder. It would be enough to remove "tgmpa-" from the names of the language files.

image

In case you have not understood, the idea is to change the name of the file from "tgmpa-it_IT.mo" to "it_IT.mo", this has worked for me within a custom WordPress theme 5.4.4

PD: I know I'm 2 years late ouo..., but I think my answer could help other people

EDIT:

image Well, to say that "it worked" is really a lot, I think the translations need to be updated, but at least it has loaded the .po and .mo files!

erikyo commented 3 years ago

hello sorry if I join this issue after so long, but I suppose this issue can be fixed in this way.

You have to change this line if ( false !== strpos( __FILE__, WP_PLUGIN_DIR ) || false !== strpos( __FILE__, WPMU_PLUGIN_DIR ) ) { so if ( false !== strpos( __FILE__, WP_PLUGIN_DIR ) || false !== strpos( __FILE__, WPMU_PLUGIN_DIR ) || false !== strpos( __FILE__, get_template_directory() ) ) {

So we will check if TGM is placed inside the template folder, otherwise translations aren't loaded.

thank you in advance for your time!