filamentphp / filament

A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS.
https://filamentphp.com
MIT License
18.98k stars 2.93k forks source link

Export using `database` queue doesn't respect app locale #12974

Closed valpuia604 closed 5 months ago

valpuia604 commented 5 months ago

Package

filament/filament

Package Version

v3.2.83

Laravel Version

v11.8.0

Livewire Version

v3.5

PHP Version

v8.2

Problem description

When switching to different locale and export data using QUEUE_CONNECTION=database doesn't respect app locale and always storing data in en language. if QUEUE_CONNECTION=sync then it's correct.

Expected behavior

Export with queue respect app locale

Steps to reproduce

clone, install login using test@example.com and password Change locale Goto user, export user using non english locale run queue php artisan queue:work Check database/notifications

Reproduction repository

https://github.com/valpuia604/fila-noti-db-bug

Relevant log output

No response

zepfietje commented 5 months ago

There's no way for the queue worker to know the selected locale when you're not storing it. Not a Filament bug, right? 🙂

valpuia604 commented 5 months ago

I am not sure about "you're not storing it", how to store the locale? I hope we can do sth like this but don't know where exactly to change (for PR) https://laravel.com/docs/11.x/notifications#localizing-notifications

zepfietje commented 5 months ago

I'm not sure I fully understand the original issue. You're talking about data being stored in English, but we're talking about exports right? Not imports?

valpuia604 commented 5 months ago

Yes, store in "English" only in export (I didn't check for imports atm). Like I said in OP using sync it's working fine.

Can you explain how we can store (not sure this word is correct or not) the selected locale for queue work database?

zepfietje commented 5 months ago

Could you clarify the issue here? I'm not sure what you're referring to with "storing in English".

valpuia604 commented 5 months ago

Screenshot from 2024-05-28 15-25-22

As we can see from this image, my locale is km but after exported the title (Export completed), message (your league...) and download button text never translate because of queue database.. like I said these are working fine if I use sync

What I meant for "storing in English" is after exported, all these notifications are displayed based on database data, so my database contains only "English" word, not others (for database not sync queue). hope you understand

zepfietje commented 5 months ago

This should just work then, right? https://laravel.com/docs/11.x/notifications#localizing-notifications

valpuia604 commented 5 months ago

I hope that links resolves this, but I don't know how to apply that one in "Export"

zepfietje commented 5 months ago

Just implement the HasLocalePreference interface on your User model?

Umar-Farooq-Shafi commented 4 months ago

not working

    /**
     * @return string|null
     */
    public function preferredLocale(): ?string
    {
        return \App::getLocale();
    }