Add translation for Chinese (Traditional) (#1000)

This commit is contained in:
pan93412 2023-04-27 19:16:27 +08:00 committed by GitHub
parent 86d7ac881b
commit e0d5930405
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 11 deletions

View File

@ -34,6 +34,7 @@ use ttf_parser::{GlyphId, Rect};
use typst::eval::{Module, Scope}; use typst::eval::{Module, Scope};
use typst::font::{Font, FontWeight}; use typst::font::{Font, FontWeight};
use typst::model::Guard; use typst::model::Guard;
use typst::util::option_eq;
use unicode_math_class::MathClass; use unicode_math_class::MathClass;
use self::ctx::*; use self::ctx::*;
@ -277,10 +278,11 @@ impl Count for EquationElem {
} }
impl LocalName 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 { match lang {
Lang::ARABIC => "معادلة", Lang::ARABIC => "معادلة",
Lang::BOKMÅL => "Ligning", Lang::BOKMÅL => "Ligning",
Lang::CHINESE if option_eq(region, "TW") => "方程式",
Lang::CHINESE => "等式", Lang::CHINESE => "等式",
Lang::CZECH => "Rovnice", Lang::CZECH => "Rovnice",
Lang::FRENCH => "Équation", Lang::FRENCH => "Équation",

View File

@ -7,6 +7,7 @@ use ecow::{eco_vec, EcoVec};
use hayagriva::io::{BibLaTeXError, YamlBibliographyError}; use hayagriva::io::{BibLaTeXError, YamlBibliographyError};
use hayagriva::style::{self, Brackets, Citation, Database, DisplayString, Formatting}; use hayagriva::style::{self, Brackets, Citation, Database, DisplayString, Formatting};
use hayagriva::Entry; use hayagriva::Entry;
use typst::util::option_eq;
use super::{LinkElem, LocalName, RefElem}; use super::{LinkElem, LocalName, RefElem};
use crate::layout::{BlockElem, GridElem, ParElem, Sizing, TrackSizings, VElem}; use crate::layout::{BlockElem, GridElem, ParElem, Sizing, TrackSizings, VElem};
@ -210,10 +211,11 @@ impl Finalize for BibliographyElem {
} }
impl LocalName 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 { match lang {
Lang::ARABIC => "المراجع", Lang::ARABIC => "المراجع",
Lang::BOKMÅL => "Bibliografi", Lang::BOKMÅL => "Bibliografi",
Lang::CHINESE if option_eq(region, "TW") => "書目",
Lang::CHINESE => "参考文献", Lang::CHINESE => "参考文献",
Lang::CZECH => "Bibliografie", Lang::CZECH => "Bibliografie",
Lang::FRENCH => "Bibliographie", Lang::FRENCH => "Bibliographie",

View File

@ -1,4 +1,5 @@
use typst::font::FontWeight; use typst::font::FontWeight;
use typst::util::option_eq;
use super::{Counter, CounterUpdate, LocalName, Numbering, Refable}; use super::{Counter, CounterUpdate, LocalName, Numbering, Refable};
use crate::layout::{BlockElem, HElem, VElem}; use crate::layout::{BlockElem, HElem, VElem};
@ -234,10 +235,11 @@ impl Refable for HeadingElem {
} }
impl LocalName 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 { match lang {
Lang::ARABIC => "الفصل", Lang::ARABIC => "الفصل",
Lang::BOKMÅL => "Kapittel", Lang::BOKMÅL => "Kapittel",
Lang::CHINESE if option_eq(region, "TW") => "小節",
Lang::CHINESE => "小节", Lang::CHINESE => "小节",
Lang::CZECH => "Kapitola", Lang::CZECH => "Kapitola",
Lang::FRENCH => "Chapitre", Lang::FRENCH => "Chapitre",

View File

@ -259,7 +259,14 @@ enum NumberingKind {
Roman, Roman,
Symbol, Symbol,
Hebrew, 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, HiraganaIroha,
KatakanaIroha, KatakanaIroha,
} }
@ -273,7 +280,7 @@ impl NumberingKind {
'i' => NumberingKind::Roman, 'i' => NumberingKind::Roman,
'*' => NumberingKind::Symbol, '*' => NumberingKind::Symbol,
'א' => NumberingKind::Hebrew, 'א' => NumberingKind::Hebrew,
'一' | '壹' => NumberingKind::Chinese, '一' | '壹' => NumberingKind::SimplifiedChinese,
'い' => NumberingKind::HiraganaIroha, 'い' => NumberingKind::HiraganaIroha,
'イ' => NumberingKind::KatakanaIroha, 'イ' => NumberingKind::KatakanaIroha,
_ => return None, _ => return None,
@ -288,7 +295,8 @@ impl NumberingKind {
Self::Roman => 'i', Self::Roman => 'i',
Self::Symbol => '*', Self::Symbol => '*',
Self::Hebrew => 'א', Self::Hebrew => 'א',
Self::Chinese => '一', Self::SimplifiedChinese => '一',
Self::TraditionalChinese => '一',
Self::HiraganaIroha => 'い', Self::HiraganaIroha => 'い',
Self::KatakanaIroha => 'イ', Self::KatakanaIroha => 'イ',
} }
@ -437,18 +445,22 @@ impl NumberingKind {
} }
fmt fmt
} }
Self::Chinese => { l @ (Self::SimplifiedChinese | Self::TraditionalChinese) => {
let chinesecase = match case { let chinese_case = match case {
Case::Lower => ChineseCase::Lower, Case::Lower => ChineseCase::Lower,
Case::Upper => ChineseCase::Upper, Case::Upper => ChineseCase::Upper,
}; };
match (n as u8).to_chinese( match (n as u8).to_chinese(
ChineseVariant::Simple, match l {
chinesecase, Self::SimplifiedChinese => ChineseVariant::Simple,
Self::TraditionalChinese => ChineseVariant::Traditional,
_ => unreachable!(),
},
chinese_case,
ChineseCountMethod::TenThousand, ChineseCountMethod::TenThousand,
) { ) {
Ok(chinesestring) => EcoString::from(chinesestring), Ok(num_str) => EcoString::from(num_str),
Err(_) => '-'.into(), Err(_) => '-'.into(),
} }
} }