Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use trans in panel config after upgrade #7604

Closed
datlechin opened this issue Aug 9, 2023 · 13 comments · Fixed by #7661
Closed

Cannot use trans in panel config after upgrade #7604

datlechin opened this issue Aug 9, 2023 · 13 comments · Fixed by #7661
Labels
bug Something isn't working unconfirmed

Comments

@datlechin
Copy link
Contributor

Package

filament/filament

Package Version

v3.0.14

Laravel Version

v10.18.0

Livewire Version

No response

PHP Version

PHP 8.2

Problem description

Cannot use translation in panel config after upgrade from v3.0.8 to v3.0.14

Target class [translator] does not exist.
            ->userMenuItems([
                MenuItem::make()
                    ->label(__('My Profile')) // error right here
                    ->url(fn () => Profile::getUrl())
                    ->icon('heroicon-o-user-circle'),
            ]);

Expected behavior

works

Steps to reproduce

Use trans() or __() in admin panel service

Reproduction repository

https://github.com/datlechin/filament

Relevant log output

No response

@datlechin datlechin added bug Something isn't working unconfirmed labels Aug 9, 2023
@nielspeen
Copy link

As you came from 3.0.8, I can confirm this starts with 3.0.14. Downgrading to 3.0.13 fixes it.

@howdu
Copy link
Contributor

howdu commented Aug 9, 2023

I had a similar issue- solved by using a closure ->label(() => __('My Profile'))

@datlechin
Copy link
Contributor Author

@howdu how about this

            ->navigationGroups([
                __('Courses'),
                __('Blog'),
                __('Forum'),
                __('Administration'),
            ])

@howdu
Copy link
Contributor

howdu commented Aug 9, 2023

Use the full class

->navigationGroups([
    NavigationGroup::make()
        ->label(fn () => __('Example'))
        ->collapsible(),
    NavigationGroup::make()
        ->label(fn () => __('Example'))
        ->collapsible(),
])

@datlechin
Copy link
Contributor Author

It works btw I don't think this is a good way to solve this issue

@danharrin
Copy link
Member

Correct me if I'm wrong. In 3.0.13, using __() does not actually translate anything, if you set the locale in middleware. It just uses your default locale. You have to actually wrap it in a closure to be able to translate.

@datlechin
Copy link
Contributor Author

datlechin commented Aug 9, 2023

ok, you're right. before v3.0.13 translate takes no effect without closure function.

@danharrin
Copy link
Member

So this is probably a good error lol. It was kinda a coincidence that it worked before. There is no way to access the locale from a service provider, as it is run before middleware.

@danharrin danharrin closed this as not planned Won't fix, can't repro, duplicate, stale Aug 9, 2023
@lloricode
Copy link
Contributor

Correct me if I'm wrong. In 3.0.13, using __() does not actually translate anything, if you set the locale in middleware. It just uses your default locale. You have to actually wrap it in a closure to be able to translate.

Hi!, same issue as mine, using filament v3.0.15

It is working on this:

            ->navigationItems([
                NavigationItem::make('API Documentation')
                    ->group(fn () => trans('Documentation'))

But this is not working

            ->navigationGroups([
                fn () => trans('Documentation'),
            ])

Screenshot_2023-08-10_08-06-57

is there any wrong on my setup? hope can fix this

@lloricode
Copy link
Contributor

Correct me if I'm wrong. In 3.0.13, using __() does not actually translate anything, if you set the locale in middleware. It just uses your default locale. You have to actually wrap it in a closure to be able to translate.

Hi!, same issue as mine, using filament v3.0.15

It is working on this:

            ->navigationItems([
                NavigationItem::make('API Documentation')
                    ->group(fn () => trans('Documentation'))

But this is not working

            ->navigationGroups([
                fn () => trans('Documentation'),
            ])

Screenshot_2023-08-10_08-06-57

is there any wrong on my setup? hope can fix this

My bad, there is a way

            ->navigationGroups([
                NavigationGroup::make()
                    ->label( fn () => trans('Documentation')),

@twarkie
Copy link

twarkie commented Aug 11, 2023

I'm forcing my filament language to english with this code in AdminPanelProvider.php:

app()->setLocale('en');

...which also results in Target class [translator] does not exist. after upgrade from 3.0.12 to 3.0.16.

@danharrin
Copy link
Member

Should be fixed by #7661

@alphyon
Copy link

alphyon commented Aug 29, 2023

I have same issue using v3.0.36

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working unconfirmed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants