I am more or less copying #952002: Add translation string contexts to Drupal 8. But since that issue was fixed and reopened I did not want to hijack it.
The issue is that certain words such as 'order' can have two meanings, which in most language will be translated into different words.
For example a commerce order would in Dutch be 'bestelling', whereas a sorting order would translate into 'volgorde'. The problem is that once I import Dutch translations into Drupal, the order entities all list as the wrong translation 'volgorde'.
Drupal 7 and 8 both have the principle of translation context, allowing additional context to be provided for translations. Could we please implement this, so the translated user interfaces start to make sense again? :)
Annotation based translations can be adapted like this:
/**
* Defines the order entity class.
*
* @ContentEntityType(
* id = "commerce_order",
* label = @Translation("Order", context = "a drupal commerce order"),
* label_collection = @Translation("Orders", context = "a drupal commerce order"),
* label_singular = @Translation("order", context = "a drupal commerce order"),
* label_plural = @Translation("orders", context = "a drupal commerce order"),
* label_count = @PluralTranslation(
* singular = "@count order",
* plural = "@count orders",
* context = "a drupal commerce order",
* ),
*
* ...
*/
See https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Annotation!Transl...
t() and $this->t() need to provide context in the 3rd parameter like this:
t('Order number', [], ['context' => 'a drupal commerce order']);
See https://www.drupal.org/docs/7/api/localization-api/string-context (Documentation for D7, but logic still applies).
The reason I am not yet proposing a patch is that I am not entirely sure about the different situations. It should definitely be done for the single word 'order', but as soon as the sentence contains references to products, etc. the ambiguity is already gone and providing of context is of lesser importance (and might break existing translations?).
Words like 'cart' are debatable and commerce appears to be using 'cart' and 'shopping cart' interchangeable. Though I doubt there will ever be a Drupal module that provides mining carts or any other kind of cart for that matter. 'Promotions' could be a job promotion, and there might be more.
Perhaps we should first inventory all words with multiple meanings and bundle them into one patch?
Or could this become something like an incremental issue where patches are provided as words are encountered?
As Bojanz suggested, this can be done word by word.
Ambiguous words
Words that should have context.
- Order (purchasing products / sorting)
- Store (physical store / store something)
- Promotion (discount action / job promotion)
Debatable words
Words that might need context.
- Cart (shopping cart / any other kind of cart)
Comment | File | Size | Author |
---|---|---|---|
#14 | 2890081-14-translation_contexts_for_commerce.patch | 10.34 KB | Neograph734 |
| |||
#10 | 2890081.patch | 1.23 KB | eiriksm |
|
Comments
Comment #2
Neograph734Comment #3
bojanz CreditAttribution: bojanz at Centarro commentedI suggest limiting scope and tackling one word at a time (fixing "order" first, for example)
Comment #4
Neograph734Thanks. Next week I should have some time to look into some of these words. In the meantime the description can be adapted to list the words.
Comment #5
Neograph734This should do it for the word 'order'. I chose to re-use the existing 'a drupal commerce order' context that is already in use for commerce 1.x.
Comment #6
Neograph734This one should cover the word 'store'.
Comment #7
Neograph734And for promotions.
Comment #8
Neograph734@bojanz, I just noticed that this is still an issue (at least for Dutch localization), where 'order' is still getting translated in a sorting context. Since I suppose most of the regular strings have been translated by now (adding context might break them??), what about adding contexts to entity definitions only?
Something like this:
Comment #9
markdcAdd "Complete" to the list of ambiguous words. The checkout process uses this for the last step. In German, "complete" can be translated several ways. But the default string that Drupal uses translates back to English as "entire" with the sense of wholeness and perfection, rather than a process that is finished.
Comment #10
eiriksmWe have this problem in Norwegian as well.
I suggest we do the context part in smaller iterations to limit the scope (like bojanz and Neograph734 suggested). Renamed this issue to reflect a suggestion for initial scope, and here is a patch.
I will open follow ups for the other parts suggested here if people think that is an OK way forward
Comment #11
andypostComment #12
NiklanIn Russian "Order" is also an ambiguous word with different translations.
With the recent update of the translations, the part of the interface where "Order" is mentioned from the entity has become "Order" in the context of "sorting something". This is confusing a lot.
The problem occurs (as I found currently) only with "Order" word, not with plural variations.
P.s. My two cents into context naming. I think it must be just "commerce", not "a drupal commerce order". There can be other contrib modules which also can use "commerce" context without any relations with drupal commerce. At least in Russian "Order" is having only two meanings and one of them strongly related to "commerce".
Comment #13
Neograph734I believe "a drupal commerce order" was already an existing context on localize.drupal.org; so it made sense to re-use it. Then again commerce does perhaps make more sense.
Comment #14
Neograph734Let's give this another try. I felt that the patch of eiriksm did not suffice because
@Translation("Order")
is used in several other files as well, which could cause unexpected differences.Attached patch adds the context "Commerce" (as advised by Niklan) to all of the below occurrences, found by searching for
@Translation("[Order|Store|Promotion]
:Let's get this RTBC, then move forward with individual string translations (if needed, because most of them will have context from surrounding words.) :)
Comment #15
bojanz CreditAttribution: bojanz at Centarro commentedDo we need this part? The title doesn't seem ambiguous (and is quite long).
The rest looks good to me.
Comment #16
Neograph734I included it because I was not sure. I believe it could also be used for something like a backend store (such as a database?) But I agree that the chance is low that it will be used like that.. But I am also not sure if adding context breaks existing translations (the old one probably does not apply anymore). So in that case it might be better to leave it out.
Comment #17
bojanz CreditAttribution: bojanz at Centarro commentedOkay, let's proceed without that part then. Tweaking title.
Comment #19
bojanz CreditAttribution: bojanz at Centarro commentedCommitted. Thanks!