enriclluelles/route_translator

Advice Request: route_translator & Accept-Language request header

Closed this issue ยท 4 comments

My complements on the great project here. It works flawlessly and was easy to setup/integrate.

I'm looking for advice in regards to the Accept-Language request header. What are the best practices for sites in general?

One possibility I see is that if a user arrives at the root path / with a request header Accept-Language=es;q=0, it could be automatically redirected to /es.

On the flip side, if a user arrives at a localized path /it then the locale from the localized path would take precedence and no redirect would happen.

I'm questioning if Accept-Language is even worth the effort and added complexity.

Has anyone else been through this? What did you decide?

Hi and thanks!

This is a good point and I'm open to ideas. This is worth at least a wiki page

I'm not using route_translator in production in the past few years, and I would avoid to manage the complexity of http headers in this gem

For this purpose, I was using http_accept_language and the following custom controller concern: https://github.com/diowa/icare/blob/main/app/controllers/concerns/route_localizer.rb

I think that it is possible to skip route translator's around_action :set_locale_from_url for the root_path action, or maybe prepend an around action, and take advantage of http_accept_language to conditionally redirect to the proper path

Let me know

That's a good suggestion. I believe I will go this route with http_accept_language and will have to dig into the implementation of :set_locale_from_url a bit. Much appreciated.

And if you're interested, I'm using route_translator in Password Pusher (staging site with route_translator) pending release to pwpush.com this weekend.

I believe we can close this now. Thanks for the help!

@pglombardo if you want to share a snippet of code for this use case, feel free to add a wiki page, that would help others