Can the Drupal t () function localize English homonyms?

In Drupal, the lines shown to the user must be passed through the t () function as follows:

$heading = "<h2>" . t("Product") . "</h2>"; 

This allows Drupal to translate the string into the appropriate language.

However, what if the same English word is used in two different senses on the same site? If I wrote a price calculation module that included the Product option, indicating that discounts should be multiplied together, how could the localization process know if the word should be translated as an item to be bought or an arithmetic operation?

Should homonyms be avoided at all?

+4
source share
2 answers

Very nice question (+1). I believe that in 2006 there was one discussion on one of the Drupal mailing lists. Key developers have fiercely defended the current i18n and l10n infrastructure designs. The problem of homonyms for the Indo-European languages ​​is limited, but when you move, for example, to China, it becomes overwhelming, since each ideogram in Chinese represents a bunch of completely different concepts, and you can get the intended one only by looking at the context.

Although there is no coded solution for homonyms, there is a very simple best practice: provide context! If possible, provide the t () function with sentences, not separate words, or say this with the code documentation in common.inc :

When using t (), try putting whole sentences and strings in one call to t (). This makes it easier for translators, as it provides a context for what each word refers to.

If this is not possible, and using synonyms with a different spelling is not an option , you can embed transparent HTML tags that provide context for the translation . For instance:

 $heading = "<h2>" . t("<span id="product-as-in-stores">Product</span>") . "</h2>"; 

This way you provide important information to translators, and if you just nested the <h2> tags, the translator would have to guess what the product belongs to.

This is BTW - one of the few cases where embedding HTML tags in t () strings is not considered bad.

NTN!

+5
source

The simplest is to use a different term for one of the cases. Thesaurus is your friend here. What about the β€œresult” for the multiplication case?

The truth is that the t() function and other similar functions in other languages, such as _() in GNU C internationalization (I forgot the exact name lib), was not well designed for words, but phrases such as messages in dialog the windows. Maybe if you included the <h2>...</h2> tags in the translated string to fix these problems?

+1
source

All Articles