Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

TranslationServiceProvider.php 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace App\Providers;
  3. use Closure;
  4. use Filament\Forms\Components\Field;
  5. use Filament\Navigation\NavigationGroup;
  6. use Filament\Resources\Components\Tab;
  7. use Filament\Tables\Columns\Column;
  8. use Illuminate\Contracts\Support\Htmlable;
  9. use Illuminate\Support\ServiceProvider;
  10. class TranslationServiceProvider extends ServiceProvider
  11. {
  12. /**
  13. * Register services.
  14. */
  15. public function register(): void
  16. {
  17. //
  18. }
  19. /**
  20. * Bootstrap services.
  21. */
  22. public function boot(): void
  23. {
  24. Field::macro('localizeLabel', function (string | Htmlable | Closure | null $customLabel = null): static {
  25. if (filled($customLabel)) {
  26. $label = $customLabel;
  27. } else {
  28. $label = $this->getLabel();
  29. if (str_ends_with($label, ' id')) {
  30. $label = str_replace(' id', '', $label);
  31. }
  32. $label = ucwords($label);
  33. }
  34. $this->label(translate($label));
  35. return $this;
  36. });
  37. Column::macro('localizeLabel', function (string | Htmlable | Closure | null $customLabel = null): static {
  38. if (filled($customLabel)) {
  39. $label = $customLabel;
  40. } else {
  41. $label = $this->getLabel();
  42. if (str_ends_with($label, ' id')) {
  43. $label = str_replace(' id', '', $label);
  44. }
  45. $label = ucwords($label);
  46. }
  47. $this->label(translate($label));
  48. return $this;
  49. });
  50. NavigationGroup::macro('localizeLabel', function () {
  51. $label = $this->getLabel();
  52. if ($label !== 'HR' && filled($label)) {
  53. $this->label(translate($label));
  54. }
  55. return $this;
  56. });
  57. Tab::macro('localizeLabel', function () {
  58. $label = $this->getLabel();
  59. $this->label(ucfirst(translate($label)));
  60. return $this;
  61. });
  62. }
  63. }