Вопрос

I've had for a long time a site with the famous Recent Tweets Widget. The plugin came as part of a theme, and back in the day, it included translation .po and .mo files for French language. I didn't pay attention to this before.

But recently I have found that the strings indicating the tweet's age (x days/months ago, etc.) are translated into Spanish, main language of the site. I have confirmed that the translated strings are not in the .po files, neither from the plugin nor from the site translations. So I assume they come fron an external site. I couldn't tell the exact date when it happened.

Digging about this oddity, I've found that translations can now be managed in http://translations.wordpress.org. And in this site, the aforementioned plugin exists, with 8 translations (a specially bad one for Spanish). My guess is somehow WP could be recovering this translation from the site, via REST API or similar. But I can't find any specific call for this in the code.

I wonder if the __() function has now the ability to recover external translations for a given text domain, or, in the shape of a question: what could be the possible sources for this "ghost" translation? Thanks in advance.

Это было полезно?

Решение

Yes, Recent Tweets Widget is one of the many plugins which their translations are managed through translate.wordpress.org, and this means that upon installing the plugin (*remember, installing and activating are different), WordPress (on your site) will automatically download the plugin's language pack (.po and .mo files) from translate.wordpress.org, and then store the translation files in the WordPress languages directory which defaults to wp-content/languages.

But WordPress will only do that if a core/site language pack is found at wp-content/languages/<locale>.mo (see get_available_languages()), which in your case should be true — e.g. you might find the MO file at wp-content/languages/es_ES.mo.

And for plugins, the downloaded language packs are saved to wp-content/languages/plugins/<locale>.<mo|po>; so for example, the Recent Tweets Widget plugin where the text domain is recent-tweets-widget, you'd find the translations for the Spanish (Spain) locale (es_ES) in:

  • wp-content/languages/plugins/recent-tweets-widget-es_ES.mo
  • wp-content/languages/plugins/recent-tweets-widget-es_ES.po

Also, it should be noted that since WordPress 4.6, language pack found in the wp-content/languages/plugins directory takes precedence over the one in the plugin's directory — which is normally loaded via load_plugin_textdomain() — so with the Recent Tweets Widget plugin as an example, if you had both wp-content/languages/plugins/recent-tweets-widget-es_ES.mo and wp-content/plugins/recent-tweets-widget/languages/recent-tweets-widget-es_ES.mo, the former will be automatically loaded and be used instead of the latter.

Hence, I believe that MO file is the source of that "ghost" translation. :)

(Well if your site's locale is es_ES, but even if not, try looking for one of the other Spanish locales. Then try renaming the file, e.g. <locale>.mo.bak, and see if the "ghost" translation persists.)

Last but not least, when a plugin is deleted (and not simply deactivated), WordPress will also remove the plugin translation files in the wp-content/languages/plugins, so keep that in mind if you wish to edit those files/translations.

Further Reading

Лицензировано под: CC-BY-SA с атрибуция
Не связан с wordpress.stackexchange
scroll top