Astina Translation Bundle
DoctrineLoader to store translations in the database plus simple admin UI to edit translation messages., (*1)
Installation
Step 1: Add to composer.json
"require": {
"astina/translation-bundle":"dev-master",
}
Step 2: Enable the bundle
Enable the bundle in the kernel:, (*2)
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Astina\Bundle\TranslationBundle\AstinaTranslationBundle(),
);
}
Bundle configuration:, (*3)
# app/config/config.yml
astina_translation:
domains: [ messages ]
locales: [ de, fr, it, en ]
admin:
layout_template: ::translation_layout.html.twig
filters:
- { name: filter_common, domain: messages, filter: '!weather% AND !wispo% AND !booking%' }
- { name: filter_weather, domain: messages, filter: 'weather% OR wispo%' }
- { name: filter_booking, domain: messages, filter: 'booking%' }
Routing configuration (if admin UI is needed):, (*4)
# app/config/routing.yml
astina_translation:
resource: "@AstinaTranslationBundle/Resources/config/routing.yml"
prefix: /admin/translations
Usage
You can add/update messages using the translation repository service:, (*5)
$repo = $container->get('astina_translation.repository.translation');
$repo->set('messages', 'foo', 'fr', 'foux');
Note: after adding/changing translations, the cache needs to be cleared., (*6)
If you have added the routing config, you can access /admin/translations
to edit messages stored in the database. The cache is automatically cleared after saving., (*7)
Dumping Translations
You can dump all stored translations to PHP array or JSON string by using the dump command:, (*8)
php app/console astina:translation:dump