dpv21589 2013-04-01 18:30
浏览 19

更改语言更改Opencart的徽标

I am trying to make the main logo of the store change when I change language. My company has a different name in english (originally in French).

Here's the code I have :

I have changed (in catalog/view/theme/yourtheme/template/common/header.tpl)

 <?php if ($logo) { ?>
  <div id="logo"><a href="<?php echo $home; ?>"><img src="<?php echo $logo; ?>" title="<?php echo $name; ?>" alt="<?php echo $name; ?>" /></a></div>
  <?php } ?>

For :

<?php
if($lang == 'fr'){
$logo = 'image/data/Lg_Axesoirs_Blanc_FR_PNG.png';
} elseif($lang == 'en'){
$logo = 'image/data/Lg_Axesoirs_Blanc_EN_PNG.png';
}
?> 
<?php if ($logo) { ?>
<div id="logo"><a href="<?php echo $home; ?>"><img src="<?php echo $logo; ?>" title="<?php echo $name; ?>" alt="<?php echo $name; ?>" /></a></div>
<?php } ?>

But it's not working, the logo does not change, but I don't understand what's wrong in my code.

Thanks!

  • 写回答

3条回答 默认 最新

  • dqys98341 2013-04-01 20:03
    关注

    Go into the admin of OpenCart to the languages section and edit a language. Look in the URL for something like language_id=1. Make a note of the language ID for each language.

    In your code, put the following:

    <?php
    
    // $this->config->get('config_language_id') returns the language ID currently active for the session
    
    switch ($this->config->get('config_language_id')) {
    
     case 1 : // Replace the "1" with your English language ID
       // The English logo
       $logo = 'image/data/Lg_Axesoirs_Blanc_EN_PNG.png';
       break;
    
     case 2 : // Replace the "2" with your French language ID
       // The French logo
       $logo = 'image/data/Lg_Axesoirs_Blanc_FR_PNG.png';
       break;
    
     default :
        // The default logo if none of the above cases match
       $logo = 'image/data/Lg_Axesoirs_Blanc_EN_PNG.png';
    
    }
    ?>
    
    <?php if ($logo) { ?>
    <div id="logo">
       <a href="<?php echo $home; ?>">
           <img src="<?php echo $logo; ?>" title="<?php echo $name; ?>" alt="<?php echo $name; ?>" />
       </a>
    </div>
    <?php } ?>
    

    As a note, this logic should really be in a controller rather than in a template view file. OpenCart doesn't let you extend core controllers so don't worry too much about putting it in the view, but if you want to do it properly have a look at something like vQmod to insert it into the controller.

    (Slightly off topic; there's a vQmod-ish-type-thing built in to an upcoming version of OpenCart which should hopefully let you edit the controllers without being dirty and downloading vQmod - but I couldn't say how long it'll be till that's released).

    Hope that helps!

    评论

报告相同问题?