This is G o o g l e's cache of http://www.ubercart.org/forum/support/1546/catalog_block_ignores_localiz... as retrieved on Aug 3, 2007 22:08:52 GMT.
G o o g l e's cache is the snapshot that we took of the page as we crawled the web.
The page may have changed since that time. Click here for the current page without highlighting.
This cached page may reference images which are no longer available. Click here for the cached text only.
To link to or bookmark this page, use the following url: http://www.google.com/search?q=cache:OcvUjv0qC3gJ:www.ubercart.org/forum...
Google is neither affiliated with the authors of this page nor responsible for its content.
These search terms have been highlighted: 07 24 2007
Ubercart
* Home
* Documentation
* Forums
* Issues
* Livetest
Home » Forums » Ubercart » Support
Catalog Block ignores localizer translations of "Catalog" title
Submitted by insipiens on Tue, 07/24/2007 - 14:49
insipiens
Posts: 19
Joined: 07/19/2007
hey,
When Drupal is installed with Localizer (which is quite frequent outside native english speaking countries), the Drupal categories and terms (at Home » Administer » Content management » Categories) can be entered in several languages (english plus translations).
The problem is: while the translated terms do show up correctly in the Catalog block, the title "Catalog" itself remains as is (in English, untranslated) independently of the chosen locale, and even though translations have been entered in the "edit vocabulary" form.
how can i correct this ? (so that the block title "Catalog" gets translated too, just like the terms)
* Add new comment
permalinkTue, 07/24/2007 - 15:56
Shawn Conn
Posts: 34
Joined: 02/18/2007
Administrator
One fix for this is to just rename the block to its translated value. You can rename any block by going to the block administer page ("admin/build/block") and clicking "configure" on the Catalog block.
* reply
permalinkTue, 07/24/2007 - 19:33
insipiens
Posts: 19
Joined: 07/19/2007
I'm not sure i understand your answer well. It sounds as if you supposed my aim was to make a shop in one single non-English language. if that was the case, then indeed there wouldn't even be a need to mess with translations, i could just replace 'Catalog' with the translation.
However, the whole point with Localizer is to allow a drupal site to support several languages. there's not just one translation, there's one per language, so the title depends on the locale chosen by the user (i currently have 3 locales activated, more are planned), and i can't just use one fixed translation.
Or did i somehow misunderstand your answer?
* reply
permalinkWed, 07/25/2007 - 04:52
daniel
Posts: 29
Joined: 05/08/2007
Bug FinderGetting busy with the Ubercode.
Which version of Ubercart are you using? There was a bug in an earlier version (missing t() around the category title) but it has since been corrected.
* reply
permalinkWed, 07/25/2007 - 15:17
insipiens
Posts: 19
Joined: 07/19/2007
i'm using ubercart-5.x-1.0-alpha7b
and indeed, a look into uc_catalog.module reveals the error
(which is also visible in http://bazaar.ubercart.org/ubercart/alpha/ubercart/uc_catalog/uc_catalog...):
at line 278 of that file, the Title of the Catalog menu is the first argument to function l, that is:
variable_get('uc_catalog_name', t('Catalog'))
which is wrong.
the t() has to be around that whole thing, not around 'Catalog'. So the correct first argument to function l would be:
t(variable_get('uc_catalog_name', 'Catalog'))
once i corrected that, the title gets auto-translated ok
* reply
permalinkThu, 07/26/2007 - 02:10
daniel
Posts: 29
Joined: 05/08/2007
Bug FinderGetting busy with the Ubercode.
Actually the code was right before you changed it. The second argument to the variable_get function is the default value in case the variable has never been set. In your case I'm guessing that you had an old version (before 'catalog' was wrapped in the t() function) installed and then upgraded.
* reply
permalinkThu, 07/26/2007 - 05:20
insipiens
Posts: 19
Joined: 07/19/2007
???
in that line, the t() has to be AROUND the whole variable_get, not around Catalog !!!
Before explaining the reason for this, i'll repeat that the Title doesn't auto-translate with the values provided in the Localizer translation fields until that correction is made in the code.
now for the reason:
variable_get('uc_catalog_name', t('Catalog'))
means that the title is the content of the variable uc_catalog_name (if it is set) and otherwise the translation of the word 'Catalog'.
So it only works for the default value, i.e. if uc_catalog_name is NOT set. If it IS set, then NO TRANSLATION whatsoever happens. you get the untranslated content of that variable for all languages.
This is wrong, since it doesn't work when you set a name with translations (and that's exactly what happens if you change the 'Catalog' title and the translations in the 'Title' and 'translation' field of the category editor.
t(variable_get('uc_catalog_name', 'Catalog')) )
means that the title is the translation of the variable uc_catalog_name and if that variable isn't set, the title is the translation of 'Catalog'.
so: if the variable isn't set, we get the same default title as above: t('Catalog'),
but more importantly, when the variable IS set, it translates too (unlike the code above which doesn't work when the variable is set)
just try it out:
install localizer, enter a name for the catalog and translations in Home » Administer » Content management » Categories (click on 'edit vocabulary' near 'Catalog')
and see which of the two code lines correctly translates.
P.S.: no, i did NOT upgrade, the latest Übercart version is the first that was installed on my server and it did already have the t() around 'Catalog', which just happens to not work if the variable is set - thus the need to put the t() around the whole variable_get and not just around 'Catalog'
* reply
permalinkThu, 07/26/2007 - 05:29
daniel
Posts: 29
Joined: 05/08/2007
Bug FinderGetting busy with the Ubercode.
Well, I have tried it since I was the one that reported the initial bug that now has been fixed Smiling
I repeat, the t() is in the correct place. If you look where the variable is set (uc_catalog.install) you'll see why:
variable_set('uc_catalog_name', t('Catalog'));
meaning, if there is a translation for 'Catalog' the variable uc_catalog_name will be set to the translation.
What I tried to say earlier was that if you installed Ubercart earlier (before the t() was added), or if you didn't have a translation of 'Catalog' then, the variable will be set to the English version. If you uninstall/reinstall uc_catalog it should work fine.
I agree that there would be alternatives to this approach but this is how it works atm.
* reply
permalinkThu, 07/26/2007 - 07:12
insipiens
Posts: 19
Joined: 07/19/2007
again: the t() around 'Catalog' doesn't work at all unless uc_catalog_name isn't set. As soon as you enter a title in the category editor form i mentioned, it can't work (since uc_catalog_name is set then) and all you get is an untranslated variable
in order to work in both cases (variable set or not), the t() has to be outside variable_set.
the only difference is that it also translates when the variable is set, so
a) that's exactly what's needed and
b) there's no disadvantage
what's the point in translating only if uc_catalog_name is not set?
* reply
permalinkThu, 07/26/2007 - 07:30
daniel
Posts: 29
Joined: 05/08/2007
Bug FinderGetting busy with the Ubercode.
again: the t() around 'Catalog' doesn't work at all unless uc_catalog_name isn't set.
This is exactly what I said above, isn't it?
And I agree that there are better/cleaner solutions. Why, for instance set a variable at all when using it requires a default value for the variable_get call? But since this seems to be the generally accepted way of doing things in Ubercart and Drupal I personally prefer to deal with this minor inconvenience rather than to modify the core files, but hey - go with whatever works best for you! Smiling
To solve the problem with ubercart upgrades the variable could be cleared and re-set with the t() call in an update function in the uc_catalog.install file but since ubercart is still in alpha I guess it doesn't matter much.
* reply
permalinkThu, 07/26/2007 - 07:41
Ryan
Posts: 1693
Joined: 09/26/2006
AdministratorCode Monkey Head - I eat bugs.
Hmm... insipiens, I'm curious if you've tried this and have it working on your site. Puzzled What daniel describes is the documented way for the t() function to work, and it's what I would expect as well. It shouldn't be used to translate variables... anything besides a single line string will break the function when using the extractor. But that doesn't account for strings that have been translated using the localizer or what-not.
My hunch is that if it is working for you, the correct thing to do would be to use t() in both cases, that way when Catalog is initially saved to the database it will get translated.
EDIT: Typed while daniel was replying, sorry for the overlap. Eye-wink
* reply


Joined: 08/07/2007