abenmada / sylius-translation-plugin
该插件通过引入基于渠道的翻译功能并适应后台主题的视觉外观来增强Lexik翻译包。
v1.0.3
2024-10-01 07:55 UTC
Requires
- php: ^8.0
- lexik/translation-bundle: ^6.0
- sylius/sylius: ^1.12
Requires (Dev)
- behat/behat: ^3.6.1
- behat/mink-selenium2-driver: ^1.4
- dmore/behat-chrome-extension: ^1.3
- dmore/chrome-mink-driver: ^2.7
- friends-of-behat/mink: ^1.8
- friends-of-behat/mink-browserkit-driver: ^1.4
- friends-of-behat/mink-debug-extension: ^2.0.0
- friends-of-behat/mink-extension: ^2.4
- friends-of-behat/page-object-extension: ^0.3
- friends-of-behat/suite-settings-extension: ^1.0
- friends-of-behat/symfony-extension: ^2.1
- friends-of-behat/variadic-extension: ^1.3
- friendsofphp/php-cs-fixer: ^3.9
- phpspec/phpspec: ^7.2
- phpstan/extension-installer: ^1.0
- phpstan/phpstan: ^1.8.1
- phpstan/phpstan-doctrine: 1.3.40
- phpstan/phpstan-strict-rules: ^1.3.0
- phpstan/phpstan-webmozart-assert: ^1.2.0
- phpunit/phpunit: ^9.5
- polishsymfonycommunity/symfony-mocker-container: ^1.0
- sylius-labs/coding-standard: ^4.2
- symfony/browser-kit: ^5.4 || ^6.0
- symfony/debug-bundle: ^5.4 || ^6.0
- symfony/dotenv: ^5.4 || ^6.0
- symfony/flex: ^2.2.2
- symfony/intl: ^5.4 || ^6.0
- symfony/web-profiler-bundle: ^5.4 || ^6.0
- vimeo/psalm: 4.30.0
README
该插件通过引入基于渠道的翻译功能并适应后台主题的视觉外观来增强Lexik翻译包。
详细信息
显示的区域设置取决于您的渠道配置。在本例中,我们选择了法语和英语。
因此,只为该渠道显示这两种语言。
您还有一个预览页面,可以查看每个区域设置的缺失翻译数量。
重要
- 显示内容的优先级如下:首先,显示渠道特定的翻译,然后,如果没有提供,显示存储在您的数据库中的全局翻译,最后,如果都没有,显示翻译文件中的翻译。
- 您可以在单个页面上管理所有渠道的翻译。当您在渠道之间切换时,将显示此渠道定义的区域设置。
安装
⚠️ 确保您没有在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