Prepare plugin options for multi-lingual support

WP translation functions, are meant to translate static strings. E.g. Regarding options, you should use them to translate the labels, not values.

However, as far I remember, the translation utility of WPML works in contrast to standard translation, i.e. if you use that than you can’t load the transaltion using from .po/.mo files.

If users want to use that feauture, everyone is free to to what they like on it’s own site, but build a plugin upon that is a thing I really would stay away from.

The get_locale() trick can be used to retrieve an option value, but can’t be used to save it: you can be sure that the function returns the language for the page a site visitor is viewing, but get_locale() in admin pages is assumed to return the locale in which the administrator is navigating the admin pages, not the locale of the option value to be saved.

The workflow you need would be something like that:

  • check if site is multi-language. If not just output a field, optionally saving in the form 'my_plugin_text_' . get_locale(). Where even the unique locale is used to build option name.

  • if the site is multi-language show multiple fields for every option, one for each site language. It means that you have to be able to get all site languages, and there is no standard way to this task: you have to look at various plugin docs (or ask plugin support) and then show appropriate fields that will be saved appending to option name the proper locale.

This is such a pain. Not being universal is just part of the problem, it brings a non trivial coding overhead and easily makes your option pages messy and bloated.

An alternative way might be to use standard WP entities, e.g. posts or taxonomy terms to store informations.

E.g. if the option texts you want to be translate are stored as CPT titles you don’t have to mind about translate them: all translation plugins are able to translate CPT titles, and they will provide a translation UI.

I don’t know if your plugin fits well this workflow, but if so, I think it’s a far better way to solve the problem.