I know that in Drupal 7, contexts are used to provide multiple translations for the different meanings of the same string.

This works great for sentences that do have different meanings depending on the context. But for most of the cases, this means that I'll need to translate the same string twice or more times.

Is there a way to automatically reuse the translations from other contexts, when it's not already translated for the real context of the string?

If not, what is the best way to automatically import all the translations from one context to another?

  • Simply not setting context at all for such strings does not work for you? – Mołot May 23 '13 at 11:14
  • No, because I may need different meanings for them in some of the languages – Pere May 23 '13 at 11:16

The problem is that the set of i18n modules set the context for strings automatically. For instance, suppose I reuse a taxonomy reference field in many content types. The vocabulary name and each of the field labels are exactly the same and have the same set of translations, but each one must be translated entirely independently. That field may also show up as an exposed filter in views and I have to translate it independently in each view as well.

Now suppose I mistranslated the vocabulary name for one of the languages and need to fix it. I have to change it everywhere, which is a ridiculously tedious process.

It would be REALLY nice to be able to translate a particular string such as this once and have it automatically update everywhere that string appears. I have been able to hack it by manipulating the locales_target table in the database directly, but that is definitely not a good solution.


Article on localize.drupal.org says:

Contexts are to be used for places where the string itself is too short to give enough context and could lead to mistranslation, or can have multiple translation in different uses. It is not to be abused wholesale for module strings, but only to be used after consideration.

It means you set the context only when the string itself is ambiguous. If it is, it's your responsibility to provide translations - all of them, because even if now that other translation is acceptable, it may cease to be if original context will call for a slightly different translation. If you have to much, well, it may be what first user of localize.drupal.org calls "abused wholesale" in his article.

API shows clearly - there is an option to set context, or not to. That's all there is.

  • The problem is that the string might be ambiguous for just some languages, but not for all of them. I know I can manually translate them again but I'm talking of a site of more than 10 languages and thousands of strings. For most of these languages, it's likely that the same word could be translated using exactly the same word. But it would be great if it's possible to improve the translations of some languages gradually. – Pere May 23 '13 at 12:35
  • 1
    Well, fill a feature request if you disagree with current Drupal philosophy and find it limitating. Or use strings with more meaning to avoid situations contexts are really needed. – Mołot May 23 '13 at 12:43

Check out translation_fallback module:

This module enables fallback to the default context when a string has no translation in its own context.

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.