1

I'm creating a plugin that must be translatable.

Under plugins/my-plugin/languages I've my .po, .pot and .mo files.

When I translate something in loco plugin I can see translation applied as expected and immediately visible.

Loco plugin directly edit .po files under plugin folder, in this way any update of my plugin leads to the loss of translations manually inserted by user.

I thought (and hoped) that the translations were written in the folder wp-content/languages/loco/plugins/my-plugin. On translate (when I use __("translatedKey", "my-plugin")) the translated value is first read from wp-content/languages/loco/plugins/my-plugin and if missing here fallback to plugins/my-plugin/languages.

In this way any plugin update doesn't overwrite translated keys. Any way to achieve this goal?

1
  • if users help you to translate your plugin, it would be easier that they send you the .PO file and then you put it in the plugin files with a new update.
    – mmm
    Commented Apr 26, 2018 at 17:22

1 Answer 1

1

I thought (and hoped) that the translations were written in the folder wp-content/languages/loco/plugins/my-plugin.

They are, but only when you create the file in that location.

Any users wishing to customize your provided translations should create a new translations file and not edit yours. Opening your provided PO file and starting to edit will not automatically create a custom copy in another location. (it doesn't know whether the person editing is you - the author, or someone else).

If you provide a valid and correctly named POT file, all they have to do is click Add language and select the custom location to create their own version. If you don't provide a POT file, they may wish to follow this guide which explains how to take your provided PO file as a base for their custom translations.

On translate (when I use __("translatedKey", "my-plugin")) the translated value is first read from wp-content/languages/loco/plugins/my-plugin and if missing here fallback to plugins/my-plugin/languages.

This is what happens once the user has two files for the same language.

After creating their own file they will have one in the custom folder (theirs) and one under the plugin folder (yours). Loco Translate's loading helper ensures that their custom translations are used first and falls back on your file for any missing ones.

4
  • Thanks, a little bit not intuitive, but necessary. Works almost perfectly. Only missing thing is that user need, after plugin update, to sync in order to get new keys added.
    – assistbss
    Commented Apr 27, 2018 at 7:28
  • The requirement to sync manually is deliberate because syncing can delete translations. (people don't like that happening automatically). Future development will provide interactive merge and fuzzy matching tools, but this is not the forum to go into that topic.
    – Tim
    Commented Apr 27, 2018 at 9:08
  • If translation files are properly provided, missing keys have no sense to exists because are not used anywhere, but yes, someone could prefer to preserve all translations. Excited to know that those new features are in development.
    – assistbss
    Commented Apr 27, 2018 at 9:34
  • If someone changed the English source from "comment" to "Comment" then the key's "existence" is ambiguous (fuzzy). There are other tools a translator may wish to use on their file instead of a hard sync (such as command line msgmerge). These are the features missing from the plugin currently. Thank you for accepting my answer.
    – Tim
    Commented Apr 27, 2018 at 10:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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