Closed adrianthedev closed 4 years ago
This may not fix it. Looking into it.
Done. It's going to fallback to default locale if the detected one is invalid.
Hey @adrianthedev thanks so much for looking into this and making a PR 🙏
Looking at your code, it looks like if we get a locale of "ro-RO" in the headers, then we will default to a locale of "en" (ie our default locale).
This would mean browsers in Romania (local "ro-RO") would see English rather than Romanian if they come to our site. It also means we are working on the assumption that "ro-RO" is an erroneous locale when when in fact it is not.
Rather than raising an error and defaulting to English what do you think about fixing the regex that picks up the locale so that it is more forgiving? Specifically this line: request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first
Atm this line only picks up the first two letters in the headers, but we could change it to pick up all the expected locales.
Thoughts? Happy to discuss :)
I tried picking up the full ro-RO
value but that doesn't really work by itself. It seems we need to use :en
or :es
, the available locales.
You can tweak the regex like that no worries, but that isn't a fix by itself. The fix is to fallback to something known, IMHO.
BTW, the app is still broken atm. It's possible that users in the US can't access it because they have a browser locale different than en
or es
. I would push a fix ASAP.
Ah of course we don't have all the locales 🤦 my bad! Defaulting to the available :en
/:es
locales makes perfect sense 👍
I'll push the change now, cheers @adrianthedev
The locale regex only pulls up two letters
ro
and it seems it's not a valid locale.This update fixes it to pick up
ro-RO
.Error
``` An I18n::InvalidLocale occurred in projects#index: 2020-08-25T16:30:09.593225+00:00 app[web.1]: 2020-08-25T16:30:09.593226+00:00 app[web.1]: "ro" is not a valid locale 2020-08-25T16:30:09.593226+00:00 app[web.1]: app/controllers/application_controller.rb:118:in `switch_locale' 2020-08-25T16:30:09.593226+00:00 app[web.1]: 2020-08-25T16:30:09.593227+00:00 app[web.1]: 2020-08-25T16:30:09.593227+00:00 app[web.1]: ------------------------------- 2020-08-25T16:30:09.593228+00:00 app[web.1]: Request: 2020-08-25T16:30:09.593228+00:00 app[web.1]: ------------------------------- 2020-08-25T16:30:09.593228+00:00 app[web.1]: 2020-08-25T16:30:09.593229+00:00 app[web.1]: * URL : https://www.helpwithblackequity.com/favicon.ico 2020-08-25T16:30:09.593229+00:00 app[web.1]: * HTTP Method: GET 2020-08-25T16:30:09.593230+00:00 app[web.1]: * IP address : 86.123.198.107 2020-08-25T16:30:09.593230+00:00 app[web.1]: * Parameters : {"controller"=>"projects", "action"=>"index", "category_slug"=>"favicon", "format"=>"ico"} 2020-08-25T16:30:09.593231+00:00 app[web.1]: * Timestamp : 2020-08-25 09:30:09 -0700 2020-08-25T16:30:09.593231+00:00 app[web.1]: * Server : 1ccec1b7-2aa6-4158-8f90-a2c27bc8b6dd 2020-08-25T16:30:09.593231+00:00 app[web.1]: * Rails root : /app 2020-08-25T16:30:09.593232+00:00 app[web.1]: * Process: 4 2020-08-25T16:30:09.593232+00:00 app[web.1]: 2020-08-25T16:30:09.593232+00:00 app[web.1]: ------------------------------- 2020-08-25T16:30:09.593233+00:00 app[web.1]: Session: 2020-08-25T16:30:09.593233+00:00 app[web.1]: ------------------------------- 2020-08-25T16:30:09.593233+00:00 app[web.1]: 2020-08-25T16:30:09.593234+00:00 app[web.1]: * session id: [FILTERED] 2020-08-25T16:30:09.593234+00:00 app[web.1]: * data: {} 2020-08-25T16:30:09.593234+00:00 app[web.1]: 2020-08-25T16:30:09.593235+00:00 app[web.1]: ------------------------------- 2020-08-25T16:30:09.593235+00:00 app[web.1]: Environment: 2020-08-25T16:30:09.593235+00:00 app[web.1]: ------------------------------- 2020-08-25T16:30:09.593235+00:00 app[web.1]: 2020-08-25T16:30:09.593236+00:00 app[web.1]: * GATEWAY_INTERFACE : CGI/1.2 2020-08-25T16:30:09.593236+00:00 app[web.1]: * HTTP_ACCEPT : image/webp,image/apng,image/*,*/*;q=0.8 2020-08-25T16:30:09.593237+00:00 app[web.1]: * HTTP_ACCEPT_ENCODING : gzip, deflate, br 2020-08-25T16:30:09.593237+00:00 app[web.1]: * HTTP_ACCEPT_LANGUAGE : ro-RO,ro;q=0.9,en-US;q=0.8,en;q=0.7 ```