EasyAdminBundle icon indicating copy to clipboard operation
EasyAdminBundle copied to clipboard

Enable locale switching from dashboard

Open Lustmored opened this issue 3 years ago • 16 comments

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 en as fallback for now?

Lustmored avatar Mar 25 '22 11:03 Lustmored

@javiereguiluz any chance you could take a look here? :smile_cat:

Lustmored avatar Apr 15 '22 11:04 Lustmored

Hello @javiereguiluz, I think this PR can be merged :)

jmsche avatar Apr 22 '22 09:04 jmsche

@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 :)

Lustmored avatar May 20 '22 11:05 Lustmored

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 avatar May 21 '22 08:05 javiereguiluz

@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"?

Lustmored avatar May 21 '22 08:05 Lustmored

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 🤔

javiereguiluz avatar May 21 '22 10:05 javiereguiluz

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 avatar May 21 '22 11:05 Lustmored

@Lustmored work for me too, may be add possibilty to remove functionnality in dashboard could be nice ?

john-dufrene-dev avatar May 21 '22 11:05 john-dufrene-dev

@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 avatar May 21 '22 11:05 Lustmored

@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 avatar May 21 '22 12:05 john-dufrene-dev

@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) :)

Lustmored avatar May 21 '22 12:05 Lustmored

@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.

Lustmored avatar May 30 '22 11:05 Lustmored

As a bonus I've made (machine) translations of word Language in all locales that seem up to date.

Lustmored avatar May 30 '22 11:05 Lustmored

@jmsche Thank you :heart:

Lustmored avatar May 30 '22 11:05 Lustmored

@javiereguiluz just a friendly ping :smile_cat:

Lustmored avatar Jun 24 '22 08:06 Lustmored

@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 avatar Sep 14 '22 09:09 Lustmored

@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!

javiereguiluz avatar Sep 27 '22 18:09 javiereguiluz