PrestaShop:翻译覆盖的控制器 [英] PrestaShop: Translating overrided controller

查看:52
本文介绍了PrestaShop:翻译覆盖的控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个模块来覆盖 AdminProductController.php 并创建一个新的 bulk_action.

I've created a module that overrides an AdminProductController.php and make a new bulk_action.

<?php
class AdminProductsController extends AdminProductsControllerCore
{
    public function __construct()
    {
        parent::__construct();
        $this->bulk_actions['setprice'] = array(
            'text' => $this->l('Set a price for selected'),
            'icon' => 'icon-price',
        );
    }
}

现在我需要翻译动作文本并使用模块分发该翻译.问题是我在模块翻译中看不到原始文本,而是在后台翻译中可见.

Now I need to translate the action text and distribute that translation with module. The problem is that I don't see the original text inside modules translation instead it is visible in back-office translations.

那么,有没有办法将此字符串添加到模块翻译而不是后台翻译?

So, is there any way to add this string to module translations not to back-office translations?

推荐答案

我在这里找到的主要问题描述:如何从 PrestaShop 中的其他模块获取翻译?

The main problem description I've found here: How to get translation from other module in PrestaShop?

这是因为翻译控制器使用正则表达式扫描模块文件夹中的 $this->l((.*)) 并将可翻译字符串添加到文件中所以我们应该在模块中做这样的事情:

This is because translations controller scans for $this->l((.*)) inside module folder using regex and adds the translatable strings to a file So we should in module do something like this:

class MyModule extends Module
{

    public static $l = null;
    public function __construct()
    {
        parent::__construct();
        $this::$l = $this->l('Set a price for selected');
    }
}

比在控制器中我们可以执行@TheDrot 建议的操作:

Than in controller we can do what was suggested by @TheDrot:

class AdminProductsController extends AdminProductsControllerCore
{
    public function __construct()
    {
        parent::__construct();
        $module = Module::getInstanceByName('modulename');
        $this->bulk_actions['setprice'] = array(
            'text' => $module->l('Set a price for selected'),
            'icon' => 'icon-price',
        );
    }
}

这篇关于PrestaShop:翻译覆盖的控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆