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

Getting 'en_US.UTF-8' instead of 'en' #39

Open
wmertens opened this issue Apr 5, 2017 · 3 comments
Open

Getting 'en_US.UTF-8' instead of 'en' #39

wmertens opened this issue Apr 5, 2017 · 3 comments

Comments

@wmertens
Copy link

wmertens commented Apr 5, 2017

When the browser sends a preference for 'en_US.UTF-8' and the provided locale list has 'en', I would expect the locale to be set to 'en', not the full string. Is that a wrong assumption?

I'm using express 4 and

import locale from 'locale'
const languages = ['en', 'nl']
app.use(locale(languages), (req, res, next) => {
		if (!languages.includes(req.locale)) {
			console.error(`!!! ${req.locale} was badly picked by locale`)
			req.locale = languages[0]
		}
		next()
})

to detect this situation.

@stuartf
Copy link
Collaborator

stuartf commented Apr 6, 2017

You're probably getting the default locale which is automatically set to match the locale of the environment.

@wmertens
Copy link
Author

wmertens commented Apr 6, 2017 via email

@florrain
Copy link
Owner

florrain commented Apr 6, 2017

Hi @wmertens - Indeed, the lib doesn't know anything about the charset suffix right now. So the locale matching probably doesn't work at all if there's a charset. You can pass the default locale when you register the middleware: locale(languages, 'en') which should solve your issue.

Not an actual bug per se but input sanitization wouldn't hurt as it seems to be the common format to include the charset on UNIX environments. If someone is willing to hack this in a PR, it'd be very welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants