-
Notifications
You must be signed in to change notification settings - Fork 50
Handle alternate locale names, long locale names #67
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
base: master
Are you sure you want to change the base?
Conversation
| 'zh-cn': 'zh-Hans', | ||
| 'zh-hk': 'zh-Hant', | ||
| 'zh-tw': 'zh-Hant', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how common it is, but zh-SG and zh-MO normally map to zh-Hans and zh-Hant, respectively, based on official status.
index.js
Outdated
| return languageCode; | ||
| if (language.indexOf('-') > -1) { | ||
| // reduce longer locales (en-US, zh-Hant-TW) to shorter forms | ||
| return browserLanguage(supportedLanguages, language.slice(0, language.lastIndexOf('-'))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works, though reduce() would be more succinct, or just a for loop incrementing the end of the range of parts.join('-') to look up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed these to while loops and added tests for "en-US" -> "en" and "zh-HK" to "zh-Hant"
MapBox page showing name_zh-Hant is correct label: https://docs.mapbox.com/data/tilesets/reference/mapbox-streets-v8/
index.js
Outdated
| } | ||
| if (supportedLanguages.indexOf(languageCode) > -1) { | ||
| return languageCode; | ||
| function browserLanguage(supportedLanguages, language) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function isn’t recursive anymore, so nothing ever passes in language anymore. language can go back to being a local constant.
As described in #66 , there are multiple ways to write Chinese-language locales and they are getting reduced to
zhbysetLanguageandbrowserLanguagefunctionsMy proposal is:
ALT_LOCALES, locales such aszh-HKwill be handled as OSM and Mapbox's supported localezh-Hantzh-Hans-CNshould be reduced tozh-Hansfirst and not a one time split tozhzh-HKexample page