19 replies [Last post]
Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15422

So, I'm working on developing a site for a French client. This means I'll be running into many of the same roadblocks others have experienced when setting up international and multilingual Ubercart sites. As I do this, I'm trying to think forward to see how to implement translatable strings in such a way that they're good for everyone.

One of the major problems with the way Ubercart functions pertaining to multilingual usage is the fact that we have a lot of settings for customizable messages and customizable form element titles/values. For example, someone can rename the "Add to cart" button through a settings form. This is fine for a single language site, but once that value has been set on a multilingual site, you lose the ability to translate it more than one ways.

That led me to think of this over lunch...

What if for customizable messages and element we came up with some specific identifier for the field and always generated the text for it by "translating" that identifier through t(). For example, the add to cart button text would always be printed out using t('!add_to_cart_button_value'). We can then pass a replacement value that either uses the default t('Add to cart') or the customizable message if it's been configured in the settings form. This means that even if you configure the text (totally fine for a single language site), you could still translate it differently for other languages by translating '!add_to_cart_button_value' to whatever you wanted for that specific language, like 'Add to bag.'

I think the code would look something like this:

<?php
if (variable_get('add_to_cart_button_value', t('Add to cart')) == t('Add to cart')) {
 
$default = t('Add to cart');
}
else {
 
$default = variable_get('add_to_cart_button_value', '');
}

$form['add_to_cart'] = array(
 
'#type' => 'submit',
 
'#value' => t('!add_to_cart_button_value', array('!add_to_cart_button_value' => $default)),
);
?>

Thoughts? Does this really solve anything? Am I overlooking something? Obviously, I'd come up with a helper API function that we could use instead of always having to determine the default like that, so this is purely concept that needs your refinement. Cool

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15422
Re: Multi-lingual customizable form element titles and messages

moritzz on Twitter pointed me to this document page on d.o instructing users how to setup multilingual variables using the i18n module. Looks promising!

Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6841
Re: Re: Multi-lingual customizable form element titles and messa

Ooh, i18n_variables looks like what we needed. I bet if we put something like the following code in all of our hook_install()s, we'd be all set.

<?php
$i18n_variables
= variable_get('i18n_variables', array());
$uc_cart_variables = array(
 
'uc_cart_help_text',
 
'uc_cart_new_account_details',
);
variable_set('i18n_variables', $i18n_variables + $uc_cart_variables);
?>

At that point, the only problem is people accidentally overwriting i18n_variables in their settings.php files.

TR
TR's picture
Online
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3369
Re: Re: Multi-lingual customizable form element titles and messa

Hey Ryan, did you forget you wrote a FAQ with that link in it? http://www.ubercart.org/faq/8123

<tr>.
Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15422
Re: Re: Re: Multi-lingual customizable form element titles and m

lol - how about that. Guess I did. Sticking out tongue

I suppose my goal here would be to figure out a way that didn't depend on config file hackery. However, Lyle's point about hook_install() might mitigate the need for that, too. Glad I posted for feedback before doing anything with this. Smiling

TR
TR's picture
Online
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3369
Re: Re: Re: Re: Multi-lingual customizable form element titles a

Lyle, maybe put it in hook_init() instead of hook_install() ? Yes, then it will execute on every non-cached page, but so does settings.php, which is where i18n recommends putting these variables.

<tr>.
asak@drupal.org's picture
Offline
Joined: 10/23/2008
Juice: 67
Yep

That sounds right to me.

Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6841
Re: Re: Re: Re: Re: Multi-lingual customizable form element titl

Yeah, hook_init() does make more sense. And, also, not using variable_set(), which writes data to the database, even though it's hard-coded. Here's a patch that takes care of all of the core Ubercart variables that I could find. Actually filling them all out for several languages looks like a long, boring process, though. That'll make it hard to make sure everything has been covered.

AttachmentSize
i18n_variables.patch 7.27 KB
asak@drupal.org's picture
Offline
Joined: 10/23/2008
Juice: 67
And

Just for reference, there's much more work which needs to be done for a truly multilingual shop:
http://www.ubercart.org/forum/internationalization/10878/i18n_issues_i_d...

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15422
Re: Re: Re: Re: Re: Re: Multi-lingual customizable form element

Looks like you got the uc_credit_fail_message in there twice and left out the checkout message variables.

Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6841
Re: Re: Re: Re: Re: Re: Re: Multi-lingual customizable form elem

Looks like I missed the uc_stock module as well.

AttachmentSize
i18n_variables.patch 9.28 KB
Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6841
Re: Re: Re: Re: Re: Re: Re: Re: Multi-lingual customizable form

And now with the address field titles, which I believe more people have asked about translating than anything else. Sticking out tongue

Also, the tabledrag on the attributes' forms didn't need to be in this patch either.

AttachmentSize
i18n_variables.patch 8.12 KB
Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6841
Re: Re: Re: Re: Re: Re: Re: Re: Re: Multi-lingual customizable f

OK, I think this is most of them, and it works, so I'm committing it. If anyone finds any more variables that we need to make translatable, post an issue somewhere.

Sorry. False alarm. There's a bug in i18n that means that you don't see the default values for these variables before they're set. I'll commit it for real once this patch gets committed.

tomrenner's picture
Offline
Joined: 01/20/2009
Juice: 21
Re: Re: Re: Re: Re: Re: Re: Re: Re: Re: Multi-lingual customizab

Very interested in the further progress of this topic, too! Regards from Vienna!

Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6841
Re: Re: Re: Re: Re: Re: Re: Re: Re: Re: Re: Multi-lingual custom

Hmm. Now I'm not sure what to do. i18n has been patched, but I don't know if I should commit this patch to Ubercart before the new version of i18n comes out. If we put out a release candidate, then most people wouldn't know to get the dev version of i18n, and they could potentially see that a lot of the strings are missing. But I also don't want to hold up a new release if they don't make a release soon.

Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6841
Re: Re: Re: Re: Re: Re: Re: Re: Re: Re: Re: Re: Multi-lingual cu

OK, I got tired of waiting, so I committed the patch. I guess we should start telling people to get the dev version of i18n, at least until the 1.2 version comes out. We can also point them to the specific issue: http://drupal.org/node/527534.

totsubo's picture
Offline
Joined: 11/12/2009
Juice: 158
Re: Re: Re: Re: Re: Re: Re: Re: Re: Re: Re: Re: Re: Multi-lingua

Is this patch in the current version, if not which version will it be available for?

I've just posted to the support forum with a similar issue:

http://www.ubercart.org/forum/support/14998/problem_uc_get_field_name_an...

Basically I've put translations for the address field names into a .po file but they are not getting picked up by uc_get_field_name(). My site is bilingual and so using the Ubercart module's form for a one-off change of the address field name's is not good enough.

Any help appreciated!

mrfelton's picture
Offline
Joined: 10/03/2008
Juice: 31
Re: Multi-lingual customizable form element titles and messages

What about the names of product attributes? These also need to be translatable.

Tom Kirkpatrick - kirkdesigns.co.uk

tomrenner's picture
Offline
Joined: 01/20/2009
Juice: 21
Re: Multi-lingual customizable form element titles and messages

Kentucky going international! Hey Ryan! Somehow I felt like that was to come ever since I heard about yor french project. Really appreciate your thoughts! The direction seems correct. Trying to go through the prob again over the weekend. Remind me to invite you for another inspiring lunch next time we meet!
Cheers, Thomas

koyama's picture
Offline
Joined: 08/12/2009
Juice: 36
Re: Multi-lingual customizable form element titles and messages

It seems there are caveats with the i18n_variables approach.

When one adds a new site language, even using complete .po files, the result is that some strings do not get translated, namely those strings that are stored as variables such as 'uc_checkout_review_instructions'.

This is a problem when creating multi-language Ubercart sites since one will have to manually type translations in the various forms for all strings stored as variables. I.e. one cannot take full advantage of .po files provided by the community.

1) Is this something you are aware of?

2) Is it really necessary that Ubercart provides settings for customizable messages and customizable form element titles/values. Can this not already be achieved with e.g. "String overrides" module?

P.S. Ubercart is great!