fix: 🐛 validate translations when there is config associated to dynamic page
This commit is contained in:
parent
d99abb07cb
commit
be98abb0d0
1 changed files with 16 additions and 14 deletions
|
|
@ -123,22 +123,24 @@ class DynamicPage extends Model
|
|||
return;
|
||||
}
|
||||
|
||||
$locales = collect(config('app.locales'));
|
||||
$modelLocales = collect(array_keys($model->config->getTranslations('config')));
|
||||
$allowedLocales = $modelLocales->intersect($locales);
|
||||
if ($model->config) {
|
||||
$modelLocales = collect(array_keys($model->config->getTranslations('config')));
|
||||
$locales = collect(config('app.locales'));
|
||||
$allowedLocales = $modelLocales->intersect($locales);
|
||||
|
||||
$missingLocales = $allowedLocales->reject(
|
||||
fn($locale) => $model->hasTranslation('content', $locale)
|
||||
);
|
||||
$missingLocales = $allowedLocales->reject(
|
||||
fn($locale) => $model->hasTranslation('content', $locale)
|
||||
);
|
||||
|
||||
if ($missingLocales->isNotEmpty()) {
|
||||
throw ValidationException::withMessages([
|
||||
'content' => trans_choice(
|
||||
'back.missing_translations',
|
||||
$missingLocales->count() > 2 ? \INF : 1,
|
||||
['locales' => Str::upper($missingLocales->implode(', '))]
|
||||
),
|
||||
]);
|
||||
if ($missingLocales->isNotEmpty()) {
|
||||
throw ValidationException::withMessages([
|
||||
'content' => trans_choice(
|
||||
'back.missing_translations',
|
||||
$missingLocales->count() > 2 ? \INF : 1,
|
||||
['locales' => Str::upper($missingLocales->implode(', '))]
|
||||
),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue