dongsibao8977 2015-09-03 08:05
浏览 39
已采纳

用模块覆盖模板的英文翻译

I need to override a class and a template. To achieve this, I choose to create a new module in order to not be blocked when Prestashop will update. For overriding class, I don't have problem.

The worry is in overriding template, fields are in English whereas in the rest of my website, they are in French (when I uninstall the module, they come back in French).

In my module, I override the template with this way :

public function hookDisplayOverrideTemplate($params)
    {
        $controllerName = get_class($params['controller']);
        $tpl = $this->local_path . 'override/tpl/' . $controllerName . '.tpl';
        if (file_exists($tpl))
        {
            return $tpl;
        }
        return false;
    }

In my .tpl file, the fields which are not translate are like this :

{l s='Your addresses'}

So, I tried to insert the fr.php file in /my_module/translations/fr.php, and I edited it :

<?php
global $_MODULE;
$_MODULE = array();
$_MODULE['<{customaddresses}prestashop>customaddresses_3908e1afa0ff22fbf112aff3c5ba55c1'] = 'Vos adresses';

Then, I modified the .tpl file :

{l s='Your addresses' mod='customaddresses'}

My fields are still in English. Someone has a solution to suggest ?

  • 写回答

1条回答 默认 最新

  • duangan4070 2015-09-04 08:41
    关注

    After a great deal of research, I found my problem.

    My solution is : $_MODULE['<{customaddresses}prestashop>address_0f68b904e33d9ac04605aecc958bcf52'] = 'Informations supplémentaires';

    I replaced "customaddresses_" by "address_" (my overriding template).

    I kept :

    {l s='Your addresses' mod='customaddresses'}
    

    And to be more proper, I changed a little bit my method hookDisplayOverrideTemplate :

    public function hookDisplayOverrideTemplate($params)
    {
        $controllerName = get_class($params['controller']);
        $tpl = $this->local_path . 'override/tpl/' . strtolower(str_replace("Controller", "", $controllerName)) . '.tpl';
        if (file_exists($tpl))
        {
            return $tpl;
        }
        return false;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题