logo light

Globally Translate all Components

Image Description
By: php coder
  • Published: 25 Mar 2024 Updated: 04 May 2024

make all Field or any components translatable

Globally Translate all Components
1Field::configureUsing(function (Field $column) {
2 $column->label(fn () => __(self::getLangFile() . $column->getName()));
3});
1public static function getLangFile(): string
2{
3 if (
4 method_exists(Livewire::current(), 'getResource')
5 && method_exists(Livewire::current()->getResource(), 'langFile')
6 ) {
7 /** @phpstan-ignore-next-line */
8 return Livewire::current()->getResource()::langFile() . '.';
9 }
10 
11 return '';
12}
Back to Tricks