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.
Hi,
I need to provide translatable shipping labels for a multilingual store. I searched around the code and this functionality is not provided yet...
I made an attempt with the following patch,
It works fine for me, however I am not sure if this the "drupal way" :)
Cheers
Dimitris
Comment | File | Size | Author |
---|---|---|---|
#1 | i18n_labels.patch | 869 bytes | jimkont |
Comments
Comment #1
jimkont CreditAttribution: jimkont commentedForgot to attach the patch :)
Comment #2
rszrama CreditAttribution: rszrama commentedAhh, didn't realize you posted the same thing in the Shipping Flat Rate queue. Let's close that one as a duplicate and try to find a solution here. For reference, this was my comment there:
We're always open to solutions that don't abuse the API. I know there are modules out there for handling this sort of thing, but I don't have any experience with them. If you research them and recommend a solution, that will go a long way toward resolving the issue for everyone. : )
My hunch is there's some i18n module we can integrate with to solve this, but I don't have any experience with it.
Comment #3
googletorp CreditAttribution: googletorp commentedRunning t function on a variable is a no go.
One solution could be to use variable_get/set since you can translate those.
Comment #4
rszrama CreditAttribution: rszrama commentedI wonder if http://drupal.org/project/variable might offer a solution, too. : ?
Comment #5
atlea CreditAttribution: atlea commentedStoring it in a variable and using the variable module for translations is a viable solution.
I prefer using http://drupal.org/project/stringoverrides for its simplicity. All it does is add an UI for the $custom_strings variable that is used by t() (and has locale support). We can mimic what t() does and reuse this variable..
I don't have 1.x installed and headed for bed, so I'll just try to wing this one.. it would be something like:
This would also work for sites without the locale module enabled... or even in settings.php. ;)
waddayathink? :)
Atle
Comment #6
googletorp CreditAttribution: googletorp commentedWaiting for #1422996: localization and i18n integration in a stable release of Rules.
Comment #7
googletorp CreditAttribution: googletorp commentedWe can actually solve this issue now.
Comment #8
Summit CreditAttribution: Summit commentedHi, I would love to see this committed. Where do I need to set the code in http://drupal.org/node/1369696#comment-5382990 for the shortterm solution?
And any progress on this stable solution please?
greetings, Martijn
Comment #9
Lukas von Blarer@googletorp: I am trying to find the place to fix this without success. Where could this be done?
Comment #10
googletorp CreditAttribution: googletorp commentedI'm guessing this needs to be handled in the rules integration code. I don't really know what's needed since I haven't done this before and never got around to look at it.
Comment #11
Lukas von BlarerJust fixed it in another module:
Not really clean... But hey, it works :)
Comment #12
googletorp CreditAttribution: googletorp commentedThe issue here is the label when it's configured. So the idea is that you can enter your custom label in the rules interface but have it be translatable.
Comment #13
Lukas von BlarerSo this was not solved by #1422996: localization and i18n integration? Is this a rules issue?
Comment #14
Gerto CreditAttribution: Gerto commentedStrange that something this basic is so hard to do.
I ended up solving it like this:
Data Comparison: Parameter: Data to compare: [site:current-page:language], Data value: *LANGUAGE*
Not sure if this is a proper way to do this, but it works and you don't have to make any code changes, so seems ok to me :)
Comment #15
ShaneOnABike CreditAttribution: ShaneOnABike commentedI am confused why we can't actually run the labels through a proper i18n function. The rules bug that was apparently blocking this is closed?
Comment #16
ShaneOnABike CreditAttribution: ShaneOnABike commentedI guess it would require defining the proper i18n info hook and each time a new shipping type was setup it would need to be added.
https://groups.drupal.org/node/152929
Comment #17
guy_schneerson CreditAttribution: guy_schneerson commentedThanks for working on this guys
I had to get this working for a client and used the following. Its a bit of a hack but the client is happy so it will do for now.
Comment #18
guy_schneerson CreditAttribution: guy_schneerson commentedthe problem with the above is it only solves the issue on the selection form so in places like the shopping cart view it will show none translated shipping.
The code below solves this and is a better approach (although no replacement to sorting this issue)
Comment #19
MyriamB CreditAttribution: MyriamB commented#18 worked for me. Thank you.
Comment #20
chefnelone CreditAttribution: chefnelone commented#18 worked for me too ;) The patch doesn't apply to the actual dev version.
Comment #21
fugazi CreditAttribution: fugazi commented#18 worked for me.
Comment #22
stella CreditAttribution: stella commentedYou really shouldn't be calling the t() function on a $variable, especially when the value in that variable is a user entered one such as this. See the API docs for more info: https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/t/7
Comment #23
guy_schneerson CreditAttribution: guy_schneerson commentedHi @stella you are correct and that's why I described it as a hack. However I think that the security issue is mitigated by the fact that the user that has entered the text is an admin.
But yes +1 me for needs work :)
Comment #24
ShaneOnABike CreditAttribution: ShaneOnABike commentedI recently tried to apply the solution in #18 but it never gets called in a custom module which is odd
Comment #25
s.messaris CreditAttribution: s.messaris commentedFor anyone needing this for drupal 8 and stumbling on this issue, the corresponding issue for d8 is https://www.drupal.org/project/commerce_shipping/issues/2934142