-
Type:
Improvement
-
Resolution: Unresolved
-
Priority:
Normal
-
None
-
Affects Version/s: None
-
Component/s: Back-end
After MBS-14482 (pull request #3888), zh-hant and zh-hans can be in MB_LANGUAGES. Browsers often send a region tag for Chinese, such as {{zh-T
W}}, instead of a script tag, such as zh-Hant. For example:
Accept-Language: zh-TW, zh, en
These region tags do not directly match zh-hant or zh-hans in MB_LANGUAGES. If a tag in Accept-Language is in MB_LANGUAGES, the server
can select it. zh-tw is not, so the server tries the next tag. I18N::LangTags also adds zh as the parent of zh-tw. If zh is in {{MB_L
ANGUAGES}}, as on beta, a browser that prefers zh-TW gets Simplified Chinese. If it is not, the browser gets English.
The same occurs for the six region tags below:
| Region tag | Region | Script |
|---|---|---|
| zh-TW | Taiwan | Traditional (zh-Hant) |
| zh-HK | Hong Kong | Traditional (zh-Hant) |
| zh-MO | Macau | Traditional (zh-Hant) |
| zh-CN | China | Simplified (zh-Hans) |
| zh-SG | Singapore | Simplified (zh-Hans) |
| zh-MY | Malaysia | Simplified (zh-Hans) |
The users can select their script in the language menu. But the first page that they see is in the wrong script, or in English.
Steps to reproduce
Prerequisites:
- The code of MBS-14482 (pull request #3888), without a fix for this issue.
- MB_LANGUAGES set to en zh zh-hant, and LANGUAGE_FALLBACK_TO_BROWSER set to 1 (the default).
- The zh_CN.UTF-8 and zh_TW.UTF-8 system locales.
- The installed translation catalogs (make -C po install) and the client bundles (./script/compile_resources.sh).
Send a request with the header and without a lang cookie:
curl -s -H 'Accept-Language: zh-TW, zh, en' http://localhost:5000/ | grep -o '<html lang="[^"]*"'
Expected: <html lang="zh-Hant", a page in Chinese (Traditional).
Actual: <html lang="zh", a page in Chinese (Simplified).
With MB_LANGUAGES set to en zh-hans, the header zh-CN, en gives English instead of Simplified Chinese.
Suggested fix
When the server reads Accept-Language, treat each region tag in the table as its script tag, if MB_LANGUAGES has the script tag. Put the script tag right after the region tag, so that it comes before the zh that follows.
Acceptance criteria
- If its script tag is in MB_LANGUAGES, each of the six region tags selects that script tag.
- An exact match comes first. For example, a server with zh-tw in MB_LANGUAGES still selects zh-tw.
- If the script tag is not in MB_LANGUAGES, the selection does not change.
- The quality values of the header keep their order. For example, a header that gives en the quality 1 and zh-TW the quality 0.8 selects English.
- A language in the lang cookie still comes before the header. The language menu sets the cookie to the script tag, so the cookie needs no change.
- Script tags in the header, such as zh-Hant-TW, and other languages keep their current behavior.
- depends on
-
MBS-14482 Locales with a script subtag (e.g. zh_Hant) cannot be used
-
- Review Submitted
-