1. Installation¶
1.1. Download the Bundle¶
1 | composer require sonata-project/translation-bundle
|
1.2. Enable the Bundle¶
Then, enable the bundle by adding it to the list of registered bundles
in bundles.php
file of your project:
// config/bundles.php
return [
// ...
Sonata\TranslationBundle\SonataTranslationBundle::class => ['all' => true],
];
1.3. Configure the Bundle¶
To use the TranslationBundle
, add the following lines to your application configuration file:
- YAML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
# config/packages/sonata_translation.yaml sonata_translation: locales: [en, fr, it, nl, es] default_locale: en # change default behavior for translated field filtering. default_filter_mode: gedmo # must be either 'gedmo' or 'knplabs', default: gedmo # here enable the types you need gedmo: enabled: true # when using gedmo/doctrine-extensions, you have to register a translatable listener # service or if you are using a bundle that integrates the library, it will be registered # by the bundle (e.g. "stof_doctrine_extensions.listener.translatable" for "stof/doctrine-extensions-bundle"). # here you can provide a custom translatable listener service name. translatable_listener_service: Gedmo\Translatable\TranslatableListener knplabs: enabled: true #phpcr: # enabled: true
Key | Description |
---|---|
locales | The list of your frontend locales in which your models will be translatable. |
default_locale | The locale, loaded in your forms by default. |
Note
If you are using the SonatAdminBundle with the SonataDoctrineORMAdminBundle, you should read the ORM chapter. If you are using SonataDoctrinePhpcrAdminBundle, you should read the PHPCR chapter.
1.4. Import the Styles¶
Install SonataTranslationBundle web assets under your public web directory:
1 | bin/console assets:install
|
Add CSS file to your SonataAdminBundle config:
1 2 3 4 5 6 | # config/packages/sonata_admin.yaml
sonata_admin:
assets:
extra_stylesheets:
- bundles/sonatatranslation/css/sonata-translation.css
|
Now, you’re good to go!