7 replies [Last post]
totsubo's picture
Offline
Joined: 11/12/2009
Juice: 163
Was this information Helpful?

On the Checkout page, in delivery information (address), I'm not getting the text field names translated properly. Things like 'First name', stay in English even when I switch languages.

My understanding is that the field names are generated by:

uc_get_field_name() in uc_store.module and the translation occurs in that function.

I've test this out by changing the following:

function uc_get_field_name($field) {
$fields = array(
'first_name' => t('First name'),

to

function uc_get_field_name($field) {
$fields = array(
'first_name' => t('Test name'),

(This worked as expected and the field name change from 'First name'to 'Test name'.)

I've checked my .po file and there is an entry for 'First name' so I don't understand why it is not being used .... (I'v also checked the admin page and it'snot being used there either)

#: uc_store.admin.inc:233 uc_store.module:708;1177
msgid "First name"
msgstr "名"

Help!

Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6846
Re: Problem with uc_get_field_name() and translatation of addres

It's probably reading the field name out of the database instead of the module code at this point. Fortunately, Ubercart can tell i18n to use different database values for each language. Go to admin/store/settings/checkout/edit/fields on your site in English, and you should see all English values. Switch languages and the labels should change, but the values in the form fields will probably stay the same. At this point, put in the translations and submit the form. Now the checkout page should show the translations for the address field labels.

There are many settings that are multilingual like this in Ubercart. If you see any others that won't switch languages (or just disappear entirely!), go find their settings page and submit the correct value for each language on your site.

bendev's picture
Offline
Joined: 07/11/2010
Juice: 29
Re: Re: Problem with uc_get_field_name() and translatation of ad

"At this point, put in the translations and submit the form. Now the checkout page should show the translations for the address field labels."

I did this and I noticed the labels changed, then I put a translation but it overrided it for all languages. Any idea how I can solve it ?

liuggio's picture
Offline
Joined: 06/08/2011
Juice: 4
lj

Hi i solved in the quitck and really dirty way.
as lyle suggest go to admin/store/settings/checkout/edit/fields.
then write those fields in english.

then go to ubercart/translation/uc_cart_checkout_pane.inc
and add the translation function "t()" to all of the uc_get_field_name

for example
from

if (uc_address_field_enabled('first_name')) {
$contents['billing_first_name'] = uc_textfield(uc_get_field_name('first_name'), $arg1->billing_first_name, uc_address_field_required('first_name'));
}
to
if (uc_address_field_enabled('first_name')) {
$contents['billing_first_name'] = uc_textfield(t(uc_get_field_name('first_name')), $arg1->billing_first_name, uc_address_field_required('first_name'));
}

ps
drupal is a messy and to many non developer worked on it.

totsubo's picture
Offline
Joined: 11/12/2009
Juice: 163
Re: Problem with uc_get_field_name() and translatation of addres

The problem was that the .po file was not being used. The Japanese translation .po file was incorrectly locate in a ubercart/translation/general.ja.po file instead of the correct location which is ubercart/module/translation/moduleName.ja.po

Nothing wrong with the code. Though as Lyle points out Ubercart doesn't play well or act properly sometimes when it comes to i18n unfortunately ...

Looking forward to Drupal Commerce!

Numael's picture
Offline
Joined: 03/11/2011
Juice: 10
Hi, This is not an i18n

Hi,

This is not an i18n problem. Ubercart don't store multiple value for name field.

function uc_get_field_name($field) {

$fields = array(
'first_name' => t('First name'),
[...]
);

$default = $fields[$field];

[...]

return variable_get('uc_field_'. $field, $default);
}

Ubercart translate default field title but can't store field name for all languages.

TR
TR's picture
Offline
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3424
Re: Hi, This is not an i18n

No Numael, you're wrong. As Totsubo said, in this case there's "Nothing wrong with the code." Ubercart properly declares all the field names as i18n variables:

  $conf['i18n_variables'][] = 'uc_store_name';
  $conf['i18n_variables'][] = 'uc_field_first_name';
  $conf['i18n_variables'][] = 'uc_field_last_name';
  $conf['i18n_variables'][] = 'uc_field_email';
  $conf['i18n_variables'][] = 'uc_field_phone';
  $conf['i18n_variables'][] = 'uc_field_company';
  $conf['i18n_variables'][] = 'uc_field_address';
  $conf['i18n_variables'][] = 'uc_field_street';
  $conf['i18n_variables'][] = 'uc_field_street1';
  $conf['i18n_variables'][] = 'uc_field_street2';
  $conf['i18n_variables'][] = 'uc_field_city';
  $conf['i18n_variables'][] = 'uc_field_zone';
  $conf['i18n_variables'][] = 'uc_field_postal_code';
  $conf['i18n_variables'][] = 'uc_field_country';

The big problem Ubercart has with internationalization is that *Drupal* doesn't have a mechanism for translating user-defined data. This doesn't cause problems for simple things like blogs or anything else in Drupal core; it only becomes apparent with complex modules like Ubercart.

<tr>.
kla2t's picture
Offline
Joined: 08/09/2011
Juice: 3
Re: Problem with uc_get_field_name() and translatation of addres

The problem is still there in Ubercart 3, and actually it seems to be an Ubercart, not a core issue.
I'm using version 7.x-3.x-dev, and I fixed the issue by simply changing line 394 in uc_store.module from

'#title' => uc_get_field_name($base_field),

to

'#title' => t(uc_get_field_name($base_field)),

It works like a charm for me and does not throw any errors!