Prestashop:我如何向模块字段添加翻译选项?

时间:2014-07-02 11:57:50

标签: php prestashop prestashop-1.6

我有prestashop的自定义字段模块。 并且我想在图片上添加语言翻译字段

enter image description here

我们如何做到这一点?

这是代码

<?php
if (!defined('_PS_VERSION_'))
    exit;
class customfield extends Module
{
    private $_hooks = array(       
        'displayBackOfficeHeader',
        'extrainformation',
        'actionPaymentConfirmation',
        'displayHeader'
        );        
    public function __construct()
    {
        $this->name = 'customfield';
        $this->tab = 'front_office_features';
        $this->version = '1.0';
        $this->author = 'PrestashopStore.net';
        $this->need_instance = 0;

        parent::__construct();

        $this->displayName = $this->l('Custom fields');
        $this->description = $this->l('Allow customer to add custom comment to their order');
        $this->confirmUninstall = $this->l('Are you sure you want to uninstall module?');
    }    
    public function install()
    {
        $langs = Language::getLanguages();
        $id_lang = (int)Configuration::get('PS_LANG_DEFAULT');

        $parent_id = Tab::getIdFromClassName("AdminTools");

        $tab = new Tab();
        $tab->class_name = "AdminCustomfield";
        $tab->module = $this->name;
        $tab->id_parent = $parent_id; 
        foreach($langs as $l){
            $tab->name[$l['id_lang']] = $this->l('Custom field');
        }

        $tab->save();
        if (!parent::install() || !$this->initDb())
            return false;
        foreach ($this->_hooks as $hook) {
            if(!$this->registerHook($hook)) return false;
        }
        return true;
    }
    public function initDb(){
        return true;
    }

    public function uninstall()
    {
       $tab_id = Tab::getIdFromClassName("AdminCustomfield");
        if($tab_id){
            $tab = new Tab($tab_id);
            $tab->delete();
        }
        if (!parent::uninstall()) return false;
        return true;
    }
    public function hookDisplayHeader($params)
    {
        $this->context->controller->addJS($this->_path.'ajax.js');
    }
    public function getContent()
    {
       if(Tools::isSubmit('save_customfield')){
           $label = addslashes(Tools::getValue('add_label'));
           $content = addslashes(Tools::getValue('add_content'));
           $label2 = Tools::getValue('add_label2');
           $sql="select *from "._DB_PREFIX_."custom_field";
           $resul =Db::getInstance()->executeS($sql);
           if(!$resul){
                $sql="insert into "._DB_PREFIX_."custom_field(id,label,conten,label2) values('','$label','$content','$label2')";
                $resul=Db::getInstance()->execute($sql);
           }
           else{
                $sql="update "._DB_PREFIX_."custom_field set label='$label',conten ='$content',label2='$label2'";
                $resul =Db::getInstance()->execute($sql);
           }
       }
       $sql="select *from "._DB_PREFIX_."custom_field";
       $custom =Db::getInstance()->getRow($sql);               
       $this->context->smarty->assign('custom',$custom);
       $this->context->smarty->assign('content',$content);
       return $this->display(__FILE__,'customfield.tpl');
    } 
    public function hookDisplayBackOfficeHeader()
    {
        Tools::addCSS((__PS_BASE_URI__).'modules/'.$this->name.'/css/customfield.css', 'all');      
    }
    public function hookExtrainformation(){
        $sql="select *from "._DB_PREFIX_."custom_field";
        $id_customer = $this->context->customer->id;
        $id_cart = $this->context->cart->id;
        $customfield =Db::getInstance()->getRow($sql);
        $sql ="select content from "._DB_PREFIX_."custom_content where id_cart =$id_cart";
        $content=Db::getInstance()->getRow($sql);
        $this->context->smarty->assign('content',$content);
        $this->context->smarty->assign('customfield',$customfield);
        return $this->display(__FILE__,'extrainformation.tpl');
    }
 }

您可以在此处找到代码http://www.a2b4.net/customfield.txt所有模块 http://www.a2b4.net/customfield.rar

1 个答案:

答案 0 :(得分:0)

显示的标记是您在Frontization&gt; Localization下的Front Office中启用的语言。翻译工具位于Back-Office&gt; Localization&gt; Translations中。当您单击该标志时,它将转到所有翻译所在的页面。从那里,您可以根据您单击的标记/语言手动更改翻译。