Skip to content

Add support for Chinese (Traditional) - #911

Closed
pan93412 wants to merge 8 commits into
typst:mainfrom
pan93412:zh-tw-support
Closed

pan93412 wants to merge 8 commits into
typst:mainfrom
pan93412:zh-tw-support

Conversation

@pan93412

@pan93412 pan93412 commented Apr 21, 2023 •

Copy link
Copy Markdown
Contributor

This PR distinguishes Simplified Chinese and Traditional Chinese1, and adds the translation, quoting, and partial support of numbering.

  1. I renamed the constant CHINESE to CHINESE_SIMPLIFIED to distinguish them.
  2. The language code of TRAD_CHINESE is named zht – the only 3-char code in Lang.
  3. The numbering feature can't be implemented as we can't distinguish translations of the 1st number in zht and zhs. It is better to add a “lang” flag to indicate which numbering kind should be used. I now mark it as #[allow(unused)] and add a TODO on it.
  4. For the translation of both new language code, I propose translating CHINESE_SIMPLIFIED as 中文(简体); CHINESE_TRADITIONAL as 中文(繁體).

Footnotes

  1. Traditional Chinese is used mainly by people in Taiwan, Hong Kong, etc. ↩

@reknih reknih left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your translation. I added a few comments on enum and constant names and our current handling of breaking changes.

I also want to keep zh in addition to the explicit zhs and zht and make it pick the correct language variant for zh based on which region the user picked. Do you think that could work?

Comment thread library/src/layout/table.rs Resolved
Comment thread library/src/meta/numbering.rs Resolved
Comment thread library/src/meta/numbering.rs Resolved
Comment thread library/src/text/quotes.rs Resolved
Comment thread src/doc.rs Resolved
Comment thread src/doc.rs Resolved
Comment thread tests/typ/layout/quote-cjk.typ Resolved
pan93412 and others added 4 commits April 21, 2023 18:28
The `zht` language implies `region: "TW"`.
- `Lang::CHINESE` has been removed.
- `Lang::Chinese` has been renamed to `Lang::ChineseSimplified`.

Co-Authored-By: Martin Haug <[email protected]>
@pan93412
pan93412 requested a review from reknih April 21, 2023 10:37
@pan93412

pan93412 commented Apr 21, 2023 •

Copy link
Copy Markdown
Contributor Author

Thank you for your translation. I added a few comments on enum and constant names and our current handling of breaking changes.

I also want to keep zh in addition to the explicit zhs and zht and make it pick the correct language variant for zh based on which region the user picked. Do you think that could work?

I prefer to leverage our already-have region property, so we won't touch our Lang enumeration. How do you think?

We may need to refactor LocalName trait to allow passing region into this method.

#set text(lang: "zh", region: "TW")

@peng1999

peng1999 commented Apr 21, 2023 •

Copy link
Copy Markdown
Contributor

I prefer to leverage our already-have region property

I'm second to this.
The documentation says lang is a ISO 639-1/2/3 language code. It seems that zhs is not a valid code.

@@ -0,0 +1,6 @@

---
#text(lang: "zh")["你好, '世界'."]

@peng1999 peng1999 Apr 21, 2023 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think implement smart quote for CJK text is a good idea. The smart quote is designed for western language users, who often typed (U+0022 Quotation Mark) instead of “true” open and close quotations. (In English that's U+201C/U+201D) But when CJK users typing their language, an input method is always used. Input methods will take care of U+0022 to U+201C/U+201D conversion and there is no need for typst to do smart quote transition.

The text in this test is rarely occurred in real world text. In Simplified Chinese, it's much more easy for us to write “你好,‘世界’。” than "你好, '世界'.". (Note that we use U+FF0C FULLWIDTH COMMA instead of U+002C COMMA) I believe this is true for all CJK languages.

Also, the smart quote currently do not working correctly in text without space, which is the case of CJK.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'll remove the related changes!

@szdytom

szdytom commented Apr 22, 2023 •

Copy link
Copy Markdown
Contributor

I prefer to leverage our already-have region property

I'm second to this. The documentation says lang is a ISO 639-1/2/3 language code. It seems that zhs is not a valid code.

tthe standard code will be zh-Hans and zh-Hant. But that is going to a complex problem, actually there a at least 4 mainly used variants:

  • zh-Hans-CN (or zh-CN for short): Simplified Chinese(Mandarin Chinese). mainly used in China mainland.
  • zh-Hant-TW (or zh-TW for short): Traditional Chinese(Taiwanese), used in Taiwan province.
  • zh-Hant-HK (or zh-HK for short): Traditional Chinese(Cantonese), used in Hongkong district.
  • zh-Hans-SG (or zh-SG for short): mainly Simplified Chinese, but partly mixed Traditional Chinese, which are subject to the official regulations of Singapore(Singaporean), used in Singapore

Note: there are also other variants like zh-MO or zh-MY.

@peng1999

Copy link
Copy Markdown
Contributor

tthe standard code will be zh-Hans and zh-Hant. But that is going to a complex problem, actually there a at least 4 mainly used variants:

It is not that complicated. We can already specify lang-region pair in current typst, and let's leverage it to support zh-cn and zh-tw first. More can be added later.

@pan93412

Copy link
Copy Markdown
Contributor Author

I'm currently working on the LocalName refactor. PR of this will be landed soon.

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.

4 participants