Case sensitive locale in url?
Frexuz opened this issue · 6 comments
Seems all urls are forced into lowercase. Is there any workaround?
config.i18n.default_locale = :'en-US'
config.i18n.available_locales = ['en-US', 'sv-SE']
localhost/en-us/start
works
localhost/en-US/start
doesn't
its quite difficult to work with, since I always have to convert between the case sensitive formats.
I18n.locale = extract_from_url
will raise an exception if you do = 'en-us'
saying its not a valid locale.
Hi,
thanks for reporting this.
Apparently, Rails routes are case sensitive, because URLs are case sensitive
Please take a look at this stackoverflow thread: https://stackoverflow.com/questions/2291907/rails-routes-how-to-make-them-case-insensitive
Thanks, I had no idea ;D
Hope it helps, closing here
Still, the point is that route_translator generates lowercase routes when it shouldn't (for locale "en-US" I have routes "en-us" and I would rather have them in proper format since URLs are case sensitive)
This is documented in the readme:
- locale_segment_proc
The locale segment of the url will by default belocale.to_s.downcase
You can supply your own mechanism via a Proc that takeslocale
as an argument, e.g.config.locale_segment_proc = ->(locale) { locale.to_s.upcase }
Feel free to fix to customize this behaviour.
IMHO since URLs are case sensitive, downcasing is a good thing, just like in slugs
Ops, by bad :-) Yeah, making 'config.locale_segment_proc = ->(locale) { locale.to_s }' does exactly what I needed