Skip to content

Conversation

@mapmeld
Copy link

@mapmeld mapmeld commented Jul 26, 2025

As described in #66 , there are multiple ways to write Chinese-language locales and they are getting reduced to zh by setLanguage and browserLanguage functions

My proposal is:

  • Using ALT_LOCALES, locales such as zh-HK will be handled as OSM and Mapbox's supported locale zh-Hant
  • Use recursion to remove locales piece by piece, for example zh-Hans-CN should be reduced to zh-Hans first and not a one time split to zh
  • Add a zh-HK example page

Comment on lines 3 to 5
'zh-cn': 'zh-Hans',
'zh-hk': 'zh-Hant',
'zh-tw': 'zh-Hant',
Copy link
Contributor

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('-')));
Copy link
Contributor

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.

Copy link
Author

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) {
Copy link
Contributor

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.

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

Successfully merging this pull request may close these issues.

2 participants