0

Gist: When writing an extension of a plugin, can the extension "borrow" the translations of the req'd parent plugin by using it's textdomain?

Scenario: Let's say that there's a parent plugin, whose translation is up to date, and follows WP standards on the matter. I come along, and write an extension plugin.

This extension requires the parent plugin (it will not install without it).

Now lets say that there's a string in my plugin that's translated in the parent plugin. Assuming the strings are absolutely identical (case, alpha, etc), can I borrow the translation of that string, which has already been translated by others, from the parent plugin and use it in my extension by simply using the parent plugin's textdomain? like _e('String', 'parentplugin');

What I'd like to do is for several items that have identical, pretranslated strings in the parent plugin, use the parent plugin's translations for them, to reduce the amount of work required by people translating my plugin.

1
  • 1
    Unfortunately, I do not have the answer, but I imagine you'll eventually just need to bite the bullet and test it out. @kaiser pointed me to a great plugin that toggles translation in a theme that may be helpful with the testing: github.com/wecodemore/wcm_lang_switch
    – tollmanz
    May 20 '13 at 17:31
1

Technically, this is possible. Just make sure to use your strings after the parent plugin has loaded its language file.

In terms of maintainability, this is not optimal. Your create a very strond dependency here: each time the parent plugin changes a string (adding a dot, removing a white space), you have to change your strings too.

I would do this only to save a lot of memory (1 MB or more) and when I knew the developer for the parent plugin creates really useful commits. Otherwise, you might miss some changes.

And Marko points out one important aspect: You need a tool for the pot files, that creates these files based on the text domain, or you wouldn’t save much. Codestyling Localization can do that, but it has other issues. I am not aware of a really good solution here.

Related: Can I leave off plugin textdomain for terms used in core?

0

I sometimes do borrow strings from WordPress and it is fine to do. The biggest problem I see is that the main plugin (WordPress in my case) can change the string and then it isn't translated anymore.

Another problem is that when you generate a pot file that it include all translatable strings. It doesn't look which textdomain it is using. In my case I changed makepot.php to exclude strings with an empty domain.

1
  • Note to my answer is that it only makes sense by doing so when the string is simple and you inherit a lot of strings. In case of Pods framework is all the countries. May 20 '13 at 17:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.