-
-
Notifications
You must be signed in to change notification settings - Fork 44
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
possibility to get region from accept language #23
Comments
So when a web browser sends "en-us", you are referring to the "us" part, is that right? If you call |
correct.
all the bits and pieces are i'm interested in are Currently I did a workaround using // something like:
const prefers = [...new Set(req.acceptsLanguages().map(lang => lang.split('-')[1].toUpperCase()).filter(Boolean))]
const allowed = ['SE', 'NO', 'GB', 'DK', 'US', ...rest_of_all_the_world]
const preferred = prefers.find(pref => allowed.includes(pref)) // SE it would be neat if the language and the region was kind of two separated methods/things Would wish for something like this to exist: req.region(['SE'])
const regions = req.regions() // ['SE', 'US']
const preferred = regions.find(region => allowed.has(region)) // SE ☝️ feature request maybe? |
Gotcha. I think that should be possible. Note that the second thing after the firsr dash is not always the region and the region can be the numeric code. It looks like from the spec that in order to know the region you need to have the list for certain ambitious situations. So it seems we probably first need to make a module that has all the iso data needed (if there is not already one) and then from there, we can parse the language tag to get the region data 👍 |
Sounds good 👍 if you don't have a region database/package then here is one coming from: google-libphonenumber if it is to any help ["AC","AD","AE","AF","AG","AI","AL","AM","AO","AR","AS","AT","AU","AW","AX","AZ","BA","BB","BD","BE","BF","BG","BH","BI","BJ","BL","BM","BN","BO","BQ","BR","BS","BT","BW","BY","BZ","CA","CC","CD","CF","CG","CH","CI","CK","CL","CM","CN","CO","CR","CU","CV","CW","CX","CY","CZ","DE","DJ","DK","DM","DO","DZ","EC","EE","EG","EH","ER","ES","ET","FI","FJ","FK","FM","FO","FR","GA","GB","GD","GE","GF","GG","GH","GI","GL","GM","GN","GP","GQ","GR","GT","GU","GW","GY","HK","HN","HR","HT","HU","ID","IE","IL","IM","IN","IO","IQ","IR","IS","IT","JE","JM","JO","JP","KE","KG","KH","KI","KM","KN","KP","KR","KW","KY","KZ","LA","LB","LC","LI","LK","LR","LS","LT","LU","LV","LY","MA","MC","MD","ME","MF","MG","MH","MK","ML","MM","MN","MO","MP","MQ","MR","MS","MT","MU","MV","MW","MX","MY","MZ","NA","NC","NE","NF","NG","NI","NL","NO","NP","NR","NU","NZ","OM","PA","PE","PF","PG","PH","PK","PL","PM","PR","PS","PT","PW","PY","QA","RE","RO","RS","RU","RW","SA","SB","SC","SD","SE","SG","SH","SI","SJ","SK","SL","SM","SN","SO","SR","SS","ST","SV","SX","SY","SZ","TA","TC","TD","TG","TH","TJ","TK","TL","TM","TN","TO","TR","TT","TV","TW","TZ","UA","UG","US","UY","UZ","VA","VC","VE","VG","VI","VN","VU","WF","WS","XK","YE","YT","ZA","ZM","ZW"] also found this earlier: |
Hi 👋
I'm using express, and i'm trying to figure out how to get the preferred region code (2 letter country code)
do you have any recommendations to deal with this?
almost feel like the negotiator dep should have some kind of feature to retrieve it
The text was updated successfully, but these errors were encountered: