locale_setter
locale_setter copied to clipboard
Change the way url param works
Hi,
I think that the current solution for the url param is a little bit misleading, for example:
Current realisation is:
def default_url_options(options = {})
if i18n.locale == i18n.default_locale
options
else
{LocaleSetter.config.url_param => i18n.locale}.merge(options)
end
end
If I am using the site's default locale then all is ok, but if any of my users have a different locale via db locale
column (or domain, not so matter) then all links will have a locale
param. I think that this is polluting url because we already setup locale via different source.
So I think that maybe is better to add locale
param if only it is already exists in url without any checks to the locale.
And then workflow will be like this:
- User lands to the main page (default locale will be used)
- User logs in (locale will switch to preferred one, no url changes)
- User passing
locale
param to url (or clicks a link that will force it) - All other links will have a
locale
param
If this is ok and I haven't missed something, then I'll provide a solution for this.
I agree. it is annoying that locale param is automatically added to every link. This should only be used when switching between locales and should probably set a session variable to save the choice
+1
Also would there be a way to make URLs look prettier? So instead of:
http://example.com/articles?locale=jp
They will always be:
http://example.com/jp/articles
@assimovt you can still achieve this and use this gem. To do this, you need to setup your routes with a locale scope or simply use this other gem (works in compliment with locale_setter): https://github.com/svenfuchs/routing-filter
+1 for this
Note that #14 solves this issue for me, @jcasimir maybe you could release a new version that includes this PR? I'm currently bundling straight from HEAD to get this fix, and this has been working great in production.