Will translate fragments of text automatically.
This plugin uses the Doctrine ORM Batcher bundle. Install that first.
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.
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],
];
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
# config/routes/setono_sylius_fragment_translation.yaml
setono_sylius_fragment_translation:
resource: "@SetonoSyliusFragmentTranslationPlugin/Resources/config/routing.yaml"
$ php bin/console doctrine:migrations:diff
$ php bin/console doctrine:migrations:migrate
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
Go to /admin/fragment-translations/new
and try to input:
Field | Value |
---|---|
Locale | da_DK (or any other secondary locale you have created) |
Search string | Sticker |
Replace string | Klistermærke |
$ 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
.
# 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