Skip to content

#40 Fix localisation issues #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/services/controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ services:
$context: '@EasyCorp\Bundle\EasyAdminBundle\Factory\AdminContextFactory'
$logDirectory: '%kernel.logs_dir%'
$processExecutionRepository: '@cleverage_ui_process.repository.process_execution'
$intlFormatter: '@EasyCorp\Bundle\EasyAdminBundle\Intl\IntlFormatter'
$translator: '@translator'
tags:
- { name: 'controller.service_arguments' }
4 changes: 3 additions & 1 deletion config/services/twig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ services:
cleverage_ui_process.twig.log_level_extension_runtime:
class: CleverAge\UiProcessBundle\Twig\Runtime\LogLevelExtensionRuntime
public: false
calls:
- [setTranslator, ['@translator']]
tags:
- { name: 'twig.runtime' }

Expand Down Expand Up @@ -56,4 +58,4 @@ services:
class: CleverAge\UiProcessBundle\Twig\Components\BootstrapModal
shared: false
tags:
- { name: 'twig.component', key: 'ui:BootstrapModal', template: '@CleverAgeUiProcess/components/BootstrapModal.html.twig' }
- { name: 'twig.component', key: 'ui:BootstrapModal', template: '@CleverAgeUiProcess/components/BootstrapModal.html.twig' }
11 changes: 8 additions & 3 deletions src/Controller/Admin/LogRecordCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function configureFields(string $pageName): iterable
return [
LogLevelField::new('level'),
TextField::new('message')->setMaxLength(512),
DateTimeField::new('createdAt')->setFormat('Y/M/dd H:mm:ss'),
DateTimeField::new('createdAt')->setFormat('short', 'medium'),
ContextField::new('context')
->onlyOnDetail(),
BooleanField::new('contextIsEmpty', 'Has context info ?')
Expand Down Expand Up @@ -87,9 +87,14 @@ public function configureFilters(Filters $filters): Filters
$processList = array_map(fn (ProcessConfiguration $cfg) => $cfg->getCode(), $processList);

return $filters->add(
LogProcessFilter::new('process', $processList, $id)
LogProcessFilter::new('Process', $processList, $id)
)->add(
ChoiceFilter::new('level')->setChoices(array_combine(Level::NAMES, Level::VALUES))
ChoiceFilter::new('level')
->setTranslatableChoices(array_combine(
Level::VALUES,
array_map(fn ($value) => 'enum.log_level.'.strtolower((string) $value), Level::NAMES)
))
->setFormTypeOption('translation_domain', 'enums'),
)->add('message')->add('context')->add('createdAt');
}
}
6 changes: 6 additions & 0 deletions src/Controller/Admin/Process/ListAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace CleverAge\UiProcessBundle\Controller\Admin\Process;

use CleverAge\UiProcessBundle\Manager\ProcessConfigurationsManager;
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Intl\IntlFormatterInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
Expand All @@ -23,12 +24,17 @@
#[IsGranted('ROLE_USER')]
class ListAction extends AbstractController
{
public function __construct(private readonly IntlFormatterInterface $intlFormatter)
{
}

public function __invoke(ProcessConfigurationsManager $processConfigurationsManager): Response
{
return $this->render(
'@CleverAgeUiProcess/admin/process/list.html.twig',
[
'processes' => $processConfigurationsManager->getPublicProcesses(),
'IntlFormatterService' => $this->intlFormatter,
]
);
}
Expand Down
8 changes: 5 additions & 3 deletions src/Controller/Admin/ProcessExecutionCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Security\Http\Attribute\IsGranted;
use Symfony\Contracts\Translation\TranslatorInterface;

#[IsGranted('ROLE_USER')]
class ProcessExecutionCrudController extends AbstractCrudController
{
public function __construct(
private readonly ProcessExecutionRepository $processExecutionRepository,
private readonly string $logDirectory,
private readonly TranslatorInterface $translator,
) {
}

Expand All @@ -52,12 +54,12 @@ public function configureFields(string $pageName): iterable
return [
TextField::new('code'),
EnumField::new('status'),
DateTimeField::new('startDate')->setFormat('Y/M/dd H:mm:ss'),
DateTimeField::new('endDate')->setFormat('Y/M/dd H:mm:ss'),
DateTimeField::new('startDate')->setFormat('short', 'medium'),
DateTimeField::new('endDate')->setFormat('short', 'medium'),
TextField::new('source')->setTemplatePath('@CleverAgeUiProcess/admin/field/process_source.html.twig'),
TextField::new('target')->setTemplatePath('@CleverAgeUiProcess/admin/field/process_target.html.twig'),
TextField::new('duration')->formatValue(function ($value, ProcessExecution $entity) {
return $entity->duration(); // returned format can be changed here
return $entity->duration($this->translator->trans('%H hour(s) %I min(s) %S s')); // returned format can be changed here
}),
ArrayField::new('report')->setTemplatePath('@CleverAgeUiProcess/admin/field/report.html.twig'),
ContextField::new('context'),
Expand Down
10 changes: 9 additions & 1 deletion src/Entity/Enum/ProcessExecutionStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,17 @@

namespace CleverAge\UiProcessBundle\Entity\Enum;

enum ProcessExecutionStatus: string
use Symfony\Contracts\Translation\TranslatableInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

enum ProcessExecutionStatus: string implements TranslatableInterface
{
case Started = 'started';
case Finish = 'finish';
case Failed = 'failed';

public function trans(TranslatorInterface $translator, ?string $locale = null): string
{
return $translator->trans('enum.process_execution_status.'.$this->value, domain: 'enums', locale: $locale);
}
}
10 changes: 9 additions & 1 deletion src/Entity/Enum/ProcessScheduleType.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@

namespace CleverAge\UiProcessBundle\Entity\Enum;

enum ProcessScheduleType: string
use Symfony\Contracts\Translation\TranslatableInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

enum ProcessScheduleType: string implements TranslatableInterface
{
case CRON = 'cron';
case EVERY = 'every';

public function trans(TranslatorInterface $translator, ?string $locale = null): string
{
return $translator->trans('enum.process_schedule_type.'.$this->value, domain: 'enums', locale: $locale);
}
}
1 change: 1 addition & 0 deletions src/Twig/Extension/LogLevelExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function getFunctions(): array
{
return [
new TwigFunction('log_label', [LogLevelExtensionRuntime::class, 'getLabel']),
new TwigFunction('log_translation', [LogLevelExtensionRuntime::class, 'getTranslation']),
new TwigFunction('log_css_class', [LogLevelExtensionRuntime::class, 'getCssClass']),
];
}
Expand Down
13 changes: 13 additions & 0 deletions src/Twig/Runtime/LogLevelExtensionRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,28 @@
namespace CleverAge\UiProcessBundle\Twig\Runtime;

use Monolog\Level;
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Extension\RuntimeExtensionInterface;

class LogLevelExtensionRuntime implements RuntimeExtensionInterface
{
private TranslatorInterface $translator;

public function setTranslator(TranslatorInterface $translator): void
{
$this->translator = $translator;
}

public function getLabel(int $value): string
{
return Level::from($value)->getName();
}

public function getTranslation(string $key): string
{
return $this->translator->trans('enum.log_level.'.strtolower($key), domain: 'enums');
}

public function getCssClass(string|int $value): string
{
return \is_int($value) ?
Expand Down
2 changes: 1 addition & 1 deletion templates/admin/field/enum.html.twig
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{% set class = field.value.value == 'failed' ? 'danger' : 'success' %}
<span class="badge badge-{{ class }}">{{ field.value.value }}</span>
<span class="badge badge-{{ class }}">{{ field.value|trans() }}</span>
2 changes: 1 addition & 1 deletion templates/admin/field/log_level.html.twig
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<span class="badge badge-{{ log_css_class(field.value) }}">{{ log_label(field.value) }}</span>
<span class="badge badge-{{ log_css_class(field.value) }}">{{ log_translation(log_label(field.value)) }}</span>
2 changes: 1 addition & 1 deletion templates/admin/field/report.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
{# @var entity \EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto #}
<ul>
{% for key, item in field.value %}
<li class="list-group-item"><span class="badge badge-{{ log_css_class(key) }}">{{ key }}</span> : {{ item }}</li>
<li class="list-group-item"><span class="badge badge-{{ log_css_class(key) }}">{{ log_translation(key) }}</span> : {{ item }}</li>
{% endfor %}
</ul>
4 changes: 2 additions & 2 deletions templates/admin/process/list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
{% endif %}
<tr>
<td>{{ process.code }}</td>
<td>{% if lastExecution is not null %}{{ lastExecution.startDate|date('Y/m/d H:i:s') }}{% endif %}</td>
<td><span class="badge badge-{{ statusClass }}">{% if lastExecution is not null %}{{ lastExecution.status.value }}{% endif %}</span></td>
<td>{% if lastExecution is not null %}{{ IntlFormatterService.formatDateTime(lastExecution.startDate, 'short', 'medium') }}{% endif %}</td>
<td><span class="badge badge-{{ statusClass }}">{% if lastExecution is not null %}{{ lastExecution.status|trans() }}{% endif %}</span></td>
<td>{% if process.options.ui.source is defined %}{{ process.options.ui.source }}{% endif %}</td>
<td>{% if process.options.ui.target is defined %}{{ process.options.ui.target }}{% endif %}</td>
<td class="text-center">
Expand Down
15 changes: 15 additions & 0 deletions translations/enums.en.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
enum.process_execution_status.started: 'Started'
enum.process_execution_status.finish: 'Finished'
enum.process_execution_status.failed: 'Failed'

enum.process_schedule_type.cron: 'Cron'
enum.process_schedule_type.every: 'Every date'

enum.log_level.debug: 'Debug'
enum.log_level.info: 'Info'
enum.log_level.notice: 'Notice'
enum.log_level.warning: 'Warning'
enum.log_level.error: 'Error'
enum.log_level.critical: 'Critical'
enum.log_level.alert: 'Alert'
enum.log_level.emergency: 'Emergency'
15 changes: 15 additions & 0 deletions translations/enums.fr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
enum.process_execution_status.started: 'Démarré'
enum.process_execution_status.finish: 'Terminé'
enum.process_execution_status.failed: 'Échoué'

enum.process_schedule_type.cron: 'Tâche planifiée'
enum.process_schedule_type.every: 'Chaque date'

enum.log_level.debug: 'Débogage'
enum.log_level.info: 'Information'
enum.log_level.notice: 'Notification'
enum.log_level.warning: 'Avertissement'
enum.log_level.error: 'Erreur'
enum.log_level.critical: 'Critique'
enum.log_level.alert: 'Alerte'
enum.log_level.emergency: 'Urgence'
19 changes: 12 additions & 7 deletions translations/messages.fr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ Timezone: Fuseau horaire
Locale: Locale
ProcessExecution: Exécution des processus
Code: Code
Status: Status
Status: Statut
Start Date: Date de début
End Date: Date de fin
Source: Source
Target: Destination
Duration: Durée
Report: Rapport
Context: Context
Context: Contexte
Launch: Exécuter
View executions: Voir les éxécutions
Process code: Code du processus
Expand All @@ -38,17 +38,22 @@ LogRecord: Logs
Level: Niveau
Message: Message
Created At: Date de création
Has context info ?: Context ?
Has context info ?: Contexte ?
ProcessSchedule: Planificateur
To run scheduler, ensure "bin/console messenger:consume scheduler_cron" console is alive. See https://symfony.com/doc/current/messenger.html#supervisor-configuration.: "Pour fonctionner, assurez vous que la commande \"bin/console messenger:consume scheduler_cron\" soit exécutée. Plus d''informations sur https://symfony.com/doc/current/messenger.html#supervisor-configuration."
Delete: Supprimer
Type: Type
Expression: Expression
Next Execution: Prochaîne exécution
Input: Input
Input: Entrée
General: Général
Context (key/value): Context (clé/valeur)
Context (key/value): Contexte (clé/valeur)
key: clé
value: valeur
Context Key: Context clé
Context Value: Context valeur
Context Key: Contexte clé
Context Value: Contexte valeur
"%H hour(s) %I min(s) %S s": "%H heure(s) %I minute(s) %S seconde(s)"
Duration (in seconds): Durée (en secondes)
Run process: Exécuter le processus
Do you really want to run process %process% in background: Voulez-vous vraiment exécuter le processus %process% en arrière plan
Confirm: Confirmer
2 changes: 2 additions & 0 deletions translations/validators.fr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The value "{{ value }}" is not every valid expression.: La valeur "{{ value }}" n'est pas une expression valide pour le type "Chaque date".
The value "{{ value }}" is not a valid cron expression.: La valeur "{{ value }}" n'est pas une expression valide pour le type "Tâche planifiée".