feat: lang middleware and filament translations
This commit is contained in:
@@ -13,9 +13,9 @@ enum PacePreference: string implements HasLabel
|
||||
public function getLabel(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::SLOW => 'Lent',
|
||||
self::NORMAL => 'Normal',
|
||||
self::FAST => 'Rapide',
|
||||
self::SLOW => __('enums.pace_preference.slow'),
|
||||
self::NORMAL => __('enums.pace_preference.normal'),
|
||||
self::FAST => __('enums.pace_preference.fast'),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,11 +15,11 @@ enum PhysicalActivityLevel: string implements HasLabel
|
||||
public function getLabel(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::SEDENTARY => 'Sédentaire',
|
||||
self::LIGHTLY_ACTIVE => 'Légèrement actif',
|
||||
self::MODERATELY_ACTIVE => 'Modérément actif',
|
||||
self::VERY_ACTIVE => 'Très actif',
|
||||
self::ATHLETE => 'Athlète',
|
||||
self::SEDENTARY => __('enums.physical_activity_level.sedentary'),
|
||||
self::LIGHTLY_ACTIVE => __('enums.physical_activity_level.lightly_active'),
|
||||
self::MODERATELY_ACTIVE => __('enums.physical_activity_level.moderately_active'),
|
||||
self::VERY_ACTIVE => __('enums.physical_activity_level.very_active'),
|
||||
self::ATHLETE => __('enums.physical_activity_level.athlete'),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,10 +14,10 @@ enum UserSex: string implements HasLabel
|
||||
public function getLabel(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::MAN => 'Homme',
|
||||
self::WOMAN => 'Femme',
|
||||
self::OTHER => 'Autre',
|
||||
self::UNKNOWN => 'Non renseigné',
|
||||
self::MAN => __('enums.user_sex.man'),
|
||||
self::WOMAN => __('enums.user_sex.woman'),
|
||||
self::OTHER => __('enums.user_sex.other'),
|
||||
self::UNKNOWN => __('enums.user_sex.unknown'),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,9 +13,9 @@ enum WeightGoal: string implements HasLabel
|
||||
public function getLabel(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::LOSE_WEIGHT => 'Perdre du poids',
|
||||
self::MAINTAIN_WEIGHT => 'Maintenir le poids',
|
||||
self::GAIN_WEIGHT => 'Prendre du poids',
|
||||
self::LOSE_WEIGHT => __('enums.weight_goal.lose_weight'),
|
||||
self::MAINTAIN_WEIGHT => __('enums.weight_goal.maintain_weight'),
|
||||
self::GAIN_WEIGHT => __('enums.weight_goal.gain_weight'),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,28 +22,28 @@ class UserForm
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
Section::make('Compte')
|
||||
Section::make(__('admin.users.sections.account'))
|
||||
->columns(2)
|
||||
->schema([
|
||||
TextInput::make('name')
|
||||
->label('Nom')
|
||||
->label(__('admin.users.fields.name'))
|
||||
->required()
|
||||
->maxLength(255),
|
||||
TextInput::make('email')
|
||||
->label('Adresse email')
|
||||
->label(__('admin.users.fields.email'))
|
||||
->email()
|
||||
->required()
|
||||
->unique(ignoreRecord: true)
|
||||
->maxLength(255),
|
||||
FileUpload::make('avatar_url')
|
||||
->label('Avatar')
|
||||
->label(__('admin.users.fields.avatar'))
|
||||
->image()
|
||||
->disk('public')
|
||||
->directory('avatars')
|
||||
->visibility('public')
|
||||
->maxSize(2048),
|
||||
TextInput::make('password')
|
||||
->label('Mot de passe')
|
||||
->label(__('admin.users.fields.password'))
|
||||
->password()
|
||||
->revealable()
|
||||
->rule(Password::default())
|
||||
@@ -52,38 +52,38 @@ class UserForm
|
||||
->dehydrated(fn ($state): bool => filled($state))
|
||||
->autocomplete('new-password'),
|
||||
DateTimePicker::make('email_verified_at')
|
||||
->label('Email vérifié le'),
|
||||
->label(__('admin.users.fields.email_verified_at')),
|
||||
DateTimePicker::make('account_verified_at')
|
||||
->label('Compte vérifié le'),
|
||||
->label(__('admin.users.fields.account_verified_at')),
|
||||
]),
|
||||
Section::make('Profil')
|
||||
Section::make(__('admin.users.sections.profile'))
|
||||
->columns(2)
|
||||
->schema([
|
||||
Textarea::make('bio')
|
||||
->label('Bio')
|
||||
->label(__('admin.users.fields.bio'))
|
||||
->rows(4)
|
||||
->columnSpanFull(),
|
||||
TextInput::make('height')
|
||||
->label('Taille')
|
||||
->label(__('admin.users.fields.height'))
|
||||
->integer()
|
||||
->minValue(0)
|
||||
->maxValue(300)
|
||||
->suffix('cm'),
|
||||
DatePicker::make('date_of_birth')
|
||||
->label('Date de naissance')
|
||||
->label(__('admin.users.fields.date_of_birth'))
|
||||
->minDate('1900-01-01')
|
||||
->maxDate(now()->subDay()),
|
||||
Select::make('sex')
|
||||
->label('Sexe')
|
||||
->label(__('admin.users.fields.sex'))
|
||||
->options(UserSex::class)
|
||||
->default(UserSex::UNKNOWN->value)
|
||||
->required(),
|
||||
]),
|
||||
Section::make('Objectifs nutritionnels')
|
||||
Section::make(__('admin.users.sections.nutrition_goals'))
|
||||
->columns(4)
|
||||
->schema([
|
||||
TextInput::make('daily_calorie_goal')
|
||||
->label('Calories')
|
||||
->label(__('admin.users.fields.daily_calorie_goal'))
|
||||
->integer()
|
||||
->minValue(0)
|
||||
->maxValue(100000)
|
||||
@@ -91,7 +91,7 @@ class UserForm
|
||||
->default(2000)
|
||||
->required(),
|
||||
TextInput::make('daily_protein_goal')
|
||||
->label('Protéines')
|
||||
->label(__('admin.users.fields.daily_protein_goal'))
|
||||
->numeric()
|
||||
->minValue(0)
|
||||
->maxValue(10000)
|
||||
@@ -99,7 +99,7 @@ class UserForm
|
||||
->default(120)
|
||||
->required(),
|
||||
TextInput::make('daily_carbs_goal')
|
||||
->label('Glucides')
|
||||
->label(__('admin.users.fields.daily_carbs_goal'))
|
||||
->numeric()
|
||||
->minValue(0)
|
||||
->maxValue(10000)
|
||||
@@ -107,7 +107,7 @@ class UserForm
|
||||
->default(250)
|
||||
->required(),
|
||||
TextInput::make('daily_fats_goal')
|
||||
->label('Lipides')
|
||||
->label(__('admin.users.fields.daily_fats_goal'))
|
||||
->numeric()
|
||||
->minValue(0)
|
||||
->maxValue(10000)
|
||||
@@ -115,21 +115,21 @@ class UserForm
|
||||
->default(70)
|
||||
->required(),
|
||||
]),
|
||||
Section::make('Activité')
|
||||
Section::make(__('admin.users.sections.activity'))
|
||||
->columns(3)
|
||||
->schema([
|
||||
Select::make('physical_activity_level')
|
||||
->label('Niveau d’activité')
|
||||
->label(__('admin.users.fields.physical_activity_level'))
|
||||
->options(PhysicalActivityLevel::class)
|
||||
->default(PhysicalActivityLevel::SEDENTARY->value)
|
||||
->required(),
|
||||
Select::make('weight_goal')
|
||||
->label('Objectif de poids')
|
||||
->label(__('admin.users.fields.weight_goal'))
|
||||
->options(WeightGoal::class)
|
||||
->default(WeightGoal::LOSE_WEIGHT->value)
|
||||
->required(),
|
||||
Select::make('pace_preference')
|
||||
->label('Rythme')
|
||||
->label(__('admin.users.fields.pace_preference'))
|
||||
->options(PacePreference::class)
|
||||
->default(PacePreference::SLOW->value)
|
||||
->required(),
|
||||
|
||||
@@ -13,95 +13,95 @@ class UserInfolist
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
Section::make('Compte')
|
||||
Section::make(__('admin.users.sections.account'))
|
||||
->columns(3)
|
||||
->schema([
|
||||
TextEntry::make('id')
|
||||
->label('ID')
|
||||
->label(__('admin.users.fields.id'))
|
||||
->copyable(),
|
||||
TextEntry::make('name')
|
||||
->label('Nom'),
|
||||
->label(__('admin.users.fields.name')),
|
||||
TextEntry::make('email')
|
||||
->label('Adresse email')
|
||||
->label(__('admin.users.fields.email'))
|
||||
->copyable(),
|
||||
TextEntry::make('email_verified_at')
|
||||
->label('Email vérifié le')
|
||||
->label(__('admin.users.fields.email_verified_at'))
|
||||
->dateTime()
|
||||
->placeholder('Non vérifié'),
|
||||
->placeholder(__('admin.users.placeholders.not_verified')),
|
||||
TextEntry::make('account_verified_at')
|
||||
->label('Compte vérifié le')
|
||||
->label(__('admin.users.fields.account_verified_at'))
|
||||
->dateTime()
|
||||
->placeholder('Non vérifié'),
|
||||
->placeholder(__('admin.users.placeholders.not_verified')),
|
||||
ImageEntry::make('avatar_url')
|
||||
->label('Avatar')
|
||||
->label(__('admin.users.fields.avatar'))
|
||||
->disk('public')
|
||||
->circular()
|
||||
->placeholder('-'),
|
||||
->placeholder(__('admin.users.placeholders.empty')),
|
||||
]),
|
||||
Section::make('Profil')
|
||||
Section::make(__('admin.users.sections.profile'))
|
||||
->columns(3)
|
||||
->schema([
|
||||
TextEntry::make('bio')
|
||||
->label('Bio')
|
||||
->placeholder('-')
|
||||
->label(__('admin.users.fields.bio'))
|
||||
->placeholder(__('admin.users.placeholders.empty'))
|
||||
->columnSpanFull(),
|
||||
TextEntry::make('height')
|
||||
->label('Taille')
|
||||
->label(__('admin.users.fields.height'))
|
||||
->numeric(decimalPlaces: 0)
|
||||
->suffix(' cm')
|
||||
->placeholder('-'),
|
||||
->placeholder(__('admin.users.placeholders.empty')),
|
||||
TextEntry::make('date_of_birth')
|
||||
->label('Date de naissance')
|
||||
->label(__('admin.users.fields.date_of_birth'))
|
||||
->date()
|
||||
->placeholder('-'),
|
||||
->placeholder(__('admin.users.placeholders.empty')),
|
||||
TextEntry::make('sex')
|
||||
->label('Sexe')
|
||||
->label(__('admin.users.fields.sex'))
|
||||
->badge(),
|
||||
]),
|
||||
Section::make('Objectifs nutritionnels')
|
||||
Section::make(__('admin.users.sections.nutrition_goals'))
|
||||
->columns(4)
|
||||
->schema([
|
||||
TextEntry::make('daily_calorie_goal')
|
||||
->label('Calories')
|
||||
->label(__('admin.users.fields.daily_calorie_goal'))
|
||||
->numeric(decimalPlaces: 0)
|
||||
->suffix(' kcal'),
|
||||
TextEntry::make('daily_protein_goal')
|
||||
->label('Protéines')
|
||||
->label(__('admin.users.fields.daily_protein_goal'))
|
||||
->numeric(maxDecimalPlaces: 2)
|
||||
->suffix(' g'),
|
||||
TextEntry::make('daily_carbs_goal')
|
||||
->label('Glucides')
|
||||
->label(__('admin.users.fields.daily_carbs_goal'))
|
||||
->numeric(maxDecimalPlaces: 2)
|
||||
->suffix(' g'),
|
||||
TextEntry::make('daily_fats_goal')
|
||||
->label('Lipides')
|
||||
->label(__('admin.users.fields.daily_fats_goal'))
|
||||
->numeric(maxDecimalPlaces: 2)
|
||||
->suffix(' g'),
|
||||
]),
|
||||
Section::make('Activité')
|
||||
Section::make(__('admin.users.sections.activity'))
|
||||
->columns(3)
|
||||
->schema([
|
||||
TextEntry::make('physical_activity_level')
|
||||
->label('Niveau d’activité')
|
||||
->label(__('admin.users.fields.physical_activity_level'))
|
||||
->badge(),
|
||||
TextEntry::make('weight_goal')
|
||||
->label('Objectif de poids')
|
||||
->label(__('admin.users.fields.weight_goal'))
|
||||
->badge(),
|
||||
TextEntry::make('pace_preference')
|
||||
->label('Rythme')
|
||||
->label(__('admin.users.fields.pace_preference'))
|
||||
->badge(),
|
||||
]),
|
||||
Section::make('Métadonnées')
|
||||
Section::make(__('admin.users.sections.metadata'))
|
||||
->columns(2)
|
||||
->schema([
|
||||
TextEntry::make('created_at')
|
||||
->label('Créé le')
|
||||
->label(__('admin.users.fields.created_at'))
|
||||
->dateTime()
|
||||
->placeholder('-'),
|
||||
->placeholder(__('admin.users.placeholders.empty')),
|
||||
TextEntry::make('updated_at')
|
||||
->label('Mis à jour le')
|
||||
->label(__('admin.users.fields.updated_at'))
|
||||
->dateTime()
|
||||
->placeholder('-'),
|
||||
->placeholder(__('admin.users.placeholders.empty')),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -23,118 +23,118 @@ class UsersTable
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('id')
|
||||
->label('ID')
|
||||
->label(__('admin.users.fields.id'))
|
||||
->searchable()
|
||||
->copyable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('name')
|
||||
->label('Nom')
|
||||
->label(__('admin.users.fields.name'))
|
||||
->searchable(),
|
||||
TextColumn::make('email')
|
||||
->label('Adresse email')
|
||||
->label(__('admin.users.fields.email'))
|
||||
->searchable(),
|
||||
TextColumn::make('email_verified_at')
|
||||
->label('Email vérifié le')
|
||||
->label(__('admin.users.fields.email_verified_at'))
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->placeholder('Non vérifié'),
|
||||
->placeholder(__('admin.users.placeholders.not_verified')),
|
||||
TextColumn::make('account_verified_at')
|
||||
->label('Compte vérifié le')
|
||||
->label(__('admin.users.fields.account_verified_at'))
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->placeholder('Non vérifié')
|
||||
->placeholder(__('admin.users.placeholders.not_verified'))
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
ImageColumn::make('avatar_url')
|
||||
->label('Avatar')
|
||||
->label(__('admin.users.fields.avatar'))
|
||||
->disk('public')
|
||||
->circular(),
|
||||
TextColumn::make('sex')
|
||||
->label('Sexe')
|
||||
->label(__('admin.users.fields.sex'))
|
||||
->badge()
|
||||
->sortable(),
|
||||
TextColumn::make('date_of_birth')
|
||||
->label('Date de naissance')
|
||||
->label(__('admin.users.fields.date_of_birth'))
|
||||
->date()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('height')
|
||||
->label('Taille')
|
||||
->label(__('admin.users.fields.height'))
|
||||
->numeric(decimalPlaces: 0)
|
||||
->suffix(' cm')
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('physical_activity_level')
|
||||
->label('Activité')
|
||||
->label(__('admin.users.fields.physical_activity_level_short'))
|
||||
->badge()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('weight_goal')
|
||||
->label('Objectif poids')
|
||||
->label(__('admin.users.fields.weight_goal_short'))
|
||||
->badge()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('pace_preference')
|
||||
->label('Rythme')
|
||||
->label(__('admin.users.fields.pace_preference'))
|
||||
->badge()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('daily_calorie_goal')
|
||||
->label('Calories')
|
||||
->label(__('admin.users.fields.daily_calorie_goal'))
|
||||
->numeric(decimalPlaces: 0)
|
||||
->suffix(' kcal')
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('daily_protein_goal')
|
||||
->label('Protéines')
|
||||
->label(__('admin.users.fields.daily_protein_goal'))
|
||||
->numeric(maxDecimalPlaces: 2)
|
||||
->suffix(' g')
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('daily_carbs_goal')
|
||||
->label('Glucides')
|
||||
->label(__('admin.users.fields.daily_carbs_goal'))
|
||||
->numeric(maxDecimalPlaces: 2)
|
||||
->suffix(' g')
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('daily_fats_goal')
|
||||
->label('Lipides')
|
||||
->label(__('admin.users.fields.daily_fats_goal'))
|
||||
->numeric(maxDecimalPlaces: 2)
|
||||
->suffix(' g')
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('bio')
|
||||
->label('Bio')
|
||||
->label(__('admin.users.fields.bio'))
|
||||
->limit(50)
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('created_at')
|
||||
->label('Créé le')
|
||||
->label(__('admin.users.fields.created_at'))
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('updated_at')
|
||||
->label('Mis à jour le')
|
||||
->label(__('admin.users.fields.updated_at'))
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->filters([
|
||||
SelectFilter::make('sex')
|
||||
->label('Sexe')
|
||||
->label(__('admin.users.fields.sex'))
|
||||
->options(UserSex::class),
|
||||
SelectFilter::make('physical_activity_level')
|
||||
->label('Activité')
|
||||
->label(__('admin.users.fields.physical_activity_level_short'))
|
||||
->options(PhysicalActivityLevel::class),
|
||||
SelectFilter::make('weight_goal')
|
||||
->label('Objectif poids')
|
||||
->label(__('admin.users.fields.weight_goal_short'))
|
||||
->options(WeightGoal::class),
|
||||
SelectFilter::make('pace_preference')
|
||||
->label('Rythme')
|
||||
->label(__('admin.users.fields.pace_preference'))
|
||||
->options(PacePreference::class),
|
||||
TernaryFilter::make('email_verified_at')
|
||||
->label('Email vérifié')
|
||||
->label(__('admin.users.filters.email_verified'))
|
||||
->nullable(),
|
||||
TernaryFilter::make('account_verified_at')
|
||||
->label('Compte vérifié')
|
||||
->label(__('admin.users.filters.account_verified'))
|
||||
->nullable(),
|
||||
])
|
||||
->recordActions([
|
||||
|
||||
@@ -24,6 +24,21 @@ class UserResource extends Resource
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'name';
|
||||
|
||||
public static function getNavigationLabel(): string
|
||||
{
|
||||
return __('admin.users.navigation.label');
|
||||
}
|
||||
|
||||
public static function getModelLabel(): string
|
||||
{
|
||||
return __('admin.users.navigation.singular');
|
||||
}
|
||||
|
||||
public static function getPluralModelLabel(): string
|
||||
{
|
||||
return __('admin.users.navigation.plural');
|
||||
}
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return UserForm::configure($schema);
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class SetLocale
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
||||
*/
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
app()->setLocale($this->resolveLocale($request));
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
private function resolveLocale(Request $request): string
|
||||
{
|
||||
$supportedLocales = config('app.supported_locales', ['fr', 'en']);
|
||||
$requestedLocale = $request->query('locale') ?: $request->header('X-Locale');
|
||||
|
||||
if (is_string($requestedLocale)) {
|
||||
$normalizedLocale = $this->normalizeLocale($requestedLocale);
|
||||
|
||||
if (in_array($normalizedLocale, $supportedLocales, true)) {
|
||||
return $normalizedLocale;
|
||||
}
|
||||
}
|
||||
|
||||
return $request->getPreferredLanguage($supportedLocales) ?? config('app.locale');
|
||||
}
|
||||
|
||||
private function normalizeLocale(string $locale): string
|
||||
{
|
||||
$locale = strtolower(str_replace('_', '-', $locale));
|
||||
|
||||
return explode('-', $locale)[0];
|
||||
}
|
||||
}
|
||||
@@ -25,9 +25,13 @@ class UserResource extends JsonResource
|
||||
'bio' => $this->bio,
|
||||
'accountVerified' => $this->account_verified_at !== null,
|
||||
'physicalActivityLevel' => $this->physical_activity_level,
|
||||
'physicalActivityLevelLabel' => $this->physical_activity_level?->getLabel(),
|
||||
'weightGoal' => $this->weight_goal,
|
||||
'weightGoalLabel' => $this->weight_goal?->getLabel(),
|
||||
'pacePreference' => $this->pace_preference,
|
||||
'pacePreferenceLabel' => $this->pace_preference?->getLabel(),
|
||||
'sex' => $this->sex,
|
||||
'sexLabel' => $this->sex?->getLabel(),
|
||||
'dateOfBirth' => $this->date_of_birth?->toDateString(),
|
||||
'nutritionGoals' => [
|
||||
'calories' => (int) $this->daily_calorie_goal,
|
||||
|
||||
Reference in New Issue
Block a user