ao / translation-bundle
Doctrine as symfony translation provider + a nice gui for editing translations.
Installs: 2 980
Dependents: 0
Suggesters: 0
Security: 0
Stars: 24
Watchers: 4
Forks: 3
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=5.3
- stof/doctrine-extensions-bundle: ~1.1
- symfony/framework-bundle: ~2.1
Suggests
- sonata-project/admin-bundle: Use translations admin backend.
- sonata-project/doctrine-orm-admin-bundle: Use translations admin backend.
This package is not auto-updated.
Last update: 2024-11-09 15:20:14 UTC
README
This bundle provides doctrine as translations storage and a nice web gui accessible from the profiler for easy translation.
Features
- All translation messages are automatically saved in the database (no extraction necessary)
- Translation panel available in the Symfony web debug toolbar
- Only messages used in current action are loaded from the database
- Translations management backend available via SonataAdminBundle
Installation
Require vendor libraries
Require ao/translation-bundle
& stof/doctrine-extensions-bundle
in composer.json
:
"require": {
"symfony/symfony": "2.1.*",
"_comment": "other packages",
"stof/doctrine-extensions-bundle": "1.1.*@dev",
"ao/translation-bundle": "1.0.*@dev"
}
Then install or update composer bundles with:
php composer.phar install
or
php composer.phar update
Add bundles to your application kernel
In app/AppKernel.php
add:
// app/AppKernel.php
public function registerBundles()
{
return array(
//...
new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(),
new AO\TranslationBundle\AOTranslationBundle()
//...
);
}
Configure translator
# app/config/config.yml
# enable translation component
framework:
translator: ~
# use AOTranslationBundle as translator
parameters:
translator.class: AO\TranslationBundle\Translation\Translator
# configure locales avaliable for translation
ao_translation:
locales:
en: ~
de:
label: German
fr: ~
Configure doctrine extensions bundle
Timestampable behavior has to be enabled.
# app/config/config.yml
stof_doctrine_extensions:
orm:
default:
timestampable: true
Update your db schema
If you use migrations:
app/console doctrine:migrations:diff
app/console doctrine:migrations:migrate
Otherwise:
app/console doctrine:schema:update
Add routing information
# app/config/routing.yml
ao_translation:
resource: "@AOTranslationBundle/Controller/"
type: annotation
prefix: /
Usage
Use translation methods like described in Symfony Translations documentation.
Translations panel
You can access translations panel by clicking on Translations in the web debug toolbar.
Now you can edit all your translation messages.
Message parameters can be inserted directly into translation by clicking on the link in Parameters
(2) column.
After you are done click the Save Translations
button (1).
As the translator needs to know which messages are used in each action, it stores this relation in a cache table.
Therefore, when a message is not used anymore it will still be visible in the translations panel.
To clear the cached messages use the Reset action cache
(3) button, which will clear the cache for current action.
Alternatively use the Reset cache
(4) button, which will clear cache for all actions.
The cache will be rebuilt with the next execution of an action.
Translations backend
In order to use translations backend you need to install SonataAdminBundle and SonataDoctrineORMAdminBundle.
Please refer to their installation guide.
After installation and configuration the backend will be available under /admin/ao/translation/message/list
.
Additional features
Using separate database connection for storing translations
In case you need to share the translations database (eg. when multiple developers collaborate) you can configure separate entity manager for the bundle.
# app/config/config.yml
doctrine:
dbal:
default_connection: default
connections:
default:
...
# configure translations database connection
translations:
...
orm:
...
default_entity_manager: default
entity_managers:
default:
connection: default
mappings:
...
translations:
connection: translations
mappings:
AOTranslationBundle: ~
ao_translation:
entity_manager: translations
stof_doctrine_extensions:
orm:
...
# enable timestampable behavior for translations entity manager
translations:
timestampable: true
To create translations schema add use --em
parameter like:
app/console doctrine:schema:create --em=translations