There is a strange behaviour with commerce product label translations.

When I change language, product label translations do not change.

Label translations do show up correctly if I clear cache only, but after few language changes, it get fixated again.

I have 3 languages: EN, LT & RU
1. IF I toggle language between LT <-> EN, everything works O.K.
2. IF I choose RU language, then field translations get fixated and doesn't change no matter which language I choose until I clear cache.
3. After cache is cleared IF I have RU language seleted and I change it to EN, then EN language gets fixated and doesn't change anymore.

I assigned a picture. As you see, it is not related with fields translations, becouse they do work.

I hope there are someone who can help.

Comments

rszrama’s picture

Status: Active » Postponed (maintainer needs more info)

I'm not sure what the issue is here, but one note is that these are defined as extra fields, not Field API fields. The text for these labels is coming from commerce_product_extra_fields() in commerce_product.module, such as:

  foreach (commerce_product_types() as $type => $product_type) {
    $extra['commerce_product'][$type] = array(
      'form' => array(
        'sku' => array(
          'label' => t('Product SKU'),
          'description' => t('Product module SKU form element'),
          'weight' => -10,
        ),
        'title' => array(
          'label' => t('Title'),
          'description' => t('Product module title form element'),
          'weight' => -5,
        ),
    // ...
  }

This means "Product SKU" and "Title" are being translated by the normal translation system as strings passed through t(). I'd expect these to be translated properly without us having to do anything more in commerce_product_reference_entity_view(), but maybe we do. Can you confirm that you've translated these strings for those other languages in the translation interface?

mindaugasd’s picture

StatusFileSize
new37.9 KB

Every SKU I find is translated.

I attached a picture with various examples.

As explained before in more detail, right translations only work if I clear cache for that moment.

mindaugasd’s picture

I wonder why SKU label is displayed as "SKU" and not "Product SKU"? Maybe it is related with this problem.

mindaugasd’s picture

I guess maybe some other module is altering the form, right?

mindaugasd’s picture

Status: Postponed (maintainer needs more info) » Active
mindaugasd’s picture

Status: Active » Closed (fixed)

I solved the issue by not using these extra fields at all (hiding) & supplementing them with standart Field API fields. Though original issue is not solved, I mark this as closed, because nobody have ever reported having the same issue and hopefully it will never reappear.

czigor’s picture

Status: Closed (fixed) » Active

Having the same issue here. There seems to be a random mixup of label translations between languages.

czigor’s picture

In my case this might have been caused by changing the default language of the site after some translations already came to being.

The workaround was to put $label in t() in my own version of commerce-product-title.tpl.php and commerce-product-sku.tpl.php and also editing the locales_source table manually so that the source TItle and SKU be in English as it should.

rszrama’s picture

Category: bug » support
Status: Active » Closed (fixed)

Alrighty, let's leave this closed then unless there's actually a bug here.

guy_schneerson’s picture

Status: Closed (fixed) » Active

Just got the same issue after importing the commerce translations into a site.
Our issue is only with the "SKU" label not the "Product SKU"

Now when i visit a product (product display) page and also on the product (commerce_product) display page admin/commerce/products/types/product-sku-s1/display/node_full the SKU label gets stuck on french "Référence"

The translations are coming from the "Built-in interface" so its should be going through t().

This is not a big issue as the site is in development and we are unlikely to expose the sku to the end user.

I know this may not be sufficient info to identify the problem and will post more details if I get any (will try and debug tomorrow morning).

Opening it for now but happy to close it if I give up on this issue.

guy_schneerson’s picture

test one: What is t() up to:
put some debug code and looks like t() translating the sku as it should always returning the correct translation.
Although it is returning sku for English the product page is showing French.

will do some more digging

guy_schneerson’s picture

Ok i found where the issue is but not why

The function commerce_product_field_extra_fields() is called from the field api function _field_info_collate_fields().

The line that calls the function is: $extra = module_invoke_all('field_extra_fields');
It then puts each of the extra fields through _field_info_prepare_extra_fields()and combines it with the rest of the field info
Finally it gets cached into the cache_field table as 'field_info_fields': cache_set('field_info_fields', $info, 'cache_field');

The problem is that 'field_info_fields' is not language specific.
Looks like after clearing the Drupal caches the _field_info_collate_fields() is called with $reset = TRUE each time you view the node in new language once you finished viewing all languages the function is called without the reset and you get the last language you visited, stored in the cache_field table as 'field_info_fields' until the next clear caches.

I tested this issue with a none commerce entity, the user History set by user_field_extra_fields() but it behaved correctly.

guy_schneerson’s picture

OK looks to me like this is a bug in the field api, written a patch the localizes the cached field_info_field and it fixed this issue.
will do one final test: make sure i can recrate this issue on a clean site and if I can post an issue and core patch

guy_schneerson’s picture

How to create:

OK managed to recreate:

  • Install a clean Kickstart 1
  • Change the display of the product display to show the "product:sku" field
  • Enable the locale module
  • Add french to your languages and import the commerce french translation file
  • now view a product node page and change languages it will get stuck on french

Created a core issue _field_info_collate_fields() is not localized

meanwhile i suppose the solution is to override the relevant template file i.e for sku update commerce-product-sku.tpl.php
change:

<?php print $label; ?>

to

<?php print t('SKU'); ?>
etron770’s picture

Issue summary: View changes

Would be fine to change this in the next update.
Caused me a couple of hours to find the solution of an 4 year old issue.

FYI: I also changed the default language ,as it was requested, during building the website. Not at the beginning.