setono/sylius-fragment-translation-plugin

Will translate fragments of text automatically


README

Latest Version Latest Unstable Version Software License Build Status

Will translate fragments of text automatically.

Installation

Step 1: Install dependencies

This plugin uses the Doctrine ORM Batcher bundle. Install that first.

Step 2: Download the plugin

Open a command console, enter your project directory and execute the following command to download the latest stable version of this plugin:

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

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Step 3: Enable the plugin

Then, enable the plugin by adding it to the list of registered plugins/bundles in config/bundles.php file of your project before (!) SyliusGridBundle:

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

Step 4: Configure plugin

First import the general configuration:

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

Then configure what resources you want to 'fragment translate':

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

Step 5: Import routing

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

Step 6: Update your database schema

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

Step 7: Using asynchronous transport (optional, but recommended)

All commands in this plugin will extend the CommandInterface. Therefore you can route all commands easily by adding this to your Messenger config:

# 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/doc/current/messenger.html#transports-async-queued-messages
            'Setono\SyliusFragmentTranslationPlugin\Message\Command\CommandInterface': async

Usage

Step 1: Create a fragment translation

Go to /admin/fragment-translations/new and try to input:

Step 2: Run CLI command

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

If you look in your database you should now have Danish translations for the products with names containing Sticker and the names should have been translated into Klistermærke.

Step 3: Using asynchronous transport (recommended)

# 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