PHP code example of outerweb / filament-translatable-fields
1. Go to this page and download the library: Download outerweb/filament-translatable-fields library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
outerweb / filament-translatable-fields example snippets
use Outerweb\FilamentTranslatableFields\TranslatableFieldsPlugin;
public function panel(Panel $panel): Panel
{
return $panel
// ...
->plugins([
// ...
TranslatableFieldsPlugin::make(),
]);
}
use Outerweb\FilamentTranslatableFields\TranslatableFieldsPlugin;
public function panel(Panel $panel): Panel
{
return $panel
// ...
->plugins([
// ...
TranslatableFieldsPlugin::make()
->supportedLocales(['en', 'de', 'fr']),
]);
}
use Outerweb\FilamentTranslatableFields\TranslatableFieldsPlugin;
public function panel(Panel $panel): Panel
{
return $panel
// ...
->plugins([
// ...
TranslatableFieldsPlugin::make()
->supportedLocales([
'en' => 'English',
'de' => 'Deutsch',
'fr' => 'Français',
]),
]);
}
use Outerweb\FilamentTranslatableFields\TranslatableFieldsPlugin;
public function panel(Panel $panel): Panel
{
return $panel
// ...
->plugins([
// ...
TranslatableFieldsPlugin::make()
->supportedLocales(fn () => getSupportedLocales()),
]);
}
use Outerweb\FilamentTranslatableFields\TranslatableFieldsPlugin;
public function panel(Panel $panel): Panel
{
return $panel
// ...
->plugins([
// ...
TranslatableFieldsPlugin::make()
->defaultLocale('de'),
]);
}
use Outerweb\FilamentTranslatableFields\TranslatableFieldsPlugin;
public function panel(Panel $panel): Panel
{
return $panel
// ...
->plugins([
// ...
TranslatableFieldsPlugin::make()
->defaultLocale(fn () => auth()->user()->preferred_locale),
]);
}
use Filament\Forms\Components\TextInput;
TextInput::make('name')
->translatable(),
use Filament\Forms\Components\TextInput;
TextInput::make('name')
->translatable(
modifyLocalizedFieldUsing: function (TextInput $field, string $locale): TextInput {
return match ($locale) {
'en' => $field->
use Filament\Forms\Components\TextInput;
// Using a bool
TextInput::make('name')
->translatable(false),
// Using a Closure
TextInput::make('name')
->translatable(fn () => someCondition()),
use Filament\Forms\Components\TextInput;
// Using an array
TextInput::make('name')
->translatable(
supportedLocales: ['en', 'de']
),
// Using a Closure
TextInput::make('name')
->translatable(
supportedLocales: fn () => getSupportedLocales(),
),
use Filament\Forms\Components\TextInput;
// Using a string
TextInput::make('name')
->translatable(
defaultLocale: 'de'
),
// Using a Closure
TextInput::make('name')
->translatable(
defaultLocale: fn () => auth()->user()->preferred_locale,
),
use Filament\Schemas\Components\Section;
Section::make()
->schema([
TextInput::make('name'),
TextInput::make('description'),
])
->translatable(),
use Illuminate\Support\Str;
use Filament\Forms\Components\TextInput;
use Filament\Schemas\Components\Component;
use Filament\Schemas\Components\Section;
Section::make()
->schema([
TextInput::make('name'),
TextInput::make('description'),
])
->translatable(
modifyLocalizedFieldUsing: function (Component $field, string $locale): Component {
if ($field instanceof TextInput && Str::startsWith($field->getName(), 'name.')) {
return match ($locale) {
'en' => $field->
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.