Skip to content

Commit a6cc010

Browse files
authored
Merge pull request #44 from cleverage/40
#40 Fix localisation issues
2 parents 2cd1286 + 04e3754 commit a6cc010

17 files changed

+105
-21
lines changed

config/services/controller.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@ services:
1212
$context: '@EasyCorp\Bundle\EasyAdminBundle\Factory\AdminContextFactory'
1313
$logDirectory: '%kernel.logs_dir%'
1414
$processExecutionRepository: '@cleverage_ui_process.repository.process_execution'
15+
$intlFormatter: '@EasyCorp\Bundle\EasyAdminBundle\Intl\IntlFormatter'
16+
$translator: '@translator'
1517
tags:
1618
- { name: 'controller.service_arguments' }

config/services/twig.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ services:
2626
cleverage_ui_process.twig.log_level_extension_runtime:
2727
class: CleverAge\UiProcessBundle\Twig\Runtime\LogLevelExtensionRuntime
2828
public: false
29+
calls:
30+
- [setTranslator, ['@translator']]
2931
tags:
3032
- { name: 'twig.runtime' }
3133

@@ -56,4 +58,4 @@ services:
5658
class: CleverAge\UiProcessBundle\Twig\Components\BootstrapModal
5759
shared: false
5860
tags:
59-
- { name: 'twig.component', key: 'ui:BootstrapModal', template: '@CleverAgeUiProcess/components/BootstrapModal.html.twig' }
61+
- { name: 'twig.component', key: 'ui:BootstrapModal', template: '@CleverAgeUiProcess/components/BootstrapModal.html.twig' }

src/Controller/Admin/LogRecordCrudController.php

+8-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function configureFields(string $pageName): iterable
5151
return [
5252
LogLevelField::new('level'),
5353
TextField::new('message')->setMaxLength(512),
54-
DateTimeField::new('createdAt')->setFormat('Y/M/dd H:mm:ss'),
54+
DateTimeField::new('createdAt')->setFormat('short', 'medium'),
5555
ContextField::new('context')
5656
->onlyOnDetail(),
5757
BooleanField::new('contextIsEmpty', 'Has context info ?')
@@ -87,9 +87,14 @@ public function configureFilters(Filters $filters): Filters
8787
$processList = array_map(fn (ProcessConfiguration $cfg) => $cfg->getCode(), $processList);
8888

8989
return $filters->add(
90-
LogProcessFilter::new('process', $processList, $id)
90+
LogProcessFilter::new('Process', $processList, $id)
9191
)->add(
92-
ChoiceFilter::new('level')->setChoices(array_combine(Level::NAMES, Level::VALUES))
92+
ChoiceFilter::new('level')
93+
->setTranslatableChoices(array_combine(
94+
Level::VALUES,
95+
array_map(fn ($value) => 'enum.log_level.'.strtolower((string) $value), Level::NAMES)
96+
))
97+
->setFormTypeOption('translation_domain', 'enums'),
9398
)->add('message')->add('context')->add('createdAt');
9499
}
95100
}

src/Controller/Admin/Process/ListAction.php

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace CleverAge\UiProcessBundle\Controller\Admin\Process;
1515

1616
use CleverAge\UiProcessBundle\Manager\ProcessConfigurationsManager;
17+
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Intl\IntlFormatterInterface;
1718
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1819
use Symfony\Component\HttpFoundation\Response;
1920
use Symfony\Component\Routing\Attribute\Route;
@@ -23,12 +24,17 @@
2324
#[IsGranted('ROLE_USER')]
2425
class ListAction extends AbstractController
2526
{
27+
public function __construct(private readonly IntlFormatterInterface $intlFormatter)
28+
{
29+
}
30+
2631
public function __invoke(ProcessConfigurationsManager $processConfigurationsManager): Response
2732
{
2833
return $this->render(
2934
'@CleverAgeUiProcess/admin/process/list.html.twig',
3035
[
3136
'processes' => $processConfigurationsManager->getPublicProcesses(),
37+
'IntlFormatterService' => $this->intlFormatter,
3238
]
3339
);
3440
}

src/Controller/Admin/ProcessExecutionCrudController.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@
3232
use Symfony\Component\HttpFoundation\Response;
3333
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
3434
use Symfony\Component\Security\Http\Attribute\IsGranted;
35+
use Symfony\Contracts\Translation\TranslatorInterface;
3536

3637
#[IsGranted('ROLE_USER')]
3738
class ProcessExecutionCrudController extends AbstractCrudController
3839
{
3940
public function __construct(
4041
private readonly ProcessExecutionRepository $processExecutionRepository,
4142
private readonly string $logDirectory,
43+
private readonly TranslatorInterface $translator,
4244
) {
4345
}
4446

@@ -52,12 +54,12 @@ public function configureFields(string $pageName): iterable
5254
return [
5355
TextField::new('code'),
5456
EnumField::new('status'),
55-
DateTimeField::new('startDate')->setFormat('Y/M/dd H:mm:ss'),
56-
DateTimeField::new('endDate')->setFormat('Y/M/dd H:mm:ss'),
57+
DateTimeField::new('startDate')->setFormat('short', 'medium'),
58+
DateTimeField::new('endDate')->setFormat('short', 'medium'),
5759
TextField::new('source')->setTemplatePath('@CleverAgeUiProcess/admin/field/process_source.html.twig'),
5860
TextField::new('target')->setTemplatePath('@CleverAgeUiProcess/admin/field/process_target.html.twig'),
5961
TextField::new('duration')->formatValue(function ($value, ProcessExecution $entity) {
60-
return $entity->duration(); // returned format can be changed here
62+
return $entity->duration($this->translator->trans('%H hour(s) %I min(s) %S s')); // returned format can be changed here
6163
}),
6264
ArrayField::new('report')->setTemplatePath('@CleverAgeUiProcess/admin/field/report.html.twig'),
6365
ContextField::new('context'),

src/Entity/Enum/ProcessExecutionStatus.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,17 @@
1313

1414
namespace CleverAge\UiProcessBundle\Entity\Enum;
1515

16-
enum ProcessExecutionStatus: string
16+
use Symfony\Contracts\Translation\TranslatableInterface;
17+
use Symfony\Contracts\Translation\TranslatorInterface;
18+
19+
enum ProcessExecutionStatus: string implements TranslatableInterface
1720
{
1821
case Started = 'started';
1922
case Finish = 'finish';
2023
case Failed = 'failed';
24+
25+
public function trans(TranslatorInterface $translator, ?string $locale = null): string
26+
{
27+
return $translator->trans('enum.process_execution_status.'.$this->value, domain: 'enums', locale: $locale);
28+
}
2129
}

src/Entity/Enum/ProcessScheduleType.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,16 @@
1313

1414
namespace CleverAge\UiProcessBundle\Entity\Enum;
1515

16-
enum ProcessScheduleType: string
16+
use Symfony\Contracts\Translation\TranslatableInterface;
17+
use Symfony\Contracts\Translation\TranslatorInterface;
18+
19+
enum ProcessScheduleType: string implements TranslatableInterface
1720
{
1821
case CRON = 'cron';
1922
case EVERY = 'every';
23+
24+
public function trans(TranslatorInterface $translator, ?string $locale = null): string
25+
{
26+
return $translator->trans('enum.process_schedule_type.'.$this->value, domain: 'enums', locale: $locale);
27+
}
2028
}

src/Twig/Extension/LogLevelExtension.php

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public function getFunctions(): array
2323
{
2424
return [
2525
new TwigFunction('log_label', [LogLevelExtensionRuntime::class, 'getLabel']),
26+
new TwigFunction('log_translation', [LogLevelExtensionRuntime::class, 'getTranslation']),
2627
new TwigFunction('log_css_class', [LogLevelExtensionRuntime::class, 'getCssClass']),
2728
];
2829
}

src/Twig/Runtime/LogLevelExtensionRuntime.php

+13
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,28 @@
1414
namespace CleverAge\UiProcessBundle\Twig\Runtime;
1515

1616
use Monolog\Level;
17+
use Symfony\Contracts\Translation\TranslatorInterface;
1718
use Twig\Extension\RuntimeExtensionInterface;
1819

1920
class LogLevelExtensionRuntime implements RuntimeExtensionInterface
2021
{
22+
private TranslatorInterface $translator;
23+
24+
public function setTranslator(TranslatorInterface $translator): void
25+
{
26+
$this->translator = $translator;
27+
}
28+
2129
public function getLabel(int $value): string
2230
{
2331
return Level::from($value)->getName();
2432
}
2533

34+
public function getTranslation(string $key): string
35+
{
36+
return $this->translator->trans('enum.log_level.'.strtolower($key), domain: 'enums');
37+
}
38+
2639
public function getCssClass(string|int $value): string
2740
{
2841
return \is_int($value) ?

templates/admin/field/enum.html.twig

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
{% set class = field.value.value == 'failed' ? 'danger' : 'success' %}
2-
<span class="badge badge-{{ class }}">{{ field.value.value }}</span>
2+
<span class="badge badge-{{ class }}">{{ field.value|trans() }}</span>
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<span class="badge badge-{{ log_css_class(field.value) }}">{{ log_label(field.value) }}</span>
1+
<span class="badge badge-{{ log_css_class(field.value) }}">{{ log_translation(log_label(field.value)) }}</span>

templates/admin/field/report.html.twig

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
{# @var entity \EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto #}
44
<ul>
55
{% for key, item in field.value %}
6-
<li class="list-group-item"><span class="badge badge-{{ log_css_class(key) }}">{{ key }}</span> : {{ item }}</li>
6+
<li class="list-group-item"><span class="badge badge-{{ log_css_class(key) }}">{{ log_translation(key) }}</span> : {{ item }}</li>
77
{% endfor %}
88
</ul>

templates/admin/process/list.html.twig

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
{% endif %}
3131
<tr>
3232
<td>{{ process.code }}</td>
33-
<td>{% if lastExecution is not null %}{{ lastExecution.startDate|date('Y/m/d H:i:s') }}{% endif %}</td>
34-
<td><span class="badge badge-{{ statusClass }}">{% if lastExecution is not null %}{{ lastExecution.status.value }}{% endif %}</span></td>
33+
<td>{% if lastExecution is not null %}{{ IntlFormatterService.formatDateTime(lastExecution.startDate, 'short', 'medium') }}{% endif %}</td>
34+
<td><span class="badge badge-{{ statusClass }}">{% if lastExecution is not null %}{{ lastExecution.status|trans() }}{% endif %}</span></td>
3535
<td>{% if process.options.ui.source is defined %}{{ process.options.ui.source }}{% endif %}</td>
3636
<td>{% if process.options.ui.target is defined %}{{ process.options.ui.target }}{% endif %}</td>
3737
<td class="text-center">

translations/enums.en.yaml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
enum.process_execution_status.started: 'Started'
2+
enum.process_execution_status.finish: 'Finished'
3+
enum.process_execution_status.failed: 'Failed'
4+
5+
enum.process_schedule_type.cron: 'Cron'
6+
enum.process_schedule_type.every: 'Every date'
7+
8+
enum.log_level.debug: 'Debug'
9+
enum.log_level.info: 'Info'
10+
enum.log_level.notice: 'Notice'
11+
enum.log_level.warning: 'Warning'
12+
enum.log_level.error: 'Error'
13+
enum.log_level.critical: 'Critical'
14+
enum.log_level.alert: 'Alert'
15+
enum.log_level.emergency: 'Emergency'

translations/enums.fr.yaml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
enum.process_execution_status.started: 'Démarré'
2+
enum.process_execution_status.finish: 'Terminé'
3+
enum.process_execution_status.failed: 'Échoué'
4+
5+
enum.process_schedule_type.cron: 'Tâche planifiée'
6+
enum.process_schedule_type.every: 'Chaque date'
7+
8+
enum.log_level.debug: 'Débogage'
9+
enum.log_level.info: 'Information'
10+
enum.log_level.notice: 'Notification'
11+
enum.log_level.warning: 'Avertissement'
12+
enum.log_level.error: 'Erreur'
13+
enum.log_level.critical: 'Critique'
14+
enum.log_level.alert: 'Alerte'
15+
enum.log_level.emergency: 'Urgence'

translations/messages.fr.yaml

+12-7
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ Timezone: Fuseau horaire
2121
Locale: Locale
2222
ProcessExecution: Exécution des processus
2323
Code: Code
24-
Status: Status
24+
Status: Statut
2525
Start Date: Date de début
2626
End Date: Date de fin
2727
Source: Source
2828
Target: Destination
2929
Duration: Durée
3030
Report: Rapport
31-
Context: Context
31+
Context: Contexte
3232
Launch: Exécuter
3333
View executions: Voir les éxécutions
3434
Process code: Code du processus
@@ -38,17 +38,22 @@ LogRecord: Logs
3838
Level: Niveau
3939
Message: Message
4040
Created At: Date de création
41-
Has context info ?: Context ?
41+
Has context info ?: Contexte ?
4242
ProcessSchedule: Planificateur
4343
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."
4444
Delete: Supprimer
4545
Type: Type
4646
Expression: Expression
4747
Next Execution: Prochaîne exécution
48-
Input: Input
48+
Input: Entrée
4949
General: Général
50-
Context (key/value): Context (clé/valeur)
50+
Context (key/value): Contexte (clé/valeur)
5151
key: clé
5252
value: valeur
53-
Context Key: Context clé
54-
Context Value: Context valeur
53+
Context Key: Contexte clé
54+
Context Value: Contexte valeur
55+
"%H hour(s) %I min(s) %S s": "%H heure(s) %I minute(s) %S seconde(s)"
56+
Duration (in seconds): Durée (en secondes)
57+
Run process: Exécuter le processus
58+
Do you really want to run process %process% in background: Voulez-vous vraiment exécuter le processus %process% en arrière plan
59+
Confirm: Confirmer

translations/validators.fr.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The value "{{ value }}" is not every valid expression.: La valeur "{{ value }}" n'est pas une expression valide pour le type "Chaque date".
2+
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".

0 commit comments

Comments
 (0)