2017 © Pedro Peláez
 

symfony-bundle translation-bundle

Provides a database storage for translations and GUI for editing them

image

argentum/translation-bundle

Provides a database storage for translations and GUI for editing them

  • Friday, November 24, 2017
  • by javer
  • Repository
  • 2 Watchers
  • 5 Stars
  • 950 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 2 % Grown

The README.md

ArgentumTranslationBundle

SensioLabsInsight Build Status Coverage Status Latest Stable Version License, (*1)

ArgentumTranslationBundle provides a database storage for translations and GUI for editing them., (*2)

This bundle supports PHP 5.4+ and Symfony 2.3+., (*3)

The bundle combines the power of the following bundles:, (*4)

Installation

Install the bundle with composer:, (*5)

composer require argentum/translation-bundle:dev-master

Register the bundle in app/AppKernel::registerBundles():, (*6)

$bundles = array(
    // ...
    new Argentum\TranslationBundle\ArgentumTranslationBundle(),
    // ...
);

Configuration

In the parameters.yml you should configure a list of locales:, (*7)

parameters:
    locales:
        - ru
        - uk
        - en

Then in the config.yml you should add the following options:, (*8)

a2lix_translation_form:
    locales: %locales%

argentum_translation:
    locales: %locales%

Make sure you have registered KnpLabs DoctrineBehaviors Listeners in your config.yml:, (*9)

imports:
    - { resource: ../../vendor/knplabs/doctrine-behaviors/config/orm-services.yml }

and have registered A2lixTranslationFormBundle in app/AppKernel::registerBundles():, (*10)

$bundles = array(
    // ...
    new A2lix\TranslationFormBundle\A2lixTranslationFormBundle(),
    // ...
);

And finally, create translation tables in your database:, (*11)

app/console doctrine:schema:update --force

or create a migration and execute it:, (*12)

app/console doctrine:migrations:diff
app/console doctrine:migrations:migrate

Translation editor

Now you can use GUI for editing the translations., (*13)

The bundle will automatically add additional items in the menu of your Sonata Admin. If you have customized the menu, you should add Translation group in config.yml:, (*14)

sonata_admin:
    dashboard:
        groups:
            // ...
            Translation: ~

The list of all domains is located at URL something like (depends on the base location of Sonata Admin in your project): /admin/argentum/translation/translationdomain/list., (*15)

Loading order

When merging all translations together translations from files in all bundles will be loaded, and then all translations from the database will be loaded. Thus, translations from the database can override any translation from the translation files in your project., (*16)

Proposed workflow

Firstly, when developing your project you should use admin panel to create all necessary domains and add all necessary translations to them., (*17)

Secondly, when your bundle is ready, you should export all translations for the bundle domain into the bundle translation files and commit them to VCS., (*18)

And finally, when your project is started, you or your client can edit any translation without need to edit project files., (*19)

Cache

All translations are cached in the cache files and will be loaded from the database only once after clearing the cache., (*20)

Export

This bundle allows you to export translations from the database for single domain or all domains in the specified directory for the specified locales using the specified format., (*21)

Export all translations to the directory:, (*22)

app/console translation:export --dir=/path/to/translations

Export translations for domain "messages":, (*23)

app/console translation:export --dir=/path/to/translations messages

Export translations for domain "messages" and locales "ru" and "uk" in xliff format:, (*24)

app/console translation:export --dir=/path/to/translations --locales="ru,uk" --format=xlf messages

Import

This bundle allows you to import translations from files into the database., (*25)

Import all translations from the specified directory:, (*26)

app/console translation:import --dir=/path/to/translations

Import translations from the directory only for the domain "messages":, (*27)

app/console translation:import --dir=/path/to/translations messages

Import translations from the directory only for the domain "messages" and locales "ru" and "uk":, (*28)

app/console translation:import --dir=/path/to/translations --locales="ru,uk" messages

Import translations from the specified bundles:, (*29)

app/console translation:import --bundles="SonataAdminBundle, SonataUserBundle"

Import translations from the entire project including all bundles, Form and Validation components, and local application translations:, (*30)

app/console translation:import

The Versions