How to translate slug

Multi tenant context, multi lang How to translate resource slug? (->getSlug()) Slug is called before middleware. Exists a way to achieve it? In this case my locale is ja_JP
Staff staffs | en
Staff staffs | en
Place places | en
Place places | en
Unit units | en
Unit units | en
Staff staffs | en
Staff staffs | en
Place places | en
Place places | en
Unit units | en
Unit units | en
Staff staffs | en
Staff staffs | en
Place places | en
Place places | en
Unit units | en
Unit units | en
Staff staffs | en
Staff staffs | en
Place places | en
Place places | en
Unit units | en
Unit units | en
2 Replies
Matthew
Matthew2mo ago
You need a file under resources/lang/ja_JP. You specify with return __(path) For more info https://laravel.com/docs/11.x/localization
galli.roberto
galli.robertoOP2mo ago
is called before middleware I cant change locale. The solution is session. In login set session(['locale', '']) and in a boot method of provider use App::setLocale(session()->get('locale')) the code has to be improved. I only check that in login filament doesn't register router, it can be work I found the solution to have all slug route translated In Resource
public static function routes(Panel $panel): void
{
$originalLocale = app()->getLocale();
foreach(config('app.locales') as $locale) { // <----- AVAILABLE LOCALE IN YOU APP
app()->setLocale($locale);
Route::name(static::getRelativeRouteName() . '.')
->prefix(static::getRoutePrefix())
->middleware(static::getRouteMiddleware($panel))
->withoutMiddleware(static::getWithoutRouteMiddleware($panel))
->group(function () use ($panel) {
foreach (static::getPages() as $name => $page) {
$page->registerRoute($panel)?->name($name);
}
});
}

app()->setLocale($originalLocale);
}
public static function routes(Panel $panel): void
{
$originalLocale = app()->getLocale();
foreach(config('app.locales') as $locale) { // <----- AVAILABLE LOCALE IN YOU APP
app()->setLocale($locale);
Route::name(static::getRelativeRouteName() . '.')
->prefix(static::getRoutePrefix())
->middleware(static::getRouteMiddleware($panel))
->withoutMiddleware(static::getWithoutRouteMiddleware($panel))
->group(function () use ($panel) {
foreach (static::getPages() as $name => $page) {
$page->registerRoute($panel)?->name($name);
}
});
}

app()->setLocale($originalLocale);
}
but at the moment I still haven't figured out how to translate panel path, panel loginRouteSlug, ... it's too hard translate the whole uri. i keep it in english

Did you find this page helpful?