Skip to content

Commit 32648b4

Browse files
committed
feat(enum): implement TranslatableInterface in SettingsEnum and add trans method
1 parent d3570a5 commit 32648b4

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

src/Enums/SettingsEnum.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* Copyright 2025 (C) IDMarinas - All Rights Reserved
44
*
5-
* Last modified by "IDMarinas" on 31/03/2025, 17:17
5+
* Last modified by "IDMarinas" on 14/04/2025, 21:22
66
*
77
* @project IDMarinas Settings Bundle
88
* @see https://github.com/idmarinas/settings-bundle
@@ -20,12 +20,12 @@
2020
namespace Idm\Bundle\Settings\Enums;
2121

2222
use Idm\Bundle\Common\Traits\Enums\EnumToArrayTrait;
23-
use Idm\Bundle\User\Enums\TranslatableChoicesEnumTrait;
23+
use Symfony\Contracts\Translation\TranslatableInterface;
24+
use Symfony\Contracts\Translation\TranslatorInterface;
2425

25-
enum SettingsEnum: string
26+
enum SettingsEnum: string implements TranslatableInterface
2627
{
2728
use EnumToArrayTrait;
28-
use TranslatableChoicesEnumTrait;
2929

3030
case STRING = 'string';
3131
case BOOL = 'bool';
@@ -41,4 +41,11 @@ public function format (mixed $value): float|bool|int|string
4141
default => (string)$value, // Default is string
4242
};
4343
}
44+
45+
public function trans (TranslatorInterface $translator, ?string $locale = null): string
46+
{
47+
$key = 'enum.setting.type.' . strtolower($this->name);
48+
49+
return $translator->trans($key, domain: 'IdmSettingsBundle', locale: $locale);
50+
}
4451
}

0 commit comments

Comments
 (0)