verbatim from http://www.firewing1.com/node/27

This problem can be solved by modifying Ubercart's "Product" module. Open sites/all/modules/ubercart/uc_product/uc_product.module in your Drupal installation and search the file for "Add to cart". About halfway down the file, you will come across this line of code in the uc_catalog_buy_it_now_form($form_state, $node) function:

'#value' => variable_get('uc_teaser_add_to_cart_text', t('Add to cart'))),

Essentially, this function says asks to retrieve the variable uc_teaser_add_to_cart_text from the database, but if the variable is not stored in the database then fall back to the localized text of Add to cart. The request for localized text is handled by Drupal's t() function. The problem with the line of code above is that if the variable uc_teaser_add_to_cart_text is stored in the database, which is the case 99% of the time, it cannot be translated as the translation function, t(), only wraps 'Add to cart'. By changing the above line to look like this:

'#value' => t(variable_get('uc_teaser_add_to_cart_text', 'Add to cart')),

The translation function t() wraps the value returned by the variable_get() function, making it translatable. You will now be able to translate the add to cart button using the Administer > Site building > Translate Interface tool

Note that I'm not an expert on i18n and the proper usage ot t(). So the above solution may not be the 'correct' way to fix the issue.

http://api.drupal.org/api/function/t/ describe how to use t() but I'm not sure how to apply what's given there to this case.

CommentFileSizeAuthor
#7 894754-i18n-add-to-cart-button.patch5.39 KBlongwave
#2 Screenshot.png64.08 KBAnonymous (not verified)
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

TR’s picture

http://drupal.org/node/313272 describes how multilingual variables like 'uc_teaser_add_to_cart_text' are handled by Drupal's translation system. IMO Ubercart's usage is correct here. If anything, the t() should probably be removed from the first line so 'Add to cart' doesn't show up in the translation interface. t() should definitely *not* be added like in the second line.

Anonymous’s picture

FileSize
64.08 KB

TR, thanks for looking into this and the link! I had absolutely no idea that there was more than one way to translate a string. I've only ever used the translation interface.

For anyone reading this, the 'Add to cart' text can be changed by following these steps:

1. Go to admin/store/settings/products/edit
2. Switch to the language you want to translate to
3. In the 'Add to cart button text' Panel, edit/translate the fields (they are labeled with 'This is a multilingual variable')

(attached a screen shot)

TR: I wanted to create a test so I went and comment the following in uc_product.module :

function uc_product_init() {
  drupal_add_css(drupal_get_path('module', 'uc_product') .'/uc_product.css');

  global $conf;
  //$conf['i18n_variables'][] = 'uc_product_add_to_cart_text';
  //$conf['i18n_variables'][] = 'uc_teaser_add_to_cart_text';
}

I though this would at the would remove the 'This is a multilingual variable' text from store/settings/products/edit/general but it didn't. Just for my own education, do oyu know why?

stewart.adam’s picture

Status: Active » Closed (works as designed)

I suppose we can mark this one as Closed then.

I'll update my blog post with the correct translation method as well :)

amirtaiar’s picture

Thats was grate!
Thank you...

JGO’s picture

Version: 6.x-2.4 » 7.x-3.x-dev
Status: Closed (works as designed) » Active

Hmm drupal 7 version does not support this :( ?

longwave’s picture

I wonder whether we should remove these "Add to cart" text options and make everyone use locale or string overrides if they want to change this text.

longwave’s picture

Status: Active » Needs review
FileSize
5.39 KB

Patch attached that removes this setting (and another one that is no longer used). We should encourage the use of locale/string overrides to change any text instead of having options for just a few strings.

longwave’s picture

Status: Needs review » Fixed

Committed.

Status: Fixed » Closed (fixed)

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