7 replies [Last post]
mypicture_Israel's picture
Offline
Joined: 06/03/2008
Juice: 65
Was this information Helpful?

Hi

As the shop is in Hebrew I would like also the the countries table and the areas will be translated to Hebrew and show it in Hebrew

Where do I translate the values of the countries?

Thank you

http://www.mypicture.co.il
Hosting digital photos and more

Visit our ubercart webshop now
shop.mypicture.co.il

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: Countries tables

Unfortunately, those country names are coming from the database and are therefore untranslatable according to the proper usage of t(). It might be possible for you to patch your install directly, though, and edit the uc_country_select() function in uc_store.module so that the options which represent country names are wrapped in t() even though they aren't string literals. If you have translation rules for them, they should still translate.

<?php
 
// Try changing:
 
$options[$country['country_id']] = $country[$order_by];

 

// To:
 
$options[$country['country_id']] = t($country[$order_by]);
?>
matteoraggi's picture
Offline
Joined: 09/10/2008
Juice: 267
Re: Re: Countries tables

It work great with ubercart 2.0 and 2.2, thanks !

greg.harvey's picture
Offline
Joined: 08/25/2009
Juice: 22
Patch

Created a patch, as per Ryan's suggestion. There's no "easy" alternative to handling this problem, so for UC1 and UC2 I don't think any other approach is sensible, even if this goes slightly against Drupal "convention":
http://drupal.org/node/782960

alexku's picture
Offline
Joined: 10/06/2009
Juice: 50
It can also be done in template.php

Country select translation on shipping and billing panes can also be done in template.php if you prefer with the code below:

/**
* Theme the delivery/billing address forms in tables.
*
* @ingroup themeable
* @see
*   uc_checkout_pane_delivery()
*   uc_checkout_pane_billing()
*/
function THEME_NAME_address_pane($form) {
// fix for country name translation start
if (isset($form['delivery_country'])) {
  foreach ($form['delivery_country']['#options'] as $k => $v)
    $form['delivery_country']['#options'][$k] = t($v);
}
elseif (isset($form['billing_country'])) {
    foreach ($form['billing_country']['#options'] as $k => $v)
      $form['billing_country']['#options'][$k] = t($v);
  }
// fix for country name translation end
  $req = '<span class="form-required">*</span>';

  if (isset($form['copy_address'])) {
    $output = drupal_render($form['copy_address']);
  }

  $output .= '<div class="address-pane-table"><table>';

  foreach (element_children($form) as $field) {
    if (substr($field, 0, 9) == 'delivery_' || substr($field, 0, 8) == 'billing_') {
      $title = $form[$field]['#title'] .':';
      unset($form[$field]['#title']);
      if (substr($field, -7) == 'street1') {
        $title = uc_get_field_name('street') .':';
      }
      elseif (substr($field, -7) == 'street2') {
        $title = ' ';
      }
      $output .= '<tr><td class="field-label">';
      if ($form[$field]['#required']) {
        $output .= $req;
      }
      $output .= $title .'</td><td>'. drupal_render($form[$field]) .'</td></tr>';
    }
  }
  $output .= '</table></div>';

  foreach (element_children($form) as $element) {
    $output .= drupal_render($form[$element]);
  }

  return $output;
}

greg.harvey's picture
Offline
Joined: 08/25/2009
Juice: 22
Um

That might work but it's a fair chunk of code to stick in template.php for the simple lack of a t() function call in the main module. It would be far better to bump the patch in the comment above on Drupal.org and get it committed!

jesus_cherrytel's picture
Offline
Joined: 04/06/2011
Juice: 4
unbelievable

I was checking to see how to deal with names, and now I see about these workarounds, I can't believe something as simple as adding the t() function usage has not been already placed in ubercart code.

Shocked

Again I say: unbelievable.

greg.harvey's picture
Offline
Joined: 08/25/2009
Juice: 22
There is a fix

To be fair, the problem here is not straightforward at all. There are problems with simply wrapping country names in the t() function, because they are *not* strings in the code (the intended use for that function) and you can get all sorts of issues emerging.

GOOD NEWS - there is a fix awaiting testing on Drupal.org: http://drupal.org/node/782960#comment-4286192

This is finally a proper fix for this long-running issue. (Higher up in the thread is also an explanation of why this is not a simple fix.) Please review the patch there and help get it committed so this problem goes away. =)