Skip to content

Let zh-HK and zh-MO use the same translation as zh-TW - #9059

Open
YDX-2147483647 wants to merge 2 commits into
typst:mainfrom
YDX-2147483647:translation-zh-region
Open

YDX-2147483647 wants to merge 2 commits into
typst:mainfrom
YDX-2147483647:translation-zh-region

Conversation

@YDX-2147483647

@YDX-2147483647 YDX-2147483647 commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Both zh-HK and zh-MO use traditional characters. However at present, their translations use simplified characters.
This PR fixes that by letting them fall back to zh-TW.

Resolves #8756

图片
Code for the diagram
#set page(width: auto, height: auto, margin: 2em)
#import "@preview/diagraph:0.3.8": raw-render
#show raw: raw-render

= Locale Inheritance in Typst v0.15.1
```dot
digraph {
  rankdir="LR"
  other [label="zh-{CN,HK,MO,…}"]
  TW [label="zh-TW"]

  zh -> other
  zh -> TW
}
```

= Locale Inheritance in This PR
```dot
digraph {
  rankdir="LR"
  other [label="zh-{CN,…}"]
  TW [label="zh-TW"]
  HK [label="zh-HK"]
  MO [label="zh-MO"]

  zh -> other
  zh -> TW
  TW -> HK
  TW -> MO
}
```

Additional considerations

Relationship between Traditional Chinese and zh-{TW,HK,MO}

Styling using language attributes | W3C Internationalization:

Until the zh-Hans and zh-Hant language tags were available, the codes zh-TW and zh-CN were used to indicate Traditional and Simplified versions of Chinese writing, respectively. This is not actually appropriate because zh-TW indicates the Chinese language spoken in Taiwan, although more than one Chinese language is spoken there. Similarly zh-CN really indicates a generic Chinese spoken language used in China (PRC), rather than Simplified Chinese writing. It could refer to Mandarin or any other Chinese language. The same code was also used incorrectly for the Simplified Chinese written in Singapore.

Roughly speaking, zh-{TW,HK,MO} can be considered as dialects1 of Traditional Chinese.
In our case, only a few nouns are translated, so the difference among zh-{TW,HK,MO} is negligible.

In fact when the strings in today's zh-TW.txt were initially added in #1000, they were meant to be Chinese (Traditional), and not specific to zh-TW.

I once considered to rename the translation file for Traditional Chinese from zh-TW.txt to zh-Hant.txt. However, now I think it's better to keep the original file name, because future strings might require different translations for zh-TW and zh-{HK,MO}.

Update: After seeing how CLDR organizes locales, I'm hesitating again... Perhaps it's better we rename it to zh-Hant.txt. We can add zh-Hant-{HK,MO}.txt in the future if necessary.

Why not set text(lang: "zh", region: "TW") for all use case of Traditional Chinese?

text.region also controls the OpenType locl (Localized Forms) feature.
For some characters, there are stylistic differences between zh-HK and zh-TW glyphs. The following is an example for Source Han Sans.

图片

As a result, when zh-HK glyphs are preferred, set text(lang: "zh", region: "TW") cannot be used. Only set text(lang: "zh", region: "HK") can produce the correct glyphs.

Why the new test case disables the paged target?

The paged target will display the specific glyphs. However, the current Noto Serif CJK fonts in typst-dev-assets do not support selecting the correct glyphs automatically based on text.region via the OpenType locl feature. As a result, I have to manually switch fonts to select the correct glyphs, which is cumbersome. (See also #8991 and typst/typst-dev-assets#18)

For simplicity, I only tested the HTML target, which does not involve glyphs and fonts.

Why not just copy zh-TW.txt as #8765 does?

That would require keeping three files zh-{TW,HK,MO}.txt synchronized, which is not very convenient...

Reference implementations

Wikipedia

We can take the Simplified 🡘 Traditional Chinese conversion rules of zh.wikipedia.org / MediaWiki as a reference.
It supports six converters: zh-{CN,HK,MO,MY,SG,TW}. (not counting internal converters)

Diagram
Code for the diagram
#set page(width: auto, height: auto, margin: 2em)
#set text(
  font: "Noto Serif CJK SC",
  top-edge: "ascender",
  bottom-edge: "descender",
)
#set list(marker: ([•], [‣], [–]).map(text.with(font: "Libertinus Serif")))
#show link: set text(blue.darken(20%))


= Hierarchy of #link("https://zh.wikipedia.org")[zh.wikipedia.org] converters

#import "@preview/diagraph:0.3.8": render
#render(
  ```dot
  digraph {
    zh [label="zh"]
    Hans [label="zh-Hans"]
    Hant [label="zh-Hant"]
    CN [label="zh-CN\n大陆简体"]
    HK [label="zh-HK\n香港繁體"]
    MO [label="zh-MO\n澳門繁體"]
    MY [label="zh-MY\n大马简体"]
    SG [label="zh-SG\n新加坡简体"]
    TW [label="zh-TW\n臺灣正體"]

    zh -> Hans
    zh -> Hant
    Hans -> CN
    Hant -> TW
    HK -> MO [label="split in 2013"]
    SG -> MY [label="split in 2018"]

    Hans -> SG
    Hant -> HK
  }
  ```.text,
)

#let link-tag(tag) = link(
  "https://w3.org/International/articles/language-tags/#" + tag,
  tag,
)

/ #link-tag("language"):
  - zh: Zhōngwén, 中文, 汉语, Chinese
/ language-#link-tag("script"):
  - zh-Hans: Han (Simplified variant), 简体
  - zh-Hant: Han (Traditional variant), 正體/繁體
/ language-#link-tag("region"):
  - zh-CN: China, 大陆
  - zh-HK: Hong Kong, 香港
  - zh-MO: Macao, 澳門
  - zh-MY: Malaysia, 大马
  - zh-SG: Singapore, 新加坡
  - zh-TW: Taiwan, 臺灣


#line(length: 4em)

References:
- #link(
    "https://zh.wikipedia.org/wiki/Help:中文维基百科的繁简、地区词处理#用字模式選擇",
  )[帮助:中文维基百科的繁简、地区词处理 → 用字模式選擇]
- #link(
    "https://phabricator.wikimedia.org/source/mediawiki/browse/master/includes/Language/Converters/ZhConverter.php#L37",
  )[MediaWiki source code → `ZhConverter.php`]
Details about zhwiki / MediaWiki converters

As shown below, when an article is displayed on zh.wikipedia.org, the reader can select one of the six converters: 大陆简体 (zh-CN), 香港繁體 (zh-HK), 澳門繁體 (zh-MO), 大马简体 (zh-MY), 新加坡简体 (zh-SG), and 臺灣正體 (zh-TW).

图片

According to zhwiki's help page, the hierarchy of these converters and three other internal converters is as the diagram above.
Specifically, zh-{CN,SG,MY} are based on zh-Hans, where zh-MY was split from zh-SG in 2018. And zh-{TW,HK,MO} are based on zh-Hant, where zh-MO was split from 2013.

The converters are implemented in MediaWiki's ZhConverter.php, and the concrete rules are saved in ZhConversion.php (~20k lines2).
In short, ZhConversion.php maintains 2+3 tables (ZH_TO_HAN{T,S} and ZH_TO_{TW,HK,CN}), and ZhConverter.php declares a fallback chain for each converter:

  • zh ⇒ zh-Hans, zh-Hant, zh-CN, zh-TW, zh-HK, zh-SG, zh-MO, zh-MY
  • zh-Hans ⇒ zh-CN, zh-SG, zh-MY
  • zh-Hant ⇒ zh-TW, zh-HK, zh-MO
  • zh-CN ⇒ zh-Hans, zh-SG, zh-MY
  • zh-SG ⇒ zh-MY, zh-Hans, zh-CN
  • zh-MY ⇒ zh-SG, zh-Hans, zh-CN
  • zh-TW ⇒ zh-Hant, zh-HK, zh-MO
  • zh-HK ⇒ zh-MO, zh-Hant, zh-TW
  • zh-MO ⇒ zh-HK, zh-Hant, zh-TW

The fallback chains are interwoven together, because the converters have to support ad-hoc overrides in wikitext.

图片
Code for the diagram
#set page(width: auto, height: auto, margin: 2em)

= Fallback rules

#place(right)[
  #set align(left)
  #text(red, $->$) = primary fallback. \
  $arrow.r$ = secondary fallback. \
  $arrow.r.dashed$ = tertiary fallback. \
  Other fallbacks are not drawn.
]

#set text(
  font: "Noto Serif CJK SC",
  top-edge: "ascender",
  bottom-edge: "descender",
)

#import "@preview/diagraph:0.3.8": render
#render({
  let rules = ```
  zh ⇒ zh-Hans, zh-Hant, zh-CN, zh-TW, zh-HK, zh-SG, zh-MO, zh-MY
  zh-Hans ⇒ zh-CN, zh-SG, zh-MY
  zh-CN ⇒ zh-Hans, zh-SG, zh-MY
  zh-SG ⇒ zh-MY, zh-Hans, zh-CN
  zh-MY ⇒ zh-SG, zh-Hans, zh-CN
  zh-Hant ⇒ zh-TW, zh-HK, zh-MO
  zh-TW ⇒ zh-Hant, zh-HK, zh-MO
  zh-MO ⇒ zh-HK, zh-Hant, zh-TW
  zh-HK ⇒ zh-MO, zh-Hant, zh-TW
.text
.trim()
.replace("\r\n", "\n")
.split("\n")
.map(rule => {
  let (locale, chain) = rule.split(" ⇒ ")
  (
    locale.trim("zh-", at: start),
    chain.split(", ").map(s => s.trim("zh-", at: start)),
  )
})
digraph {
  Hans [label="zh-Hans"]
  CN [label="zh-CN\n大陆简体"]
  MY [label="zh-MY\n大马简体"]
  SG [label="zh-SG\n新加坡简体"]
  Hant [label="zh-Hant"]
  TW [label="zh-TW\n臺灣正體"]
  MO [label="zh-MO\n澳門繁體"]
  HK [label="zh-HK\n香港繁體"]
```.text

"\n"

for (locale, (a, b, c, ..)) in rules {
  locale + " -> " + a + " [style=bold, color=red]; "
  locale + " -> " + b + "[]; "
  locale + " -> " + c + " [style=dashed]; "
}

"}"
})
figure = 图、圖

table = 表、表

equation = 式、式

bibliography = 参考文献、書目

heading = 小节、小節

outline = 目录、目錄

raw = 代码、程式

page = 页、頁

footnote = 脚注、註腳

email = 电子邮件、電子郵件

telephone = 电话、電話

For the above wikitext, choosing any of zh-{CN,SG,MY} shows:

figure = 图、图

table = 表、表

equation = 式、式

bibliography = 参考文献、书目

heading = 小节、小节

outline = 目录、目录

raw = 代码、程式

page = 页、页

footnote = 脚注、注脚

email = 电子邮件、电子邮件

telephone = 电话、电话

And choosing any of zh-{TW,HK,MO} shows:

figure = 圖、圖

table = 表、表

equation = 式、式

bibliography = 參考文獻、書目

heading = 小節、小節

outline = 目錄、目錄

raw = 代碼、程式

page = 頁、頁

footnote = 腳註、註腳

email = 電子郵件、電子郵件

telephone = 電話、電話

LaTeX babel

The babel package supports 3 + 2×2 + 1 = 8 locales: zh, zh-Hans, zh-Hant, zh-Han{s,t}-{HK,MO}, and zh-Hans-SG. (not counting their aliases)
Most notably, babel does not support specifying zh-CN or zh-TW. Its manual implies that zh-Hans and zh-Hant should be used.

The localization files live in https://github.com/latex3/babel/tree/main/locale/zh.

图片
Code for the diagram
#set page(width: auto, height: auto, margin: 2em)
= Locale Inheritance in LaTeX babel
#import "@preview/diagraph:0.3.8": render
#render(
  ```dot
  digraph {
    rankdir="LR"
    Hans [label="zh-Hans"]
    Hans_HK [label="zh-Hans-HK"]
    Hans_MO [label="zh-Hans-MO"]
    Hans_SG [label="zh-Hans-SG"]
    Hant [label="zh-Hant"]
    Hant_HK [label="zh-Hant-HK"]
    Hant_MO [label="zh-Hant-MO"]
    pinyin [label="zh-Latn-pinyin"]

    zh -> Hans
    Hans -> Hans_HK
    Hans -> Hans_MO
    Hans -> Hans_SG
    zh -> Hant
    Hant -> Hant_HK
    Hant -> Hant_MO
    zh -> pinyin
  }
  ```.text,
)
Details about babel locales
  • zh, 中文 (babel-zh.ini with babel-chinese.tex)

    • zh-Hans, 简体中文 (babel-zh-Hans.ini with babel-chinese-{hans,simplified}.tex)

      The only difference from zh is that the OpenType smpl (Simplified Forms) feature is enabled.

      • zh-Hans-HK, 中国香港特别行政区 (babel-zh-Hans-HK.ini with babel-chinese-{hans-hk,simplified-hongkongsarchina}.tex)

        Many strings are left empty to inherit from zh-Hans, and other strings are the same as zh-Hans. The only essential difference from zh-Hans is the date/time format.

      • zh-Hans-MO, 中国澳门特别行政区(babel-zh-Hans-MO.ini with babel-chinese-{hans-mo,simplified-macausarchina}.tex)

        Identical to zh-Hans-HK.

      • zh-Hans-SG, 新加坡 (babel-zh-Hans-SG.ini with babel-chinese-{hans-sg,simplified-singapore}.tex)

        Identical to zh-Hans-{HK,MO}, except the date format.

    • zh-Hant, 繁體中文 (babel-zh-Hant.ini with babel-chinese-{hant,traditional}.tex)

      Significantly different from zh: ref 参考文献 → 參 考 資 料, bib 参考文献 → 文 獻, figure 图 → 圖, contents 目录 → 目 錄 (somehow, this space is U+2000 EN QUAD), … Also, the OpenType trad (Traditional Forms) feature is enabled.

      • zh-Hant-MO, 中國澳門特別行政區 (babel-zh-Hant-MO.ini with babel-chinese-{hant-mo,traditional-macausarchina}.tex)

        Many strings are left empty to inherit from zh-Hant, and other strings are the same as zh-Hant. Essentially identical to zh-Hant.

      • zh-Hant-HK, 中國香港特別行政區 (babel-zh-Hant-HK.ini with babel-chinese-{hant-hk,traditional-hongkongsarchina}.tex)

        Identical to zh-Hant-HK, except the date/time format and the month names.

    • zh-Latn-pinyin, Hànyǔ Pīnyīn (babel-zh-Latn-pinyin.ini with babel-chinese-pinyin.tex)

      Significantly different from zh. The strings are romanized from zh, numbering patterns are omitted, and hyphenation rules are tweaked.

CLDR

Locale Data Summaries:

See also these sections in the CLDR core spec:

图片
Code for the diagram
#set page(width: auto, height: auto, margin: 2em)
= Locale Inheritance in CLDR
#import "@preview/diagraph:0.3.8": render
#render(
  ```dot
  digraph {
    rankdir="LR"
    zh -> zh_Hans_HK
    zh -> zh_Hans_MO
    zh -> zh_MY
    zh -> zh_SG
    zh -> zh_Hant
    zh_Hant -> zh_HK
    zh_Hant -> zh_MO
    zh_Hant -> zh_Hant_MY
    zh -> zh_Latn
  }
  ```.text,
)

Footnotes

  1. The word dialect is usually used to refer to spoken languages, but here we are more focused on written languages. ↩

  2. This file is too large, so I'm linking to its history page. Click Code to view the actual file. ↩

@YDX-2147483647

This comment was marked as resolved.

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.

Heading references uses incorrect language and region

1 participant