setono/sylius-fragment-translation-plugin

自动翻译文本片段


README

Latest Version Latest Unstable Version Software License Build Status

自动翻译文本片段。

安装

步骤 1: 安装依赖项

此插件使用了 Doctrine ORM Batcher 包。请先安装它。

步骤 2: 下载插件

打开命令行控制台,进入项目目录,并执行以下命令以下载此插件的最新稳定版本

$ composer require setono/sylius-fragment-translation-plugin

此命令要求您全局安装了 Composer,具体请参阅 Composer 文档的 安装章节

步骤 3: 启用插件

然后,通过将其添加到项目 config/bundles.php 文件中注册的插件/包列表中(在 SyliusGridBundle 之前)来启用该插件。

<?php
$bundles = [
    Setono\SyliusFragmentTranslationPlugin\SetonoSyliusFragmentTranslationPlugin::class => ['all' => true],
    Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true],
];

步骤 4: 配置插件

首先导入通用配置

# config/packages/_sylius.yaml
imports:
    # ...
    - { resource: "@SetonoSyliusFragmentTranslationPlugin/Resources/config/app/config.yaml" }
    # ...

然后配置您想进行 '片段翻译' 的资源

# config/packages/setono_sylius_fragment_translation.yaml
setono_sylius_fragment_translation:
    resource_translations:
        -
            name: sylius.product
            properties:
                - name

步骤 5: 导入路由

# config/routes/setono_sylius_fragment_translation.yaml
setono_sylius_fragment_translation:
    resource: "@SetonoSyliusFragmentTranslationPlugin/Resources/config/routing.yaml"

步骤 6: 更新您的数据库模式

$ php bin/console doctrine:migrations:diff
$ php bin/console doctrine:migrations:migrate

步骤 7: 使用异步传输(可选,但推荐)

此插件中的所有命令都将扩展 CommandInterface。因此,您可以轻松地将所有命令路由到您的 消息传递器配置

# config/packages/messenger.yaml
framework:
    messenger:
        routing:
            # Route all command messages to the async transport
            # This presumes that you have already set up an 'async' transport
            # See docs on how to setup a transport like that: https://symfony.com.cn/doc/current/messenger.html#transports-async-queued-messages
            'Setono\SyliusFragmentTranslationPlugin\Message\Command\CommandInterface': async

使用方法

步骤 1: 创建片段翻译

访问 /admin/fragment-translations/new 并尝试输入

步骤 2: 运行 CLI 命令

$ php bin/console setono:sylius-fragment-translation:translate

如果查看您的数据库,现在应该有包含 Sticker 的产品名称的丹麦语翻译,并且名称应该已经翻译成 Klistermærke

步骤 3: 使用异步传输(推荐)

# config/packages/messenger.yaml
framework:
    messenger:
        routing:
            # Route all command messages to the async transport
            # This presumes that you have already set up an 'async' transport
            'Setono\SyliusFragmentTranslationPlugin\Message\Command\CommandInterface': async