It is currently not possible to translate the title and/or display title of the added flat rate shipping services. Ideally this is done with i18n string since this is dynamic data.


Jax’s picture

Status: Active » Needs review
2.88 KB

Here's a first attempt that works for my current project.

I first tried to integrate this directly in commerce_shipping but that module expects the titles of the services to be translated within hook_commerce_shipping_service_info() since some module use t() to translate their title, eg. the shipping service example module.

This means that each module that uses dynamic strings for titles should implement its own i18n integration.

The patch allows the title and display_title to be translated.

husumiao’s picture

The patch commerce_flat_rate_i18n.patch on #1 is perfect worked. But you need reload the shipping services flat rat page on Chinese version.

thierry.beeckmans’s picture

Category: feature » bug
Priority: Normal » Critical

After applying the patch I had an error, preventing it to use i18n.
A little change to the patch is required, adding a title to the object info

function commerce_flat_rate_i18n_object_info() {
  $info['commerce_flat_rate'] = array(
    'title' => t('Commerce flat rate'),
  return $info;
Daniel Kulbe’s picture

The #3 worked perfectly. But I would extend it by the description-field:

function commerce_flat_rate_i18n_object_info() {
  $info['commerce_flat_rate'] = array(
    'title' => t('Commerce flat rate'),
	'key' => 'name',
    'class' => 'i18n_string_object_wrapper',
    'string translation' => array(
      'textgroup' => 'commerce_flat_rate',
      'type' => 'name',
      'properties' => array(
        'title' => t('Title'),
        'display_title' => t('Display title'),
		'description' => t('Description'),
  return $info;

Hope to see this in beta2 !!!

cspitzlay’s picture

I took the patch from #1 and implemented the following changes on top:

- implement the two suggestions from #3 and #4 to add a title and to make the description translatable
- add a guard so translation only happens if i18n_string is active (I got a fatal error when i18n_string was not there, the existing guard (in the saving function) did not catch the case when the shipping data was *used*)
- add context to display title (disambiguation, there was a translation error on the German version of the edit form)
- implement hook_i18n_string_objects so refreshing of strings will work
(admin/config/regional/translate/i18n_string); before it would just report that the strings could not be refreshed.
- make sure the edit mode only uses the untranslated strings; this is important if you are using the shipping method edit form in a non-default language. Saving the translated values would overwrite your original ones.

rszrama’s picture

Category: bug » feature
Priority: Critical » Normal
Cottser’s picture

Here's a revised patch and interdiff.

+++ b/commerce_flat_rate.i18n.incundefined
@@ -12,7 +13,8 @@ function commerce_flat_rate_i18n_object_info() {
-        'display_title' => t('Display title'),
+        'display_title' => t('Display title', array(), array('context' => 'title for display purposes')),

I'm not sure why the context was added here. Can you explain, @cspitzlay? I've left this for now.

Summary of changes:

  1. Added @file docblock and newline at EOF.
  2. Updated capitalization to "Commerce Flat Rate" where appropriate.
  3. Updated the description of the textgroup to indicate that it now contains description strings.
  4. Cleaned up the call to i18n_string_object_update() in commerce_flat_rate_service_form_submit(). I don't see the need for creating a new object here, and now the string will only get updated if the flat rate service saved successfully. The string update still lags a bit here (same as the patch from #5), it seems like you either need to save the shipping service twice or manually refresh the strings to get the new values. Haven't had a chance to debug that yet.

I'm not quite happy with the whole untranslated_strings bit that fixes the admin UI bug, but I'm not sure how else to implement that unless there's an i18n function we can use to get the untranslated string.

cspitzlay’s picture

I added the context so this string can be translated independently from other uses of that source string.

"Display title" can either mean "to display a title" or "the title to be displayed".
In German, for example, these two would translate to "Titel anzeigen" and "Anzeige-Titel", respectively.
The former is Drupal's standard translation (the German one, at least), the latter meaning is what we need here.

Cottser’s picture

@cspitzlay - Thanks.

See for more information about why the double encoding is happening. Internationalization's i18n_string() API changed in i18n 1.5.

fago’s picture

radimklaska’s picture

Patch in #7 works fine. Thanks!

inventlogic’s picture

Status: Needs review » Reviewed & tested by the community

I have applied the patch in #7 and it appears to do what is required regarding translating the flat rate displayed title.

I think it should be committed.

iKb’s picture

#7 + fix for Notice: Undefined index: untranslated_strings

iKb’s picture

Sorry this one will work

maxplus’s picture


thanks for patch #14, it works for me.

I had to edit and save every shipping method to get the strings available at admin/config/regional/translate/translate

weri’s picture

Thanks for the patch #14. This one works for me.

mhotby’s picture

Thanks! This should be updated to dev version.

kaido24’s picture

Issue summary: View changes

#14 worked for me too.

MURANJO’s picture

Many thanks, #14 worked for me too with commerce kickstart.

leonardo.pampalon’s picture

Really thanks, #14 worked fine also for me.

caco13’s picture

I applied #14, but now the entries in /admin/commerce/config/shipping are

  • Express Shipping (Machine name: express_shipping)
    An express shipping service with additional fee.
  • Express Shipping (Machine name: free_shipping)
    An express shipping service with additional fee.
  • Express Shipping (Machine name: standard_shipping)
    An express shipping service with additional fee.

When you "edit" the options above, the Title, Display title, Description, and Base rate are ok, with correct past values.

I couldn't find the expressions above in /admin/config/regional/translate/translate either.

Should I ran update.php maybe?

kaido24’s picture

You should go to admin/config/regional/translate/i18n_string and refresh flat rate textgroup strings.

caco13’s picture

Thanks kaido24. I think it was a cash issue. Someway the entries now are showed correctly. Probably when I cleared the cash, the problem was solved.

Marko B’s picture

Seems this patch works, had some errors with it until I refreshed cache. Hope this part goes into dev soon as it is very needed on any i18n site.

sketman’s picture

Works for me too, can this patch be commited please?

iampuma’s picture

#14 tested and works. Thanks.

ShaneOnABike’s picture

This works really great! Can we not place this in the latest dev release??

ShaneOnABike’s picture

I just updated the attachments to only include the one that officially works right now!

nbourdial’s picture

Patch works for me as well. Please let us know when it will be committed and released.

gonssal’s picture

Confirming it works.

Maybe commit and get the module out of beta already?

sanderjp’s picture

The only problem I have with #8 is that I have a lot of different shipping methods setup with rules for my country, within EU and outside of EU, that mostly have the same titles. Now that the context is added, I have to translate the same title and description for multiple shipping methods. Meaning if my client wants the title changed, I have to edit all of them, not sure if that is ideal.
Other than that, thanks for the work! (#14 works for me too, after saving all my shipping methods again)

Aambro’s picture

Thanks for the patch #14. Works for me after upgrading the module to dev version.

Arne Slabbinck’s picture

#14 tested and works, thanks!

MURANJO’s picture

#14 patch worked for me too after editing and saving flat rate services. Then appereared new strings in translate.
Many thanks!!

czigor’s picture

Works for me too, thanks!

kpatsali’s picture

Hi to everyone...
I am sorry for the ignorance, but where and how do i have to insert #14 patch in order to translate flat rate?
Thank you in advance...

FMB’s picture

kpatsali: there's a page on this topic in the documentation, hope it helps ^^

kpatsali’s picture

thank you for the replay, but at the end i didn't use this patch at all....
I created two shipping rates, each for every language (title and information)...
Then, i created two different rules, each for every shipping rate and added a condition for the language...
Finally, shipping module shows the title and the information a have committed for each shipping rate and i didn't need to translate them, because they appear depending on the site's interface language.
Thank you anyway..

thePanz’s picture

The patch is introducing a noticeable overhead, mostly related to the i18n_object('commerce_flat_rate', $service)->translate($language->language); invocation.

I will try to provide a patch soon by using cache_get/cache_set mechanisms, in a first try some benefits are noticeable if Redis is used.

thePanz’s picture

Added patch, I extended the previous one with a caching level to reduce the overhead introduced by i18n_string.
I analyzed the two approaches (with and without caching) with and a reduction of 25% loading time in Checkout pages is shown.

thePanz’s picture

14.59 KB
11.37 KB

Updated patch, added interdiff.

thePanz’s picture

Updated patch, fixed unrecognized function.

thePanz’s picture

14.38 KB
720 bytes

Updated patch

facine’s picture

Hello, patch 43 works fine!


Anybody’s picture

+1 for RTBC

czigor’s picture

We've been using #43 for 3 months now in production without a problem. Can't be more RTBC.’s picture

#14 works !!

Sometimes it doesn't work because you didn't triggered the t(''); translate function of Drupal.

Before going to /admin/config/regional/translate/translate
You must enter into the page that contains the sentence you want to translate, here it gonna be (fr/checkout/410/shipping) for example
410 = the number of the order for example

After that you will be able to find the flat rate available for translation into /admin/config/regional/translate/translate

aumcara’s picture

Great job thePanz thanks!

#43 worked for me also !

Shame these little kind of details are not native :-/ I am facing the same situaiton with the Discount module ... no i18 integration native in module either.

maxplus’s picture

#43 is working for me on a production site.
After applying the patch, I edited and saved the flat rate shipping service and then the "Commerce Flat Rate" category appeared in the translate interface where I could successfully translate it.


Anybody’s picture

Great! Confirming RTBC.

@Maintainer: Can we have a new dev and stable release including this patch?

Tavorick’s picture

I can also confirm that patch #43 works perfect. A commit to at least the dev version would be very nice.

shi99’s picture

#43 worked well for me too

smurfxx’s picture

Was patch #43 committed to latest dev?