catalog/controller/event/autotranslater.php

(开头部分) 5KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

<?php

class ControllerEventAutotranslater extends Controller
{
    public static $no_translate_key = ['href','addresses','code','languages','thumb'];
    public static $lang_map = ['en-gb' => 'en', 'zh-cn' => 'zh'];

    // catalog/view/*/before 视图解释钱翻译
    public function index(&$route, &$args, &$output)
    {
        $in_local = $this->config->get('config_autotrans_inlocal');
        $is_auto_trans = $this->config->get('config_is_auto_translate') && $this->config->get('config_trans_api_url') ? true : false; //是否开启自动翻译
        $break_route = ['common/','extension/'];
        $need_route = ['common/home','common/maintenance','extension/d_blog_module'];
        if (!$is_auto_trans || $in_local) {
            return;
        }
        $from = 'en';
        $to = $this->session->data['language'];
        foreach ($break_route as $item){
            if(stripos($route,$item) !== false && !$this->isNeedTrans($route,$need_route)){
                return;
            }
        }

        if (!empty(self::$lang_map[$to])) {
            $to = self::$lang_map[$to];
        }
        if ($from != $to) {
            $need_trans = [];
            $this->gettrans($args, $need_trans);
            $trans_data = $this->api_trans($need_trans, $from, $to,$route);
            $i = 0;
            $this->translate($args, $trans_data, $i);
        }

    }

    //view/*/after 整页翻译
    public function after(&$route, &$args, &$output) {
        $in_local = $this->config->get('config_autotrans_inlocal');
        $is_auto_trans = $this->config->get('config_is_auto_translate') && $this->config->get('config_trans_api_url') ? true : false; //是否开启自动翻译
        $break_route = ['common/', 'extension/'];
        $need_route = ['common/home', 'common/maintenance', 'extension/d_blog_module'];
        if (!$is_auto_trans || $in_local) {
            return;
        }
        $from = 'en';
        $to = $this->session->data['language'];
        foreach ($break_route as $item) {
            if (stripos($route, $item) !== false && !$this->isNeedTrans($route, $need_route)) {
                return;
            }
        }
        if(!empty($output) && is_string($output)){
            $trans_data = $this->api_trans($output, $from, $to,$route);
            $output = $trans_data?:$output;
        }
    }

后面还有 72 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。