Motivation
Throughout history, the Chinese language has been associated with multiple language codes (RFC 5646 with ISO-639 zh). The most commonly used ones include zh-CN
(Simplified Hanzi Script of Chinese Mandarin primarily used in PRC, etc.), zh-TW
(Traditional Hanzi Script of Chinese Mandarin mainly used in Taiwan, etc.), and zh
(often synonymous with zh-CN
). There are also less utilized codes like zh-HanS
and zh-HanT
, which have similar effects to zh-CN
and zh-TW
respectively, but without specified regions.
The upcoming ECMAScript Intl
API will assign distinct display names to all these codes, carrying with them regional and political connotations. To maintain neutrality in my application, I prefer using zh-HanS
and zh-HanT
instead of zh-CN
and zh-TW
.
Problem
Most modern browsers always send Accept-Language: zh-CN; zh;
for zh-CN
/zh-HanS
, and Accept-Language: zh-TW; zh;
for zh-TW
/zh-HanT
in HTTP headers. As a result, if I use src/i18n/zh-HanS
/ src/i18n/zh-HanT
in my application, the
detectLocale(initAcceptLanguageHeaderDetector({headers})
function of typesafe-i18n
will fail to identify the correct locale, attempt to fallback to zh
, and ultimately end up at the baseLocale (en
).
Question
How can I create aliases for these codes and ensure the detector correctly falls back to the intended language?