20 replies [Last post]
drupalina's picture
Offline
Joined: 09/20/2009
Juice: 5

Hi,

After searching this forum and some very old issues I've managed to find code replacements in uc_catalog.module so as to translate the word "Catalog" in the Block title and breadcrumbs. Basically that was done by placing the t() around the the whole variable_get rather than simply around t('Catalog'). For details see http://www.ubercart.org/forum/archive/107/catalog_block_ignores_localize... (I'm surprised that this is still not implemented in Ubercart 6x-2)

But now I'm trying to translate the actual taxonomy terms inside the catalog block (and other parts of catalog display) as if they were strings, but I can't find the replacement codes for where to put t().

Would someone please be kind enough to post the replacement codes???

I mean in the following format:

"replace this line:
EXAMPLE1
with this line
EXAMPLE2"

Thanks a lot!

alexku's picture
Offline
Joined: 10/06/2009
Juice: 50
drupalina wrote: Would
drupalina wrote:

Would someone please be kind enough to post the replacement codes???

I mean in the following format:

"replace this line:
EXAMPLE1
with this line
EXAMPLE2"
Thanks a lot!

Here is what I did:

uc_catalog.pages.inc file:

added the following code (to translate catalog name and desc on the catalog page and category name and desc on a category page) after line "$catalog = uc_catalog_get_page((int)$tid);"

<?php
//check if we are on the catalog or on the category page
if (!$catalog->tid) {
   
//if on catalog page
   
$catalog->name = tt("taxonomy:vocabulary:$catalog->vid:name", $catalog->name, NULL, FALSE);
    if (
$catalog->description) {
       
$catalog->description = tt("taxonomy:vocabulary:$catalog->vid:description", $catalog->description, NULL, FALSE);
    }
}
else {
   
//if on category (term) page
   
$catalog->name = tt("taxonomy:term:$catalog->tid:name", $catalog->name, NULL, FALSE);
    if (
$catalog->description) {
       
$catalog->description = tt("taxonomy:term:$catalog->tid:description", $catalog->description, NULL, FALSE);
    }
}
?>

added the following code (to translate term names in catalog) after line "foreach ($catalog->children as $child) {"

<?php
$child
->name = tt("taxonomy:term:$child->tid:name", $child->name, NULL, FALSE);
if (
$child->description) {
   
$child->description = tt("taxonomy:term:$child->tid:description", $child->description, NULL, FALSE);
}
?>

uc_catalog.module file:
function uc_catalog_nodeapi:

added the following code (to translate catalog name in breadcrumb) after line "if (count($terms)) {" replacing line "$crumbs[] = l(variable_get('uc_catalog_name', t('Catalog')), variable_get('uc_catalog_url', 'catalog'));"

<?php
$catalog_name
= variable_get('uc_catalog_name', 'Catalog');
$catalog_id = variable_get('uc_catalog_id', '1');
$translated_name = tt("taxonomy:vocabulary:$catalog_id:name", $catalog_name, NULL, FALSE);
$crumbs[] = l($translated_name, variable_get('uc_catalog_url', 'catalog'));
?>

added the following code (to translate term names in breadcrumb) after line "foreach (array_reverse($parents[$term->tid]) as $parent) {"

<?php
$parent
->name = tt("taxonomy:term:$parent->tid:name", $parent->name, NULL, FALSE);
if(
$parent->description){                                $parent->description = tt("taxonomy:term:$parent->tid:description", $parent->description, NULL, FALSE);
}
?>

function uc_catalog_block:
added the following code (to translate the name of the catalog block) after line "$content = theme('uc_catalog_block', $menu_tree);"

<?php
$catalog_name
= variable_get('uc_catalog_name', 'Catalog');
   
$catalog_id = variable_get('uc_catalog_id', '1');
   
$translated_name = tt("taxonomy:vocabulary:$catalog_id:name", $catalog_name, NULL, FALSE);
   
$subject = l($translated_name, variable_get('uc_catalog_url', 'catalog'));
?>

function uc_catalog_set_breadcrumb:
added the following code (to translate term names in the breadcrumb) after line "if ($tid != 0) {" replacing line "$breadcrumbs[] = l(variable_get('uc_catalog_name', t('Catalog')), 'catalog');"

<?php
$catalog_name
= variable_get('uc_catalog_name', 'Catalog');
$catalog_id = variable_get('uc_catalog_id', '1');
$translated_name = tt("taxonomy:vocabulary:$catalog_id:name", $catalog_name, NULL, FALSE);
$breadcrumbs[] = l($translated_name, variable_get('uc_catalog_url', 'catalog'));
?>

function _uc_catalog_navigation:
added the following code (to translate term names in the catalog block) after line "static $types;"

<?php
if ($branch->tid) {
   
$branch->name = tt("taxonomy:term:$branch->tid:name", $branch->name, NULL, TRUE);
    if (
$branch->description) {
       
$branch->description = tt("taxonomy:term:$branch->tid:description", $branch->description, NULL, FALSE);
    }
}
?>

I have also attached archive with corrected files (you can find corrections by searching for string "alexku")

Hope this helps Smiling

AttachmentSize
uc_catalog.zip 10.16 KB
heyyo's picture
Offline
Joined: 05/17/2009
Juice: 35
Re: drupalina wrote: Would

Will this solution will be committed ?

chewzer's picture
Offline
Joined: 01/21/2010
Juice: 5
Thanks

Thank you, I've solved a big problem:)

(I had to remove lines 448/449/450 to resolve an error in catalog title link)

alexku's picture
Offline
Joined: 10/06/2009
Juice: 50
chewzer wrote: Thank you,
chewzer wrote:

Thank you, I've solved a big problem:)

(I had to remove lines 448/449/450 to resolve an error in catalog title link)

Does not work for me if I remove these lines. Could you give me a list of other modules which you are using (perhaps "domain access" module)

chewzer's picture
Offline
Joined: 01/21/2010
Juice: 5
alexku wrote: chewzer
alexku wrote:
chewzer wrote:

Thank you, I've solved a big problem:)

(I had to remove lines 448/449/450 to resolve an error in catalog title link)

Does not work for me if I remove these lines. Could you give me a list of other modules which you are using (perhaps "domain access" module)

these are installed modules:

Ubercart
CCK
ImageCache
DHTML Menu
Thickbox
Advanced help
Token
Webform
jQuery Update
jQuery plugins
Wysiwyg
Views

baim78's picture
Offline
Joined: 12/15/2009
Juice: 2
Re: How to translate the taxonomy terms in Calatolg block?

Thanks for this post, its works, very help me.
I repost files after fixed problem in title link catalog.
Thanks.

AttachmentSize
uc_catalog_2.zip 10.55 KB
totsubo's picture
Offline
Joined: 11/12/2009
Juice: 158
Re: Re: How to translate the taxonomy terms in Calatolg block?

I used the files but I was not able to get the Catalog block title to change. It always displayed 'Catalog' even when I had a translation string available.

alexku's picture
Offline
Joined: 10/06/2009
Juice: 50
baim78 wrote: Thanks for this
baim78 wrote:

Thanks for this post, its works, very help me.
I repost files after fixed problem in title link catalog.
Thanks.

I see that Your fix doesn't use "global $language". It doesn't work for me this way and my solution posted earlier does. Will do more research on this later, when I will have some spare time Smiling

ferrangil's picture
Offline
Joined: 02/27/2009
Juice: 62
Translation of terms not shown on homepage, etc...

Almost working! thank you alexku for your excelent help!

When I'm on a product page, I can change between English, Spanish and Catalan and the Catalog changes it's block name and the terms show it's translated term, so perfect!
But when I'm on a term page, or the home page or any other page (about us, etc...) and I change the language to Spanish or Catalan, the Catalog block is empty (but the catalog block name changes just fine, it's just that the translated terms are not displayed as they do when browsing a product).

You don't have this problem? I even used the files you attached but it get the same results.

Not sure if it's the same problem, but when I'm on a category page like www.example.com/catalog/new-releases (in english), all products are listed just fine and everything works great. If I change the language while on that page, I end up in www.example.com/es/catalog/new-releases but no products are listed!! The Catalog block is empty (only 'Catálogo' instead of Catalog).

I would need to solve those problems as we only have the site in english right now :/

Thanks in advance!

joaogarin's picture
Offline
Joined: 07/14/2010
Juice: 21
Changing Language problem

Almost working! thank you alexku for your excelent help!

"When I'm on a product page, I can change between English, Spanish and Catalan and the Catalog changes it's block name and the terms show it's translated term, so perfect!
But when I'm on a term page, or the home page or any other page (about us, etc...) and I change the language to Spanish or Catalan, the Catalog block is empty (but the catalog block name changes just fine, it's just that the translated terms are not displayed as they do when browsing a product).

You don't have this problem? I even used the files you attached but it get the same results.

Not sure if it's the same problem, but when I'm on a category page like www.example.com/catalog/new-releases (in english), all products are listed just fine and everything works great. If I change the language while on that page, I end up in www.example.com/es/catalog/new-releases but no products are listed!! The Catalog block is empty (only 'Catálogo' instead of Catalog).

I would need to solve those problems as we only have the site in english right now :/

Thanks in advance!
"

Did you ever got to fix this?

Thanks in advance!

alexku's picture
Offline
Joined: 10/06/2009
Juice: 50
Re: Translation of terms not shown on homepage, etc...

Unfortunately or fortunately Smiling I don't have such problems and this makes it very hard to help you. Did you ever solve your problems?

miraclegr's picture
Offline
Joined: 04/27/2010
Juice: 36
Few things not working...

Thanks for the excellent work.
Almost everything works fine except a few things.

The block title remains untranslated and becomes a link to the top level catalog page although this setting is not checked from the catalog settings.
I noticed thet after your code the variable $subject is set again, resulting in not using your translation code at all.

I modified the code you mention in function uc_catalog_block as follows and now it works fine.

// code from you start
$catalog_name = variable_get('uc_catalog_name', 'Catalog');
$catalog_id = variable_get('uc_catalog_id', '1');
$translated_name = tt("taxonomy:vocabulary:$catalog_id:name", $catalog_name, NULL, FALSE);
//$subject = l($translated_name, variable_get('uc_catalog_url', 'catalog'));
// code from you end

// new line
$subject = $translated_name; // don't create a link by default

// old code
//$subject = variable_get('uc_catalog_name', t('Catalog'));

An other problem is with breadcrumb. When I have multiple subcategories, the parents in between the top level parent and the last selected term are not translated either. In the block everything works fine.
This happens only when displaying a category page. When displaying a product everything works fine.

I'm using drupal 6.16 and uc 2.2

miraclegr's picture
Offline
Joined: 04/27/2010
Juice: 36
Solved the breadcrumb issue

After a few tries I have managed to find a solution for the breadcrumb issue I had.

In the uc_catalog.module, after the "$current = array_pop($parents);" line I added:

      $current->name = tt("taxonomy:term:$current->tid:name", $current->name, NULL, FALSE);
      if ($current->description) {
        $current->description = tt("taxonomy:term:$current->tid:description", $current->description, NULL, FALSE);
      }

So now I get the translated term wherever I am.

wqmeng's picture
Offline
Joined: 07/12/2008
Juice: 33
typo error

Hi, all

I have also the translation problem and It's great to find your solution.

While from you code , the 'uc_catalog_id', In my ubercart 2.2 , It is uc_catalog_vid in the variables Table.

So please confirm for it. All the variable_get('uc_catalog_id', '1') should be variable_get('uc_catalog_vid', '1')

alexku's picture
Offline
Joined: 10/06/2009
Juice: 50
I confirm

Hi wqmeng, you are right. Check for the corrected version below. Thank you Smiling

ermannob's picture
Offline
Joined: 07/20/2010
Juice: 14
Re: How to translate the taxonomy terms in Calatolg block?

Thanks alexku and miraclegr. Your patches work fine also on UC 2.3.

Thanks a lot!

alexku's picture
Offline
Joined: 10/06/2009
Juice: 50
Newest updated version

Updated version which includes fixes by miraclegr (#11 & #12) and fixes for the bug found by wqmeng (#13)

uc_catalog.pages.inc file:

added the following code (to translate catalog name and desc on the catalog page and category name and desc on a category page) after line "$catalog = uc_catalog_get_page((int)$tid);"

<?php
//check if we are on the catalog or on the category page
if (!$catalog->tid) {
   
//if on catalog page
   
$catalog->name = tt("taxonomy:vocabulary:$catalog->vid:name", $catalog->name, NULL, FALSE);
    if (
$catalog->description) {
       
$catalog->description = tt("taxonomy:vocabulary:$catalog->vid:description", $catalog->description, NULL, FALSE);
    }
}
else {
   
//if on category (term) page
   
$catalog->name = tt("taxonomy:term:$catalog->tid:name", $catalog->name, NULL, FALSE);
    if (
$catalog->description) {
       
$catalog->description = tt("taxonomy:term:$catalog->tid:description", $catalog->description, NULL, FALSE);
    }
}
?>

added the following code (to translate term names in catalog) after line "foreach ($catalog->children as $child) {"

<?php

$child

->name = tt("taxonomy:term:$child->tid:name", $child->name, NULL, FALSE);
if (
$child->description) {
   
$child->description = tt("taxonomy:term:$child->tid:description", $child->description, NULL, FALSE);
}
?>

uc_catalog.module file:
function uc_catalog_nodeapi:

added the following code (to translate catalog name in breadcrumb) after line "if (count($terms)) {" replacing line "$crumbs[] = l(variable_get('uc_catalog_name', t('Catalog')), variable_get('uc_catalog_url', 'catalog'));"

<?php

  $catalog_name

= variable_get('uc_catalog_name', 'Catalog');
 
$catalog_id = variable_get('uc_catalog_vid', '1');
 
$translated_name = tt("taxonomy:vocabulary:$catalog_id:name", $catalog_name, NULL, FALSE);
 
$crumbs[] = l($translated_name, variable_get('uc_catalog_url', 'catalog'));
?>

added the following code (to translate term names in breadcrumb) after line "foreach (array_reverse($parents[$term->tid]) as $parent) {"

<?php

$parent

->name = tt("taxonomy:term:$parent->tid:name", $parent->name, NULL, FALSE);
if(
$parent->description){                               
 
$parent->description = tt("taxonomy:term:$parent->tid:description", $parent->description, NULL, FALSE);
}
?>

function uc_catalog_block:
added the following code (to translate the name of the catalog block) after line "$content = theme('uc_catalog_block', $menu_tree);"

<?php

        $catalog_name

= variable_get('uc_catalog_name', 'Catalog');
   
$catalog_id = variable_get('uc_catalog_vid', '1');
   
$subject = tt("taxonomy:vocabulary:$catalog_id:name", $catalog_name, NULL, FALSE);

?>

function uc_catalog_set_breadcrumb:
added the following code (to translate term names in the breadcrumb) after line "if ($tid != 0) {" replacing line "$breadcrumbs[] = l(variable_get('uc_catalog_name', t('Catalog')), 'catalog');"

<?php

$catalog_name

= variable_get('uc_catalog_name', 'Catalog');
$catalog_id = variable_get('uc_catalog_vid', '1');
$translated_name = tt("taxonomy:vocabulary:$catalog_id:name", $catalog_name, NULL, FALSE);
$breadcrumbs[] = l($translated_name, variable_get('uc_catalog_url', 'catalog'));
?>

added the following code (to translate term names in the breadcrumb) after line "$current = array_pop($parents);"

<?php
      $current
->name = tt("taxonomy:term:$current->tid:name", $current->name, NULL, FALSE);
      if (
$current->description) {
        
$current->description = tt("taxonomy:term:$current->tid:description", $current->description, NULL, FALSE);
      }
?>

function _uc_catalog_navigation:
added the following code (to translate term names in the catalog block) after line "static $types;"

<?php
if ($branch->tid) {
   
$branch->name = tt("taxonomy:term:$branch->tid:name", $branch->name, NULL, TRUE);
    if (
$branch->description) {
       
$branch->description = tt("taxonomy:term:$branch->tid:description", $branch->description, NULL, FALSE);
    }
}
?>

Hope this helps Smiling

alexku's picture
Offline
Joined: 10/06/2009
Juice: 50
template.php version

Actually I have moved all my code to template.php file because it is easier for me to maintain updates this way. But It's quite hackish and should be used with care Smiling Attached it below and hope it will help someone.

AttachmentSize
multilingual_uc_catalog_template.txt 14.65 KB
ermannob's picture
Offline
Joined: 07/20/2010
Juice: 14
Thanks alexku! I put your

Thanks alexku!
I put your code in a custom module with the right theme name and it works!

I took a moment to update your code to make it work with i18n 6.x-1.5. [function i18nstrings_tt() has been renamed to i18nstrings()]

AttachmentSize
multilingual_uc_catalog_template.txt for i18 6.x-1.5 14.61 KB
kellogs's picture
Offline
Joined: 02/11/2010
Juice: 57
Re: How to translate the taxonomy terms in Calatolg block?

Per interest, why was that patch never submitted for review to Ubercart core on Drupal.org?

I rolled out a patch with your modifications and submitted it to Ubercart core on Drupal.

If you would like to test and improve the patch, please follow this link:
http://drupal.org/node/951760