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)
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Neograph734 created an issue. See original summary.

Neograph734’s picture

Issue summary: View changes
bojanz’s picture

I suggest limiting scope and tackling one word at a time (fixing "order" first, for example)

Neograph734’s picture

Issue summary: View changes

Thanks. 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.

Neograph734’s picture

Issue summary: View changes
Status: Active » Needs review
FileSize
11.69 KB

This 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.

Neograph734’s picture

This one should cover the word 'store'.

Neograph734’s picture

Neograph734’s picture

@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:

  * @ContentEntityType(
  *   id = "commerce_order",
- *   label = @Translation("Order"),
- *   label_collection = @Translation("Orders"),
- *   label_singular = @Translation("order"),
- *   label_plural = @Translation("orders"),
+ *   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"),
markdc’s picture

Add "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.

eiriksm’s picture

Title: Add contexts for string translations » Add translation context for order entity label
FileSize
1.23 KB

We 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

andypost’s picture

Niklan’s picture

In 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".

Neograph734’s picture

I 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.

Neograph734’s picture

Let'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]:

  • @Translation("Order")
  • @Translation("Order type")
  • @Translation("Store")
  • @Translation("Store type")
  • @Translation("Promotion")
  • @Translation("Store ID from the current store")

Let's get this RTBC, then move forward with individual string translations (if needed, because most of them will have context from surrounding words.) :)

bojanz’s picture

diff --git a/modules/store/src/Plugin/views/argument_default/CurrentStore.php b/modules/store/src/Plugin/views/argument_default/CurrentStore.php
index 9712d9b0..7e316771 100644
--- a/modules/store/src/Plugin/views/argument_default/CurrentStore.php
+++ b/modules/store/src/Plugin/views/argument_default/CurrentStore.php
@@ -16,7 +16,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
  *
  * @ViewsArgumentDefault(
  *   id = "active_store",
- *   title = @Translation("Store ID from the current store")
+ *   title = @Translation("Store ID from the current store", context = "Commerce")
  * )
  */
 class CurrentStore extends ArgumentDefaultPluginBase implements CacheableDependencyInterface {

Do we need this part? The title doesn't seem ambiguous (and is quite long).

The rest looks good to me.

Neograph734’s picture

I 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.

bojanz’s picture

Title: Add translation context for order entity label » Add translation context for order/promotion/store

Okay, let's proceed without that part then. Tweaking title.

  • bojanz committed 5be7ee4 on 8.x-2.x authored by Neograph734
    Issue #2890081 by Neograph734, eiriksm, Niklan: Add translation context...
bojanz’s picture

Status: Needs review » Fixed

Committed. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.