Prestashop: как я могу добавить возможность перевода в поля модуля?

У меня есть модуль пользовательского поля для prestashop. И я хочу добавить поля языкового перевода, как на картинке

введите здесь описание изображения

Как мы можем это сделать?

вот код

<?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


person lospicos    schedule 02.07.2014    source источник


Ответы (1)


Появляющиеся флажки — это языки, которые вы включили в своем фронт-офисе в разделе «Локализация»> «Локализация». Инструмент переводов находится в Back-Office>Localization>Translations. Когда вы нажмете на флажок, вы попадете на страницу, где есть все переводы. Оттуда вы можете вручную изменить перевод в зависимости от флага/языка, на который вы нажали.

person Butterback    schedule 02.07.2014
comment
Этот перевод дает только перевод модуля, а не поля. - person lospicos; 03.07.2014