Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#43 | interdiff.txt | 720 bytes | thePanz |
#43 | commerce_flat_rate-1480654-43.patch | 14.38 KB | thePanz |
#14 | commerce_flat_rate-1480654-14.patch | 5.78 KB | iKb |
#1 | commerce_flat_rate_i18n.patch | 2.88 KB | Jax |
Comments
Comment #1
Jax CreditAttribution: Jax commentedHere'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.
Comment #2
husumiao-1 CreditAttribution: husumiao-1 commentedThe patch commerce_flat_rate_i18n.patch on #1 is perfect worked. But you need reload the shipping services flat rat page on Chinese version.
Comment #3
thierry.beeckmans CreditAttribution: thierry.beeckmans commentedAfter 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
Comment #4
Daniel KulbeThe #3 worked perfectly. But I would extend it by the description-field:
Hope to see this in beta2 !!!
Comment #5
cspitzlayI 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.
Comment #6
rszrama CreditAttribution: rszrama commentedComment #7
star-szrHere's a revised patch and interdiff.
I'm not sure why the context was added here. Can you explain, @cspitzlay? I've left this for now.
Summary of changes:
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.
Comment #8
cspitzlayI 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.
Comment #9
star-szr@cspitzlay - Thanks.
See http://drupal.org/node/1534468 for more information about why the double encoding is happening. Internationalization's i18n_string() API changed in i18n 1.5.
Comment #10
fagoalso see slightly related #1892264: Allow flat rate services to be exported using Features
Comment #11
radimklaskaPatch in #7 works fine. Thanks!
Comment #12
inventlogic CreditAttribution: inventlogic commentedI 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.
Comment #13
iKb CreditAttribution: iKb commented#7 + fix for Notice: Undefined index: untranslated_strings
Comment #14
iKb CreditAttribution: iKb commentedSorry this one will work
Comment #15
maxplus CreditAttribution: maxplus commentedHi,
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
Comment #16
weri CreditAttribution: weri commentedThanks for the patch #14. This one works for me.
Comment #17
mhotby CreditAttribution: mhotby commentedThanks! This should be updated to dev version.
Comment #18
kaido.toomingas CreditAttribution: kaido.toomingas commented#14 worked for me too.
Comment #19
MURANJO CreditAttribution: MURANJO commentedMany thanks, #14 worked for me too with commerce kickstart.
Comment #20
leonardo.pampalon CreditAttribution: leonardo.pampalon commentedReally thanks, #14 worked fine also for me.
Comment #21
caco13 CreditAttribution: caco13 commentedI applied #14, but now the entries in /admin/commerce/config/shipping are
An express shipping service with additional fee.
An express shipping service with additional fee.
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?
Comment #22
kaido.toomingas CreditAttribution: kaido.toomingas commentedYou should go to admin/config/regional/translate/i18n_string and refresh flat rate textgroup strings.
Comment #23
caco13 CreditAttribution: caco13 commentedThanks 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.
Comment #24
Marko B CreditAttribution: Marko B commentedSeems 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.
Comment #25
sketman CreditAttribution: sketman commentedWorks for me too, can this patch be commited please?
Comment #26
iampuma#14 tested and works. Thanks.
Comment #27
ShaneOnABike CreditAttribution: ShaneOnABike commentedThis works really great! Can we not place this in the latest dev release??
Comment #28
ShaneOnABike CreditAttribution: ShaneOnABike commentedI just updated the attachments to only include the one that officially works right now!
Comment #29
nbourdial CreditAttribution: nbourdial commentedPatch works for me as well. Please let us know when it will be committed and released.
Thanks
Comment #30
gonssalConfirming it works.
Maybe commit and get the module out of beta already?
Comment #31
SanderJP CreditAttribution: SanderJP commentedThe 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)
Comment #32
Aambro CreditAttribution: Aambro as a volunteer commentedThanks for the patch #14. Works for me after upgrading the module to dev version.
Comment #33
Arne Slabbinck CreditAttribution: Arne Slabbinck commented#14 tested and works, thanks!
Comment #34
MURANJO CreditAttribution: MURANJO commented#14 patch worked for me too after editing and saving flat rate services. Then appereared new strings in translate.
Many thanks!!
Comment #35
czigor CreditAttribution: czigor at Liip for FREITAG lab. AG commentedWorks for me too, thanks!
Comment #36
kpatsali CreditAttribution: kpatsali commentedHi 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...
Comment #37
FMB CreditAttribution: FMB commentedkpatsali: there's a page on this topic in the documentation, hope it helps ^^
Comment #38
kpatsali CreditAttribution: kpatsali commentedFMB,
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..
Comment #39
thePanz CreditAttribution: thePanz as a volunteer commentedThe 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.
Comment #40
thePanz CreditAttribution: thePanz as a volunteer commentedAdded 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 Blackfire.io and a reduction of 25% loading time in Checkout pages is shown.
Comment #41
thePanz CreditAttribution: thePanz as a volunteer commentedUpdated patch, added interdiff.
Comment #42
thePanz CreditAttribution: thePanz as a volunteer commentedUpdated patch, fixed unrecognized function.
Comment #43
thePanz CreditAttribution: thePanz as a volunteer commentedUpdated patch
Comment #44
facine CreditAttribution: facine as a volunteer commentedHello, patch 43 works fine!
Thanks!
Comment #45
Anybody+1 for RTBC
Comment #46
czigor CreditAttribution: czigor at Liip for FREITAG lab. AG commentedWe've been using #43 for 3 months now in production without a problem. Can't be more RTBC.
Comment #47
aaronsssp CreditAttribution: aaronsssp commented#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
Comment #48
aumcara CreditAttribution: aumcara commentedGreat 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.
Comment #49
maxplus CreditAttribution: maxplus commented#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.
Thanks!
Comment #50
AnybodyGreat! Confirming RTBC.
@Maintainer: Can we have a new dev and stable release including this patch?
Comment #51
Tavorick CreditAttribution: Tavorick commentedI can also confirm that patch #43 works perfect. A commit to at least the dev version would be very nice.
Comment #52
shi99 CreditAttribution: shi99 commented#43 worked well for me too
Comment #53
smurfxx CreditAttribution: smurfxx commentedWas patch #43 committed to latest dev?
Comment #54
MahmoodZidan CreditAttribution: MahmoodZidan commentedWhat file do I patch exaclty? Sorry I don't know PHP but I don't understand which file to patch.
Comment #55
Pascal- CreditAttribution: Pascal- commented#43 does not apply anymore
seriously dissapointed that this is not commited yet
Comment #56
dotoree CreditAttribution: dotoree commented@MahmoodZidan Please read this guide about appling a patch to a contributed module: https://www.drupal.org/node/620014
Comment #57
MahmoodZidan CreditAttribution: MahmoodZidan commented@dotoree Thanks a lot :) I already patched it, and forgot to update here. Thanks a lot. I am still learning PHP and Drupal so this will be useful.