Skip to content

Commit 0e7c283

Browse files
committed
feat: add default portal and redirect route configuration for translations
1 parent 118f577 commit 0e7c283

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

config/translatable.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@
2929
'styles' => [
3030
'table-cell-wrapper' => 'd-flex justify-content-center align-items-center',
3131

32-
'icons' => [
32+
'icons' => [
3333
'add' => 'fas fa-plus',
3434
'edit' => 'fas fa-edit',
3535
],
3636
],
37+
38+
'default_portal' => 'web',
39+
'default_redirect_route' => 'home',
3740
];

src/Traits/UrlGenerators/DbTranslatedUrlGenerator.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,16 @@ public function url(string $action = 'show', Language|string|null $locale = null
3636
} elseif ($translation = $this->getTranslation($localeCode)) {
3737
$params[] = $translation->routeKeyForPortal($portal);
3838
} else {
39+
// If the portal is the default portal, and there is no translation available, redirect to default route
40+
if ($portal === config('translatable.default_portal')) {
41+
return translate_route(config('translatable.default_redirect'));
42+
}
43+
44+
// Switch to the create route if no translation exists
3945
$route_name = $portal ? "{$portal}.{$model_route_name}.create" : "{$model_route_name}.create";
46+
47+
// Add in the lang parent param to indicate which model to translate
48+
$params['lang_parent'] = $this->getKey();
4049
}
4150

4251
return translate_route(name: $route_name, parameters: $params, locale: $localeCode);

0 commit comments

Comments
 (0)