locale_setter icon indicating copy to clipboard operation
locale_setter copied to clipboard

Change the way url param works

Open somebody32 opened this issue 11 years ago • 5 comments

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:

  1. User lands to the main page (default locale will be used)
  2. User logs in (locale will switch to preferred one, no url changes)
  3. User passing locale param to url (or clicks a link that will force it)
  4. 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.

somebody32 avatar Apr 11 '13 06:04 somebody32

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

aaronchi avatar Apr 23 '13 22:04 aaronchi

+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 avatar Aug 19 '13 07:08 assimovt

@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

steakchaser avatar Oct 15 '13 22:10 steakchaser

+1 for this

zykadelic avatar Mar 24 '14 14:03 zykadelic

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.

ludwigschubert avatar Dec 30 '14 15:12 ludwigschubert