summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpan93412 <pan93412@gmail.com>2023-04-27 19:16:27 +0800
committerGitHub <noreply@github.com>2023-04-27 13:16:27 +0200
commite0d59304055619f6834109168dfb02f9a895f333 (patch)
tree662b8aba6638b9650ad5890e23d934e66c282396
parent86d7ac881b823990aea20dfabb2e04aa7c8141b2 (diff)
Add translation for Chinese (Traditional) (#1000)
-rw-r--r--library/src/math/mod.rs4
-rw-r--r--library/src/meta/bibliography.rs4
-rw-r--r--library/src/meta/heading.rs4
-rw-r--r--library/src/meta/numbering.rs28
4 files changed, 29 insertions, 11 deletions
diff --git a/library/src/math/mod.rs b/library/src/math/mod.rs
index 47c28d17..21e5d805 100644
--- a/library/src/math/mod.rs
+++ b/library/src/math/mod.rs
@@ -34,6 +34,7 @@ use ttf_parser::{GlyphId, Rect};
use typst::eval::{Module, Scope};
use typst::font::{Font, FontWeight};
use typst::model::Guard;
+use typst::util::option_eq;
use unicode_math_class::MathClass;
use self::ctx::*;
@@ -277,10 +278,11 @@ impl Count for EquationElem {
}
impl LocalName for EquationElem {
- fn local_name(&self, lang: Lang, _: Option<Region>) -> &'static str {
+ fn local_name(&self, lang: Lang, region: Option<Region>) -> &'static str {
match lang {
Lang::ARABIC => "معادلة",
Lang::BOKMÅL => "Ligning",
+ Lang::CHINESE if option_eq(region, "TW") => "方程式",
Lang::CHINESE => "等式",
Lang::CZECH => "Rovnice",
Lang::FRENCH => "Équation",
diff --git a/library/src/meta/bibliography.rs b/library/src/meta/bibliography.rs
index 99f2111f..1e922c42 100644
--- a/library/src/meta/bibliography.rs
+++ b/library/src/meta/bibliography.rs
@@ -7,6 +7,7 @@ use ecow::{eco_vec, EcoVec};
use hayagriva::io::{BibLaTeXError, YamlBibliographyError};
use hayagriva::style::{self, Brackets, Citation, Database, DisplayString, Formatting};
use hayagriva::Entry;
+use typst::util::option_eq;
use super::{LinkElem, LocalName, RefElem};
use crate::layout::{BlockElem, GridElem, ParElem, Sizing, TrackSizings, VElem};
@@ -210,10 +211,11 @@ impl Finalize for BibliographyElem {
}
impl LocalName for BibliographyElem {
- fn local_name(&self, lang: Lang, _: Option<Region>) -> &'static str {
+ fn local_name(&self, lang: Lang, region: Option<Region>) -> &'static str {
match lang {
Lang::ARABIC => "المراجع",
Lang::BOKMÅL => "Bibliografi",
+ Lang::CHINESE if option_eq(region, "TW") => "書目",
Lang::CHINESE => "参考文献",
Lang::CZECH => "Bibliografie",
Lang::FRENCH => "Bibliographie",
diff --git a/library/src/meta/heading.rs b/library/src/meta/heading.rs
index 43505448..01804edc 100644
--- a/library/src/meta/heading.rs
+++ b/library/src/meta/heading.rs
@@ -1,4 +1,5 @@
use typst::font::FontWeight;
+use typst::util::option_eq;
use super::{Counter, CounterUpdate, LocalName, Numbering, Refable};
use crate::layout::{BlockElem, HElem, VElem};
@@ -234,10 +235,11 @@ impl Refable for HeadingElem {
}
impl LocalName for HeadingElem {
- fn local_name(&self, lang: Lang, _: Option<Region>) -> &'static str {
+ fn local_name(&self, lang: Lang, region: Option<Region>) -> &'static str {
match lang {
Lang::ARABIC => "الفصل",
Lang::BOKMÅL => "Kapittel",
+ Lang::CHINESE if option_eq(region, "TW") => "小節",
Lang::CHINESE => "小节",
Lang::CZECH => "Kapitola",
Lang::FRENCH => "Chapitre",
diff --git a/library/src/meta/numbering.rs b/library/src/meta/numbering.rs
index b5416f68..dc3ae987 100644
--- a/library/src/meta/numbering.rs
+++ b/library/src/meta/numbering.rs
@@ -259,7 +259,14 @@ enum NumberingKind {
Roman,
Symbol,
Hebrew,
- Chinese,
+ SimplifiedChinese,
+ // TODO: Pick the numbering pattern based on languages choice.
+ // As the `1st` numbering character of Chinese (Simplifed) and
+ // Chinese (Traditional) is same, we are unable to determine
+ // if the context is Simplified or Traditional by only this
+ // character.
+ #[allow(unused)]
+ TraditionalChinese,
HiraganaIroha,
KatakanaIroha,
}
@@ -273,7 +280,7 @@ impl NumberingKind {
'i' => NumberingKind::Roman,
'*' => NumberingKind::Symbol,
'א' => NumberingKind::Hebrew,
- '一' | '壹' => NumberingKind::Chinese,
+ '一' | '壹' => NumberingKind::SimplifiedChinese,
'い' => NumberingKind::HiraganaIroha,
'イ' => NumberingKind::KatakanaIroha,
_ => return None,
@@ -288,7 +295,8 @@ impl NumberingKind {
Self::Roman => 'i',
Self::Symbol => '*',
Self::Hebrew => 'א',
- Self::Chinese => '一',
+ Self::SimplifiedChinese => '一',
+ Self::TraditionalChinese => '一',
Self::HiraganaIroha => 'い',
Self::KatakanaIroha => 'イ',
}
@@ -437,18 +445,22 @@ impl NumberingKind {
}
fmt
}
- Self::Chinese => {
- let chinesecase = match case {
+ l @ (Self::SimplifiedChinese | Self::TraditionalChinese) => {
+ let chinese_case = match case {
Case::Lower => ChineseCase::Lower,
Case::Upper => ChineseCase::Upper,
};
match (n as u8).to_chinese(
- ChineseVariant::Simple,
- chinesecase,
+ match l {
+ Self::SimplifiedChinese => ChineseVariant::Simple,
+ Self::TraditionalChinese => ChineseVariant::Traditional,
+ _ => unreachable!(),
+ },
+ chinese_case,
ChineseCountMethod::TenThousand,
) {
- Ok(chinesestring) => EcoString::from(chinesestring),
+ Ok(num_str) => EcoString::from(num_str),
Err(_) => '-'.into(),
}
}