src/Controller.php
protected function tagTrans($content)
    {

        $regular = '/{FY:(.*?):(.*?)}/is';
        preg_match_all('/{FY:(.*?):(.*?)}/is', $content, $matches);

        if (array_filter($matches)) {

            //组合翻译结构
            foreach ($matches[0] as $key => $value) {
                $transArray[$matches[2][$key]][] = $matches[1][$key];
            }

            //批量翻译
            if ($transArray) {
                foreach ($transArray as $key => $value) {
                    if ($key != 'zh') {
                        $transValue[$key] = dao('BaiduTrans')->baiduTrans($value, $key, 'zh');
                    } else {
                        foreach ($value as $key => $value) {
                            $transValue['zh'][$value] = $value;
                        }
                    }
                }

                foreach ($transValue as $key => $value) {
                    foreach ($value as $k => $v) {
                        $content = str_replace("{FY:$k:$key}", $v, $content);
                    }
                }
            }

        }

        return $content;
    }
protected function tagTrans($content)
    {

        $regular = '/{FY:(.*?):(.*?)}/is';
        preg_match_all('/{FY:(.*?):(.*?)}/is', $content, $matches);

        if (array_filter($matches)) {

            //组合翻译结构
            foreach ($matches[0] as $key => $value) {
                $transArray[$matches[2][$key]][] = $matches[1][$key];
            }

            //批量翻译
            if ($transArray) {
                foreach ($transArray as $key => $value) {
                    if ($key != 'zh') {
                        $transValue[$key] = dao('BaiduTrans')->baiduTrans($value, $key, 'zh');
                    } else {
                        foreach ($value as $key => $value) {
                            $transValue['zh'][$value] = $value;
                        }
                    }
                }

                foreach ($transValue as $key => $value) {
                    foreach ($value as $k => $v) {
                        $content = str_replace("{FY:$k:$key}", $v, $content);
                    }
                }
            }

        }

        return $content;
    }
标签翻译功能