Muhsin
Muhsin

Reputation: 13

Prestashop how to add static contents in different language in tpl file

I need add some custom text in Prestashop template file, but there are two languages in my store, and I want to add these contents in different language statically? Can I check current language by language id?

Upvotes: 1

Views: 12500

Answers (4)

JoZu
JoZu

Reputation: 1

For Prestashop 1.7 there is the update:

{if ($language.iso_code == "es")}
  <div style="text-align:center;"><img src="spanish-image.jpg"></div>
{else if ($language.iso_code == "en")}

Upvotes: 0

Bruno Leveque
Bruno Leveque

Reputation: 2811

You have multiple ways to achieve this goal depending on the kind of .tpl file you are editing:

  • If it is a .tpl in your Theme, the easiest way is:

    {l s='My text to translate'}

  • If it is .tpl file included in a module, you should do the following:

    {l s='My text to translate' mod='modulename'}

In both situations, PrestaShop will automatically translate these strings into the language currently selected by the end user.

  • If you prefer to manually handle the translation process, you should instead do:

    {if $lang_iso == 'en'}English{else}Other language{/if}

Upvotes: 6

JB Dan
JB Dan

Reputation: 54

statically

    {if $lang_iso == en } 

    english text 
    {else}

    Other language
   {/if}

Upvotes: 3

arifur rahman
arifur rahman

Reputation: 264

If you see on editorial block you will understand how to do that.

you can build a module and then hook that to the perticular area.

and generate the text box like

    /* Gets languages and sets which div requires translations */
    $id_lang_default = (int)Configuration::get('PS_LANG_DEFAULT');
    $languages = Language::getLanguages(false);
    $divLangName = 'image¤title¤url¤legend¤description';


foreach ($languages as $language)
    {
        $this->_html .= '<div id="image_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $id_lang_default ? 'block' : 'none').';float: left;">';
        $this->_html .= '<input type="file" name="image_'.$language['id_lang'].'" id="image_'.$language['id_lang'].'" size="30" value="'.(isset($slide->image[$language['id_lang']]) ? $slide->image[$language['id_lang']] : '').'"/>';
        /* Sets image as hidden in case it does not change */
        if ($slide && $slide->image[$language['id_lang']])
            $this->_html .= '<input type="hidden" name="image_old_'.$language['id_lang'].'" value="'.($slide->image[$language['id_lang']]).'" id="image_old_'.$language['id_lang'].'" />';
        /* Display image */
        if ($slide && $slide->image[$language['id_lang']])
            $this->_html .= '<input type="hidden" name="has_picture" value="1" /><img src="'.__PS_BASE_URI__.'modules/'.$this->name.'/images/'.$slide->image[$language['id_lang']].'" width="'.(Configuration::get('HOMESLIDER_WIDTH')/2).'" height="'.(Configuration::get('HOMESLIDER_HEIGHT')/2).'" alt=""/>';
        $this->_html .= '</div>';
    }

in this way it will save language wise value

Upvotes: 0

Related Questions