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.
Hello,
I'm trying to translate the "Order total" string at the footer of the cart view on the checkout page, and for some strange reason I can't translate it/or the translation is not working.
I have translated a string "Order total" but it seems to have no effect there, it does change the label of the component in the view edit page, but that doesn't really help me.
Any ideas? this is the only string that I can't translate - where is the code originating? maybe there's a missing t() ?
Idan
Comment | File | Size | Author |
---|---|---|---|
#108 | commerce.jpg | 42.28 KB | tahiticlic |
#107 | multilingual settings strings.png | 102.19 KB | Argus |
#92 | 1121722-91.instance-translation-dx.patch | 10.71 KB | bojanz |
#64 | 1121722-64-instance-field-translation.patch | 6.01 KB | rszrama |
#52 | field-translate-1121722-52.patch | 1.14 KB | helior |
Comments
Comment #1
svendecabooterI'm having the same problem...
I traced it back to the following code in commerce_price.module (around line 344):
The
$instance['label']
variable contains the original label instead of the translated oneThis must have something to do with the field formatter, but can't quite figure out the flow at the moment...
Comment #2
arbel CreditAttribution: arbel commentedgreat find! Thanks.
I wrapped a t() around it:
'title' => t(check_plain($instance['label'])),
and it worked right away with a previous translation.
Idan
Comment #3
svendecabooterNot sure if that's best practice though. This should probably work with a placeholder or something...
Comment #4
rszrama CreditAttribution: rszrama commentedHmm, it seems $instance['label'] should have been originally wrapped in t()... must be a missing link in the price component API somwhere. :?
Comment #5
v.zhakov CreditAttribution: v.zhakov commentedI have a same problem. Subscribe.
Comment #6
akamaus CreditAttribution: akamaus commentedI post a patch wrapping $instance in t() for ease of referencing from drush makefiles.
Comment #7
n9352527 CreditAttribution: n9352527 commentedThe commerce_order_total price field instance was created by calling the commerce_price_create_instance() function in commerce order module. The instance label passed to this field creation function was wrapped in t(). This means that the translation was performed when the field instance was created using the default language at that time and saved as the field instance label. Once the field was created, it is not possible to change the translation anymore.
I think the translation should be done during formatting instead of on field instance creation. This would allow translation to language that hasn't been added when the field instance was created and allow multi languages translations. Of course, the field instance label would then be saved as the default string instead of the translated string.
Comment #8
rszrama CreditAttribution: rszrama commentedYeah, n9353537 nails the problem. The issue is that this is the way fields are supposed to work, and you aren't supposed to wrap variables in t(). I'm not quite sure what the best thing for us to do would be... on the one hand, it might make sense to just employ a t() hack (i.e. use akamus' patch), but on the other it might be better to recommend a field translation module if a sufficient one exists.
Comment #9
n9352527 CreditAttribution: n9352527 commentedWell, the API documentation page on t() says
So, I guess it is okay to wrap the instance label with t()?
Comment #10
Damien Tournoud CreditAttribution: Damien Tournoud commentedWe removed the automatic translation of field instance label between Drupal 7.0 and 7.2. Now we need to figure out how to best integrate into the i10n module.
Comment #11
khiminrm CreditAttribution: khiminrm commentedSubscribe
Comment #12
akamaus CreditAttribution: akamaus commentedFixed a patch from #6 so now it really gets applied by drush make.
Comment #13
witchcraft CreditAttribution: witchcraft commentedSubscribe
hope it will fixed in RC1
i dont know how to apply patch so far
Comment #14
akamaus CreditAttribution: akamaus commented@witchcraft, just go to sites/all/modules/commerce of your drupal installation and run
patch < /path/to/commerce_order_total_translate.patch
Comment #15
JGO CreditAttribution: JGO commentedPlease apply fix :)
Comment #16
JGO CreditAttribution: JGO commentedPatch in #6 is working great btw :)
Does anyone experience the problem that fields translations are not shown ? I mean the label translation works, but the content of the field is not shown translated.
Comment #17
guillaumev CreditAttribution: guillaumev commentedConfirming patch #12 works as well...
Comment #18
rszrama CreditAttribution: rszrama commentedSee #8 / #10 for why I'm not committing this as is. If there's a way to do this through field translation, I'd prefer that. What we're dealing with is apparently a regression caused by Drupal core changes, so we shouldn't have to use t() in this way to translate our label.
Comment #19
Damien Tournoud CreditAttribution: Damien Tournoud commentedWe need something like this.
It will only work properly when the Field API will pass the requested language down to the formatter (which is the point of #1178500: hook_field_*() prepare/view have no access to the requested language). Until that core patch lands, it will just use the current interface language.
Comment #20
tormiSubscribing.
Comment #21
ducecc CreditAttribution: ducecc commentedsubscribe
Comment #22
City-busz CreditAttribution: City-busz commentedsubscribe
Comment #23
gagoo CreditAttribution: gagoo commentedSubscribe
Comment #24
Cookiz CreditAttribution: Cookiz commentedSubscribe
Comment #25
ytsurksame for the string Billing infromation ;)
waiting for CORE #1178500: hook_field_*() prepare/view have no access to the requested language
Comment #26
brunorios1 CreditAttribution: brunorios1 commentedsubscribe
Comment #27
vasikesubscribe
Comment #28
amfis CreditAttribution: amfis commentedpatch #12 looks good.
Comment #29
andypostI think $GLOBALS['language_content'] should be used here.
Also 'en' should be changed to LANGUAGE_NONE
Issue (1) make no sense because of (2)
1 - #1178500: hook_field_*() prepare/view have no access to the requested language
2 - #1089174: Prepare view hooks do not receive the language parameter
Comment #30
atlea CreditAttribution: atlea commentedHi -
is there a solution yet to translate field labels? Or edit them? :) Need to translate "Order total" and "Shipping information" on the "order" bundle.
I guess this only is a problem if there is no translation when the fields are created, as some of the labels have translated labels.. but that is not always the case.
i18n seems overkill for single language sites (that is non-English).
Thanks :)
Atle
Comment #31
mr.baileysMarked #1463990: Some strings are not translatet as duplicate.
Comment #32
atlea CreditAttribution: atlea commented#32: Short update. Tried i18n field translation, and could not get it to work with Commerce. The labels did show up as translateable, but translations are not working when printed. Have not had the time to look into this any further.
Comment #33
sunfire-design CreditAttribution: sunfire-design commentedI think this patches work for both translation problems.
The first translate "Order total" and the second one the "Shipping Information" and "Billing Information" problem.
It works for me.
Comment #35
sunfire-design CreditAttribution: sunfire-design commentedNew version.
Should also work without l18n.
Comment #36
elmotri CreditAttribution: elmotri commentedHere is another patch for shipping and billing that is working. Didn't test this one.
Comment #37
sunfire-design CreditAttribution: sunfire-design commented@elmotri There are many ways to translate these strings
Now the order total patch should pass the test.
Comment #38
elmotri CreditAttribution: elmotri commentedIf you set the status to needs work, the patch won't be tested. See http://drupal.org/node/332678
I don't prefer one patch over another :) as long as it works
Comment #39
sunfire-design CreditAttribution: sunfire-design commented#35: commerce_price-translate-order-total.patch queued for re-testing.
Comment #40
sunfire-design CreditAttribution: sunfire-design commented@elmotri Thx for the link.
Comment #41
rszrama CreditAttribution: rszrama commentedEvery time we hit a field translation issue, some form of
t($instance['label'])
comes up - wrapping a variable in t(). However, as I always point out, that is an inappropriate use of the function. t() should only be used to wrap string literals per the documentation. We can definitely get the i18n support in if this is what we need to do to support it, though I was under the impression that was supposed to just work for some reason. : PComment #42
TipiT CreditAttribution: TipiT commentedPatch works good, but says there is "trailing whitespace". Thanks!
Comment #43
bojanz CreditAttribution: bojanz commentedThis is not committable.
Comment #44
sunfire-design CreditAttribution: sunfire-design commentedThe last patches only use the t() function, if i18n isn't installed.
Comment #45
rszrama CreditAttribution: rszrama commentedRight, but that's still inappropriate. t() should never be used to wrap variables, only string literals. In other words,
is fine, but
is not, even if it's just as a fallback for an actual solution.
Comment #46
sunfire-design CreditAttribution: sunfire-design commentedYes it's a bit quick and dirty, but i couldn't find a better way now.
Comment #47
atlea CreditAttribution: atlea commentedI think we should look at why the field labels are not translated using i18n rather than "quick and dirty" fixes.
I have just had a chance to look at this briefly, but I seems like I was able to translate the field instance label, but not the field label since the field is locked. That is fine, but I suspec the field label is printed rather than the instance label since everything looks ok in the backend, but the untranslated label is still output to the screen.
A.
Comment #48
no2e CreditAttribution: no2e commentedThere is a fix for the strings "Billing information" and "Shipping information": #1451132: Translation issue "Billing information" + "Shipping information" (patch in #6)
Comment #49
tregismoreira CreditAttribution: tregismoreira commentedThe patch #37 works great for me.
Comment #50
samuel.pismel CreditAttribution: samuel.pismel commented#35: commerce_price-translate-order-total.patch queued for re-testing.
Comment #51
rszrama CreditAttribution: rszrama commentedNothing has changed since this was demoted to "needs work". See my comments above for the reasons why. The issue linked in #48 may provide us with a good solution here.
Comment #52
helior CreditAttribution: helior commentedThis should be sufficient.
Comment #54
helior CreditAttribution: helior commented#52: field-translate-1121722-52.patch queued for re-testing.
Comment #56
rszrama CreditAttribution: rszrama commented#52: field-translate-1121722-52.patch queued for re-testing.
Comment #58
rszrama CreditAttribution: rszrama commentedAhh, the problem was the Version was set to 1.2. : P
Comment #59
rszrama CreditAttribution: rszrama commented#52: field-translate-1121722-52.patch queued for re-testing.
Comment #60
rszrama CreditAttribution: rszrama commentedCommitting the quick fix here from #52. Worked fine for me translating that field to le français.
It does seem silly to keep adding calls to i18n_field() throughout our code, though, so I'm going to open a follow-up that evaluates replacing strings on an object-by-object basis per Damien's patch in #19. That would entail replacement for all calls to i18n_field() if possible.
Comment #62
dornea.nu CreditAttribution: dornea.nu commentedHi,
the problem still persists in commerce 7.x-1.3. Any ideas how to solve it?
Thanks in advance.
Cheers,
Victor
Comment #63
Damien Tournoud CreditAttribution: Damien Tournoud commentedWhat's the reasoning with not directly committing #19? As far as I see it should have exactly the same effect: we use the current user interface language if we don't have a more specific language we can use.
Comment #64
rszrama CreditAttribution: rszrama commentedD'oh, I'm guessing that by the time I circled back around to this I just didn't even notice your comprehensive patch from before. Rerolled and putting it up for testing.
Comment #65
vasikei can confirm that all field instances could be translated both with or without the last patch (#64).
So the question is this patch it's really needed?
As i know the i18n Field translation should be able to do it for all type of fields, if the fields are defined right, no matter of entity type.
Maybe the solution search should related with Damien Tournoud #10 comment.
imho it's about how the LOCKED Commerce fields could be localized in a non-multilingual drupal, in other language than english.
could be this a Drupal core field locale issue?
Comment #66
rszrama CreditAttribution: rszrama commentedI guess the idea behind the patch in #64 (which I'm reclassifying as a feature request since the bugs themselves have been fixed) is that we could translate a product earlier in the call stack so we don't have to put all these calls to i18n_field throughout our code. If we were going to go with this, though, I suppose we'd need to update the patch to remove all those calls to i18n_field and then test to make sure translation was still possible. I haven't actually reviewed the patch, just put it through test bot.
Comment #67
garegin1987 CreditAttribution: garegin1987 commented#64 patch not work
Comment #68
hamuchen CreditAttribution: hamuchen commentedI had the same issue all the way. And i have found the solution for translating "field:commerce_order_total:commerce_order:label".
It's a bad config for your localization:
I hope this will help you all.
btw: I have #64 installed.
Greetings
hamu
Comment #69
Damien Tournoud CreditAttribution: Damien Tournoud commentedWe still do need #64. What happens is that
i18n_fields
automatically translate field and instance data (label, description, allowed values, etc.), but can only do so in context it controls. When we use this data in other contexts (like the ones targeted by this patch: error messages, etc.), we do need to perform the translation manually.Comment #70
SaxxIng CreditAttribution: SaxxIng commentedhamuchen (#68) you're right, but after that (translate the field once again) I have to restore the source language on my native site language (not english) and so translated labels doesn't work anymore!
This trick works only if I could mantain language source english "forever" (but obviosuly on many sites this is just not possible).
Comment #71
akamaus CreditAttribution: akamaus commentedIn the past I used #6 as a workaround. Can someone explain the current situation? Do I need to enable i18n to translate 'Order total' into russian?
Comment #72
odizle CreditAttribution: odizle commentedThanks for working on this guys.
i am not a programer but i have tried the patch in #64 using mac osx terminal and get this error:
can't find file to patch at input line 49
Perhaps you should have used the -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git a/modules/customer/includes/commerce_customer.checkout_pane.inc b/modules/customer/includes/commerce_customer.checkout_pane.inc
|index eebdcc0..9c34c9e 100644
|--- a/modules/customer/includes/commerce_customer.checkout_pane.inc
|+++ b/modules/customer/includes/commerce_customer.checkout_pane.inc
anyone can help with this?
any updates at all for this issue?
Thanks
Comment #73
brunorios1 CreditAttribution: brunorios1 commented@odizle, try:
patch -p1 < 1121722-64-instance-field-translation.patch
Comment #74
odizle CreditAttribution: odizle commentedthanks @brunorios1,and sorry for the late reply. I think I did manage to apply the patch using the command you have written, but after uploading the patched module to the server, the site did not i got an error :
Fatal error: Cannot redeclare commerce_object_translate() (previously declared in /home/evelon/domains/evelon.co.il/public_html/sites/all/modules/commerce 3/commerce.module:117) in /home/evelon/domains/evelon.co.il/public_html/sites/all/modules/commerce 3/commerce.module on line 147
Comment #75
ram4nd CreditAttribution: ram4nd commented#6 Translated Order Total for me.
Comment #76
rszrama CreditAttribution: rszrama commentedThanks for the feedback, but as I've mentioned at least a half dozen times above, we can only use t() to wrap string literals. You can feel free to use that patch on your own site if you want, just remember to re-apply it when you update versions of Commerce.
Comment #77
Raphael Apard CreditAttribution: Raphael Apard commentedIs there a solution to use commerce in only one language (not english) without enable i18n modules ?
Comment #78
gynekolog CreditAttribution: gynekolog commentedRaphael Apard: solution #6 work fine
Comment #79
Raphael Apard CreditAttribution: Raphael Apard commentedthx. I'm currently using this code :
Comment #80
geemark CreditAttribution: geemark commented#35: commerce_customer-translate-shipping-billing-information.patch queued for re-testing.
Comment #81
Anonymous (not verified) CreditAttribution: Anonymous commentedI'm lost. #6 is considered wrong, got it. #64 is considered unfinished ("we'd need to update the patch to remove all those calls to i18n_field"). #79 doesn't work for me. Can someone provide a clue stick to those who need to put a multilingual shop into production and can't use English as a source language, please?
Thanks a lot!
Comment #82
Summit CreditAttribution: Summit commentedHi, http://drupal.org/node/1451132#comment-5984944 maybe?
greetings, Martijn
Comment #83
laraz CreditAttribution: laraz commentedsolution #6 work for me. THANKS.
Comment #84
a.milkovskyhttp://drupal.org/node/1121722#comment-4593864
helped me
Comment #85
Prague man CreditAttribution: Prague man commentedWhy this is not in stable downloaded module?
Comment #86
giuvax CreditAttribution: giuvax commentedI did it. Brutally.
What gives the label to the Order total in Cart is the field label: the label of 'Order total' field in the Order settings (config/order/fields). I changed the label of Shipping Information and Billing information and I got them translated on Cart, but I couldn't since Order total field is locked by default.
So, I went to the db. I unlocked the field (changing 1 to 0 in the right field in the drup_field_config table). I came back to that admin page and I could edit the field. I change the label and then I LOCKED BACK AGAIN the field (1 -> 0).
I do not recommend to anyone who doesn't know what he's doing. But I solved while I'm waiting a clean solution.
Comment #87
ShaneOnABike CreditAttribution: ShaneOnABike commentedOkay it's been like over a year and this seems to be the only item that isn't translated can we roll this into the next release PLEASE with sugar on top??
Comment #88
gianfrasoft CreditAttribution: gianfrasoft commentedMy suggestion is: take a look to the views those have been installed by commerce module!
Comment #89
giuvax CreditAttribution: giuvax commentedNope. All the words in any View doesn't apply. I tried translating in any View.
Comment #90
gianfrasoft CreditAttribution: gianfrasoft commented@rszrama, I think you should add this code to your patch:
http://drupal.org/node/1776644#comment-7372464
Infact, your patch doesn't translate "Order total" label in order's page. Thank you!
Comment #91
bojanz CreditAttribution: bojanz commentedOrder total is translatable right now (make sure you have i18n_string and i18n_field installed, you won't get anywhere in D7 translating without them).
This issue is just about code cleanup (and I will be rerolling the patch ASAP).
EDIT: Patch needed quite a bit of work. Posting it tomorrow.
Comment #92
bojanz CreditAttribution: bojanz commentedRetitling for clarity.
Everything changed since the previous patch was written, I had to start from scratch.
This follows the i18n pattern of returning the translation from the function, instead of modifying the object that's being translated by reference.
I am unsure about this part:
Isn't $instance['label'] always non-empty? Can we just replace that whole line with $translated_instance['label']?
Comment #93
Clauce CreditAttribution: Clauce commentedHave applied patch #92, no error, but still getting "Order total" in my french site... but I'm still at 7.x-1.5 version, so that may be the cause...
Comment #94
rszrama CreditAttribution: rszrama commentedThen you might need to update. : )
Leaving this at 7.x-1.x-dev; the test bot needs to know wish version we're working with in case there are future updates to the patch.
Comment #95
Clauce CreditAttribution: Clauce commentedSorry !! i didn't realise I've changed the status of the post...
Thanks for your patience, I'am a newbie when it comes to posting replies in issues, but now I understand !
Comment #96
webdrips CreditAttribution: webdrips commentedHope this the correct thread since a bunch of other threads point to this one.
I have a couple content types that use the price field.
#92 applies cleanly against 7.x-1.7, but my translated price field label translation isn't working for node add/edit form.
The translations are working for the node view. The rest of my site is translated properly.
Also anyone know how to translate currency codes?
Comment #97
bojanz CreditAttribution: bojanz commented#2015797: [meta] Make Commerce fully translatable is the place for generic questions like those.
For instance, it lists the i18n patch you need in order to translate the price label on the node add / edit form.
Comment #98
rszrama CreditAttribution: rszrama commentedHonestly, my hunch is that we don't need that tertiary operator there, but amateescu added it on purpose when it first went in, so I can only imagine he encountered a scenario where the label was not set for some reason. If not, it's harmless cruft.
Committing #92 as is; sorry it took me so long to get to.
fwiw, I was able to translate the price field as expected, and you probably shouldn't be translating currency codes. If you really need to, you can create your own language specific currency info cache.
Comment #99
tahiticlic CreditAttribution: tahiticlic commentedHi,
it is marked as fixed, but still doesn't work with last dev version. Is there some patch to apply on ?
Comment #100
rszrama CreditAttribution: rszrama commentedIt works - I've tested it. : D
Please describe what it is you can't actually accomplish. Remember that you need to clear your cache and refresh your strings to see the new interface text translation possibilities.
Comment #101
tahiticlic CreditAttribution: tahiticlic commentedWhat do you mean by "refresh your strings" ?
I've updated the module to dev version, clear caches, translated "Order total" to "Total de la commande" (which appears correctly in Views UI), but still on checkout rendering I can read "Order total".
Comment #102
rszrama CreditAttribution: rszrama commentedI had no issue translating it, so I'm not sure. Perhaps you have other configuration to do? Is the language being detected properly, for example?
Comment #103
tahiticlic CreditAttribution: tahiticlic commentedWell every other string are translated correctly. But this one, I've never succeeded in translating it.
I'll try on a fresh install and report the result.
Comment #105
Argus CreditAttribution: Argus commentedThis is a confusing subject if you run in to it the first time, so I'll add a little explanation. Please correct if needed.
Comment #106
tahiticlic CreditAttribution: tahiticlic commented@Argus, can you check the list you give :
I've followed what you've said, and now "Order total" is translated as "Adresse de Facturation" (which is the translation of "Shipping address").
Comment #107
Argus CreditAttribution: Argus commented@tahiticlic: Here is an image of what I was pointing at. Did you use that?
admin/config/regional/i18n/strings
Comment #108
tahiticlic CreditAttribution: tahiticlic commentedNope, what I can see is the attached screen.
What versions do you use ? I've downloaded the last dev version of Commerce(7.x-1.8+1-dev) and the last version of Internationalization (7.x-1.9)
[Edit] my question is maybe silly, but why is this so complicated to translate those strings ? Why don't we use the standard 't' function process ?
Comment #109
Argus CreditAttribution: Argus commentedI'm using the versions in Commerce Kickstart, which are Commerce 7.x-1.8 and Internationalization 7.x-1.9.
Perhaps you have to manually add Commerce Order Message as a text format? Go to "admin/config/content/formats". I cannot find where this text format is applied to the Order Total though. Perhaps you could try to select all text formats in that screen (admin/config/regional/i18n/strings).
These are not normal strings but variables used in the code, that's why they cannot be translated easily. Read the above discussion to learn more about it.
Comment #110
toufichalwani CreditAttribution: toufichalwani commentedsolution #6 work for me. THANKS.
Comment #111
maxplus CreditAttribution: maxplus commentedHi Thanks,
#6 also solved my problem
Comment #112
ssoulless CreditAttribution: ssoulless commented#6 wrok for me too!!
that solved my problem
Comment #113
Paul89 CreditAttribution: Paul89 commented#6 solved issue.
Comment #114
a.milkovskyWorkaround without patching:
Comment #115
4kant CreditAttribution: 4kant commentedThanks to a.milkovsky (#114). I always should install this module from the start together with commerce ;-)
Comment #116
maxplus CreditAttribution: maxplus commentedThanks a.milkovsky (#114),
easy fix and works great for me too and now I don't always have to patch de core Commerce files again!
Comment #117
maragones CreditAttribution: maragones commentedSolution #86 works for me (for the label "Order total")
Thanks.
Comment #118
psf_ CreditAttribution: psf_ commentedSolution #114 worj fine, thx...
Comment #119
rolok CreditAttribution: rolok commentedHi all,
sorry about the dumb question...but where should i place the code (Solution #114)?
you main to writing a new module and add this code?
Thanks :)
Comment #120
rolok CreditAttribution: rolok as a volunteer commentedOK, never mind
i based on solution #6 with a little bit changes :)
now its working
thanks
i replaced the row: 'title' => check_plain($translated_instance['label']),
(this row is little bit different from the one in #6 probably because the different versions)
with this: 'title' => check_plain(t($instance['label'])),
works for me
Comment #121
marco.falconi CreditAttribution: marco.falconi commented#114 worked for me (after translating the text with the tranlation interface), but i don't know if it is the best solutuion.
Regards