Enable locale switching from dashboard
This is pretty straight-forward feature to allow locale switching in dashboards. It's a proof-of-concept and not finished PR.
The idea is to be able to pass list of available locales into dashboard configuration. When done - dashboard should display an option to change locale. I have reused appearance CSS ~~classes mainly because yarn watch is making changes to all CSS files within project and that's surely undesired~~.
TODO:
- [x] gather feedback
- [x] (optional) create better styling if needed
- [x] add translations - should I translate new label into all languages (via translator maybe) or just leave
enas fallback for now?
@javiereguiluz any chance you could take a look here? :smile_cat:
Hello @javiereguiluz, I think this PR can be merged :)
@javiereguiluz any chance you could take a look at this? Along with translatables I think this enables even better multi-lingual dashboards out of the box :)
I'm testing this feature but it doesn't work for me 😐
I click on a language and I see the _locale attribute added to the URL ... but that doesn't translate contents for me. Also, none of the links of the page include the new _locale, so the language change doesn't persist and it's annoying to have to select it for each page.
I think this would need many more changes to make it work as most users would expect: the locale change must translate the entire page contents and must be persistent between requests. See https://symfony.com/doc/current/translation/locale.html
@javiereguiluz did you change EasyAdmin routes import to /{_locale}/admin from /admin (or similar)? I believe without that change there is no way to make it work.
I probably need to rework docs comment:
// When using this option you should also add
// {_locale} placeholder in dashboard route path (e. g. '/admin/{_locale}').
To reflect this - probably "should" -> "need to"?
Yes, I've changed what you said and now it's working 🙌 It still surprises me that everything works without any other change on our side 🤔
The reason for that is whenever _locale is present in a route Symfony router context handles it for ourselves and it does that very well (mostly via LocaleListener) 👍
I think there is a point in adding info about that route requirement to other parts of the doc, I will take a look again early next week. In the meantime could you please let me know how to proceed with translations of added string? Machine translate them or leave untranslated in this PR?
@Lustmored work for me too, may be add possibilty to remove functionnality in dashboard could be nice ?
@Lustmored work for me too, may be add possibilty to remove functionnality in dashboard could be nice ?
This feature is disabled by default and requires explicit configuration to work, so I don't think I understand what do you mean
@Lustmored okay I understand what you mean,
Always need to use in url /{_locale} ? Session system or other system not possible ?
In symfony 6.1 for example new system for locale is coming, we are not oblige to pass parameter in url with this system
https://symfony.com/blog/new-in-symfony-6-1-locale-switcher
@john-dufrene-dev I believe locale switcher has other purpose (to ease running parts of the code with other locale than the rest) and you can use any other method of using _locale parameter if you have own logic for that.
Generally speaking - adding _locale parameter to the route path is the default and recommended way (just like in Symfony), but you can handle it any other way that is Symfony compatible and it still will work (as EasyAdmin is fueled by Symfony) :)
@javiereguiluz Sorry it took a bit longer - I had really busy week. And so did you, so congratulations on 6.1 release :tada:
Back to the point - I went through the docs and found 2 or 3 places where IMO it was worth to add a note about _locale handling. I have also created UPGRADE.md entry. I'm not great at writing docs (but doing my best!), so wording might be imperfect, but hopefully it will allow users to easily set up multilingual dashboards.
As a bonus I've made (machine) translations of word Language in all locales that seem up to date.
@jmsche Thank you :heart:
@javiereguiluz just a friendly ping :smile_cat:
@michaelKaefer @javiereguiluz I have rebased this work and migrated to new LocaleDto so that we can configure more than just a locale name and display name (for now just an icon, but it's still a step forward).
@Lustmored thanks A LOT for this contribution 🙇 I've tested it again and it works perfectly. I'm going to do some minor design tweaks in a separate PR, but let's merge this right now. Thanks!