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.
At the moment Ubercart does not support the ability to translate a country name, so the CIF files have English country names but you cannot provide locale alternatives.
For example, United Kingdom needs to be Royaume-Uni for a French website. Impossible to do this.
I will upload a patch shortly to resolve this issue.
Comment | File | Size | Author |
---|---|---|---|
#17 | 782960_translate_countries.patch | 8.5 KB | Island Usurper |
#13 | 782960-translate-countries.patch | 10.3 KB | longwave |
#1 | 782960-uc_translate_countries.patch | 938 bytes | greg.harvey |
Comments
Comment #1
greg.harveyAnd here is the patch. Tested on www.weeride.fr, seems to work fine.
Comment #2
Pomliane CreditAttribution: Pomliane commentedHi,
Any news on this just-can't-believe-it issue ?
By the way is this really just a 'feature request' ?
Cheers,
Comment #3
greg.harveyBumping this up to major, as it's a tiny patch and is a big problem for multilingual Ubercart sites.
Comment #4
TR CreditAttribution: TR commentedIt's a problem, but the fix is just wrong. Please read http://api.drupal.org/api/function/t/6
Comment #5
greg.harveyHmm, Ryan intimated that might be an issue. It does work, but I appreciate it can have its own issues. Ok, so this is going to require a lot more thought.
Right now the only place these country names are strings in code is in the CIF files. Unfortunately, these are often contributed and look like this:
Since the country name is inserted directly in to the database, all these would need to change. But if we were to do something like this:
Then we could provide translations for country names in the translations for uc_store.module.
Would that work do you think?
Comment #6
TR CreditAttribution: TR commentedThink about the way translations work. The translation template extractor parses the module code looking for strings wrapped in t(). The extractor uses the argument of the t() function to build a list of words and phrases that need to be translated. If you use a variable as the argument, there's no word or phrase to put in that list because the value of the variable is unknown and can be anything at run time (even if you personally know that the variable will only have certain values, the program has no way of determining that).
The reason your fix "works" is because you've manually translated the few country names you use in your store, which adds those countries to the list. But if a new country were loaded, that name would not appear translated until you manually added a translation for it.
The reason just adding t() into the .cif file won't work is because the .cif files are not parsed as part of the template extraction process. There's probably a way to fool the extractor by using something like (in pseudo-code ...)
if (FALSE) module_load_include('<all .cif files>')
in the .module. That would allow the extractor to parse the .cif files and see the country names wrapped in t() but would never load the .cif files when the module is run normally.Someone is going to have to do the research to figure out if there's an established way of translating module data like this in Drupal (I have not encountered one) or if Ubercart has to make up its own mechanism to ensure the data is translatable. And if Ubercart has to invent a solution, what should that solution be.
Comment #7
greg.harveyYup, which is fine for my purposes (it stopped my client chewing on my arm) but as you say, it isn't a correct long-term fix.
Thanks for the suggestions/ideas to follow up on. I'll see if I can do a little research when I get back from my holidays. Hopefully some other interested parties will join in. I'll tweet it and see if any traction is gained.
Comment #8
PROMESThe patch in #1 does work, but the resulting table still is sorted the original way. We have to add a sort.
Part of the original patch:
after the shown code should be added:
Anyone who needs a translation .po file:
use the .pot file from project: countries_api.
Comment #9
longwaveMarked #801436: Allow translate zone name in uc_zone_select (uc_store) as a duplicate.
Comment #10
Bartezz CreditAttribution: Bartezz commentedAs mentioned in the duplicate issue, same goes for zone names.
Cheers
Comment #11
TR CreditAttribution: TR commentedSee also #1066364: META: Make custom data translatable.
Comment #12
longwaveSee #1066364-11: META: Make custom data translatable for a possible approach to this.
Comment #13
longwavePatch attached. This lets you run a multilingual Ubercart installation that has translated country names in the dropdowns at checkout and the various admin pages that show country names, sorted alphabetically where needed.
Country names are stored in English in the database and then t() is wrapped around $country_name where appropriate - this is not usually recommended, but in this instance it is okay as the variable will always come from a fixed set of strings. uc_store.countries.inc will ensure these strings are extracted by potx when translation source files are generated; this file is never included but in testing potx will pick it up anyway.
Until this is committed and a new 6.x release is made, localize.drupal.org will not include translations of country names in Ubercart .po downloads. You can work around this by adding translations manually, or importing a .po file from another project that includes translated countries.
This patch was sponsored by Opsview.
Comment #14
longwavePlanning to commit this to 6.x soon, as it has been working well in testing here. Comments or reviews still welcome, however.
Comment #15
TR CreditAttribution: TR commentedI didn't try to use a translation, but I inspected and tested the patch with a clean install in English and everything behaved as it should without any errors. The approach is sound and addresses all the concerns above and in related issues. As mentioned in http://drupal.org/node/1066364#comment-4231434, the addition of uc_store.countries.inc won't be necessary for the D7 port.
Comment #16
longwaveCommitted to 6.x. Needs porting to 7.x without uc_store.countries.inc, as noted by TR.
Comment #17
Island Usurper CreditAttribution: Island Usurper commentedHere 'tis. Haven't tested it yet, but I'll install a language I can halfway read before too long.
Comment #18
longwaveTested and committed.