2lenet/easyadmin-plus-bundle
EasyAdminPlus is packaged with an action to manage all your translations files directly in the admin area.
# config/packages/lle_easyadmin_plus.yaml
lle_easy_admin_plus:
translator:
# defines the locales you want to manage
locales:
- fr
- en
# defines the directories in which you want to extract translations files
paths:
- /translations
- ...
# defines a list of domains you want to exclude from admin
excluded_domains:
- validators
- ...
All the settings are optional.
If you don't provide them, the Translator will extract files located in the default Symfony 4 translations directory (/translations) and only work with your default locale (locale parameter or kernel.default_locale if not set)
Add the lle_easy_admin_plus_translations route in the menu attribute of the EasyAdmin configuration file.
# config/packages/easy_admin.yaml
easy_admin:
site_name: Your website
design:
# ...
menu:
# ...
- { route: 'lle_easy_admin_plus_translations', label: 'Translations', icon: 'globe' }
Just browse /admin/translations or click on your item in the EasyAdmin menu.
You can switch the current domain to manage.
You've a list of:
action.save is exploded into action > save for user readability)Eg: several files
Eg: classic case with only one file
The grid uses a display: flex layout, so every translation value will be floated.
You can submit and save your changes by clicking on the button located in the sticky bottom bar.
The entire action is also responsive:
The Translator manage all the translations formats supported by Symfony (yaml, xlf, json, ts, php, po, mo, ini, csv).
It preserves the original file format when committing the changes.
All the files are backuped according to the Symfony convention (eg: messages.en.xlf~) before the erasing task is complete.
The Translator list all the translations files in the directories paths provided, excludes unwanted domains if needed and extracts the distinct files and all the keys from the dictionaries.
Notes:
When submitting the form, files on the current domain are backuped and erased with your changes.
Message is added in session flashbag and translations' cache dir (kernel.cache_dir) is cleared for production use before forwarding on GET.
The Translator component dispatchs two events.
The event is dispatched when an admin accesses the form on a specific domain.
use Symfony\Component\EventDispatcher\GenericEvent;
use Lle\EasyAdminPlusBundle\Translator\Event\EasyAdminPlusTranslatorEvents;
$this->get('event_dispatcher')->dispatch(EasyAdminPlusTranslatorEvents::PRE_TRANSLATE,
new GenericEvent($domain, [
'domain' => $domain,
'user' => [
'username' => $user ? $user->getUsername() : null,
'roles' => $user ? $user->getRoles() : [],
],
])
);
The event is dispatched when an admin submits the form on a specific domain.
use Symfony\Component\EventDispatcher\GenericEvent;
use Lle\EasyAdminPlusBundle\Translator\Event\EasyAdminPlusTranslatorEvents;
$this->get('event_dispatcher')->dispatch(EasyAdminPlusTranslatorEvents::POST_TRANSLATE,
new GenericEvent($domain, [
'domain' => $domain,
'files' => $fileNames,
'user' => [
'username' => $user ? $user->getUsername() : null,
'roles' => $user ? $user->getRoles() : [],
],
])
);
use Lle\EasyAdminPlusBundle\Translator\Event\EasyAdminPlusTranslatorEvents;
class EasyAdminPlusSubscriber implements EventSubscriberInterface
{
/**
* [@return](https://github.com/return) array
*/
public static function getSubscribedEvents()
{
// return the subscribed events, their methods and priorities
return array(
EasyAdminPlusTranslatorEvents::PRE_TRANSLATE => 'logAccess',
EasyAdminPlusTranslatorEvents::POST_TRANSLATE => 'clearVarnishCache',
);
}
/**
* Log admin access
*
* [@param](https://github.com/param) GenericEvent $event event
*/
public function logAccess(GenericEvent $event): bool
{
$domain = $event->getArguments()['domain'];
$user = $event->getArguments()['user'];
# your logic
}
/**
* Clear Varnish Cache
*
* [@param](https://github.com/param) GenericEvent $event event
*/
public function clearVarnishCache(GenericEvent $event): bool
{
$domain = $event->getArguments()['domain'];
$files = $event->getArguments()['files'];
$user = $event->getArguments()['user'];
# your logic
}
Next chapter: Chapter 4 - ACL
How can I help you explore Laravel packages today?