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

匿名 (未验证) 提交于 2019-12-03 03:04:01

问题:

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?

回答1:

statically

    {if $lang_iso == en }       english text      {else}      Other language    {/if} 


回答2:

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}



回答3:

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



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!