Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(examples/with-react-intl): Bug when accept-language is not 'en' #5488

Merged
merged 1 commit into from
Oct 20, 2018

Conversation

ultrox
Copy link
Contributor

@ultrox ultrox commented Oct 20, 2018

Expected Behaviour

When you run npm run dev and visit the http:https://localhost:3000 with browser with locale other then 'en' in development you should be served eng version of the app.

image

Also expected in dev in console per explanation in readme ( & after fix is applyed)

image

Actual Behaviour

When you visit app in dev mode & in production, app crashes
image

Reason

package 'accept' returns false if can't find language in offered list of languages, then later on
bool is attempted to be split, and app crashes in prod & dev.

…ther then 'en'

package accept returns false if can't find language in offered list of languages, then later on
bool is attempted to be split, and app crashes in prod & dev
@timneutkens timneutkens merged commit 2ce3f39 into vercel:canary Oct 20, 2018
@timneutkens
Copy link
Member

Makes sense 👍

@ultrox
Copy link
Contributor Author

ultrox commented Oct 21, 2018

Thanks! @timneutkens

@matthewlilley
Copy link
Contributor

matthewlilley commented Dec 2, 2018

@ultrox @timneutkens My default locale is en, and now I'm getting the locale.split is not a function error, even with this fix.

    accept.language(languages) //  is returning['en-GB', 'en']
    getLocaleDataScript(locale) // then this function calls split on an array
   

rauchg pushed a commit that referenced this pull request Dec 3, 2018
* Fix for locale.split is not a function.

Following from #5488

- Renamed languages to supportedLanguages
- Firstly, accept languages based on supportedLanguages
- And finally, accept a single language, if it returns false, the default of 'en' is used.

I looked at the navigator library, which is used by 'accept', this should be a more solid solution, since we can now know that `const locale` is always a string.

// Before (Sometimes returns an array as `const local`)
const locale = accept.language(languages) || 'en' 

// After (Always returns a string)
const locale = accept.language(accept.languages(supportedLanguages)) || 'en';

* Update server.js

Update variable name.
@lock lock bot locked as resolved and limited conversation to collaborators Dec 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants