# 当浏览器首次接受的语言是\`zh-HK\`时，默认UI语言不正确

**URL:** <https://meta.discourse.org/t/when-first-browser-accept-language-is-zh-hk-the-default-ui-language-is-incorrect/198066>\
**Category:** UX\
**Created:** [2021年七月24日 12:56 UTC](https://meta.discourse.org/t/when-first-browser-accept-language-is-zh-hk-the-default-ui-language-is-incorrect/198066 "2021-07-24T12:56:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![alvinhochun](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alvinhochun/32/228752_2.png) [@alvinhochun](https://meta.discourse.org/u/alvinhochun)\
**Post date:** [2021年七月24日 12:56 UTC](https://meta.discourse.org/t/when-first-browser-accept-language-is-zh-hk-the-default-ui-language-is-incorrect/198066/1 "2021-07-24T12:56:46Z")

</div>

Discourse currently has Traditional Chinese (zh\_TW) and Simplified Chinese (zh\_CN) localization. However when I have the browser’s accept-language set to `zh-HK` first, Discourse errorneously selects `zh_CN` as the default language.

Most users from Taiwan (`zh-TW`), Hong Kong (`zh-HK`) and Macau (`zh-MO`) prefer Traditional Chinese, so for these accept-language values Discourse should select `zh_TW` as the default language instead. (Technically you can also make use of [Unicode CLDR likely subtags](https://unicode-org.github.io/cldr-staging/charts/38/supplemental/likely_subtags.html) information, but for just Chinese it would be a bit overkill.)

I also want to point out that, having “中文” and “中文 (TW)” in the language selection is _extremely weird_. It really should list “简体中文” for Simplified Chinese and “正體中文” for Traditional Chinese instead.

---

<div class="post-metadata">

**Author:** ![schleifer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/schleifer/32/86416_2.png) [@schleifer](https://meta.discourse.org/u/schleifer)\
**Post date:** [2021年七月27日 13:51 UTC](https://meta.discourse.org/t/when-first-browser-accept-language-is-zh-hk-the-default-ui-language-is-incorrect/198066/2 "2021-07-27T13:51:49Z")

</div>

> [@alvinhochun](#):
>
> 在语言选择中同时出现“中文”和“中文 (TW)" _非常奇怪_

这确实如此。这里有一个 PR 来修改它：

> <https://github.com/discourse/discourse/pull/13861>
>
> Discussion at https://meta.discourse.org/t/198066

（Twitter 使用“繁體”而不是“正體”，所以我跟随了他们的做法。）

@gerhard，这就是需要修改的全部了吗？

---

<div class="post-metadata">

**Author:** ![schleifer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/schleifer/32/86416_2.png) [@schleifer](https://meta.discourse.org/u/schleifer)\
**Post date:** [2021年七月27日 14:41 UTC](https://meta.discourse.org/t/when-first-browser-accept-language-is-zh-hk-the-default-ui-language-is-incorrect/198066/3 "2021-07-27T14:41:11Z")

</div>

要解决标题中的问题，“正确”的做法是我们使用 zh-Hans 和 zh-Hant，但各浏览器提供的选项并不一致。

Chrome：

 ![image](https://global.discourse-cdn.com/meta/original/3X/3/9/3982f0072715630fff4bef270a16480718d51efd.png)

Firefox：

 ![image](https://global.discourse-cdn.com/meta/original/3X/c/3/c3e216af2e8df2fa74c0fc92ab306413981ae489.png)

我在 Safari 中找不到任何选择语言的方法，因此它是否始终使用系统设置？这可能包含所有这些选项：

 ![image](https://global.discourse-cdn.com/meta/original/3X/8/3/8353d7396b0af17a6903bc4618c0e208e574d97c.png)  
 ![image](https://global.discourse-cdn.com/meta/original/3X/4/9/49a3f663f6c342538714162f9c7d1a308f4ed91b.png)

[文档](https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPInternational/LanguageandLocaleIDs/LanguageandLocaleIDs.html) 指出，macOS 支持类似 `zh-Hans_HK` 的语言代码。我很好奇浏览器是否能接收到这样的代码。

---

<div class="post-metadata">

**Author:** ![alvinhochun](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alvinhochun/32/228752_2.png) [@alvinhochun](https://meta.discourse.org/u/alvinhochun)\
**Post date:** [2021年七月28日 06:46 UTC](https://meta.discourse.org/t/when-first-browser-accept-language-is-zh-hk-the-default-ui-language-is-incorrect/198066/4 "2021-07-28T06:46:58Z")

</div>

> [@schleifer](#):
>
> （Twitter 使用“繁體”而非“正體”，所以我遵循了他们的用法。）

台湾的 FOSS 本地化社区更倾向于使用“正體”而非“繁體”，但对我来说两者并无妨。

> [@schleifer](#):
>
> 要解决标题中的问题，“正确”的做法是我们使用 zh-Hans 和 zh-Hant，但浏览器在提供的选项上并不一致。

只要只有两种变体，代码部分大多是表面上的。很多时候，即使名称显示为“中文（繁体）”，底层代码仍然是 `zh_TW`。无论哪种情况，你都需要处理浏览器发送的语言标签中的 `language-region` 和 `language-script-region` 两种变体。据我所知，Android 上的 Firefox 会根据 Android 系统区域设置，发送带有 `zh-Hant-HK` 的 accept-language 请求。
