abenmada/sylius-translation-plugin

该插件通过引入基于渠道的翻译功能并适应后台主题的视觉外观来增强Lexik翻译包。


README

该插件通过引入基于渠道的翻译功能并适应后台主题的视觉外观来增强Lexik翻译包

详细信息

显示的区域设置取决于您的渠道配置。在本例中,我们选择了法语和英语。

presentation photo

因此,只为该渠道显示这两种语言。

presentation photo

您还有一个预览页面,可以查看每个区域设置的缺失翻译数量。

presentation photo

重要

  • 显示内容的优先级如下:首先,显示渠道特定的翻译,然后,如果没有提供,显示存储在您的数据库中的全局翻译,最后,如果都没有,显示翻译文件中的翻译。
  • 您可以在单个页面上管理所有渠道的翻译。当您在渠道之间切换时,将显示此渠道定义的区域设置。

安装

⚠️ 确保您没有在MySQL模式中启用 ONLY_FULL_GROUP_BY,否则请将其删除!要检查模式,请执行以下SQL查询:SELECT @@sql_mode

通过composer需要插件

composer require abenmada/sylius-translation-plugin

更改您的 config/bundles.php 文件以添加插件的行

<?php

return [
    //..
    Lexik\Bundle\TranslationBundle\LexikTranslationBundle::class => ['all' => true],
    Abenmada\TranslationPlugin\TranslationPlugin::class => ['all' => true],
]

然后在 config/packages/abenmada_translation_plugin.yaml 中创建配置文件

imports:
    - { resource: "@TranslationPlugin/Resources/config/services.yaml" }

然后导入路由 config/routes/abenmada_translation_plugin.yaml

abenmada_translation_plugin_routing:
    resource: "@TranslationPlugin/Resources/config/routes.yaml"
    prefix: /%sylius_admin.path_name%/translations

更新实体 src/Entity/Channel/Channel.php

<?php

declare(strict_types=1);

namespace App\Entity\Channel;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Abenmada\TranslationPlugin\Model\Channel\ChannelTrait as AbenmadaTranslationChannelTrait;
use Sylius\Component\Core\Model\Channel as BaseChannel;

/**
 * @ORM\Entity
 * @ORM\Table(name="sylius_channel")
 */
class Channel extends BaseChannel
{
    use AbenmadaTranslationChannelTrait;

    public function __construct()
    {
        $this->channelTranslations = new ArrayCollection();
        parent::__construct();
    }
}

运行迁移

bin/console doctrine:migration:migrate

安装资产

bin/console assets:install --ansi

将翻译文件内容导入您的数据库

bin/console lexik:translations:import

管理区域设置

  • 默认支持的区域设置包括:英语(en)、法语(fr)、阿拉伯语(ar)、德语(de)、西班牙语(es)、波兰语(pl)、葡萄牙语(pt)和意大利语(it)。
  • 您可以通过提供的配置选项调整语言设置。
lexik_translation:
    fallback_locale: [ '%locale%' ]                     # default locale(s) to use
    managed_locales: [ en, fr, ar, de, es, pl, pt, it ] # locale(s) that the bundle has to manage