Prestashop how to add static contents in different

2019-04-02 11:52发布

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?

标签: prestashop
3条回答
我命由我不由天
2楼-- · 2019-04-02 12:07

statically

    {if $lang_iso == en } 

    english text 
    {else}

    Other language
   {/if}
查看更多
男人必须洒脱
3楼-- · 2019-04-02 12:16

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

查看更多
虎瘦雄心在
4楼-- · 2019-04-02 12:22

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}

查看更多
登录 后发表回答