feat: support text conversion between simplifed and traditional Chinese, closes #2508 (#2520)

This commit is contained in:
Huang Xin
2025-11-23 16:56:12 +08:00
committed by GitHub
parent cd614e3845
commit c792c18e01
45 changed files with 553 additions and 38 deletions
+1 -1
View File
@@ -66,7 +66,7 @@ jobs:
- name: install Dependencies
working-directory: apps/readest-app
run: |
pnpm install && pnpm setup-pdfjs
pnpm install && pnpm setup-vendors
- name: run tests
working-directory: apps/readest-app
+2 -2
View File
@@ -180,8 +180,8 @@ jobs:
- name: install dependencies
run: pnpm install
- name: copy pdfjs-dist to public directory
run: pnpm --filter @readest/readest-app setup-pdfjs
- name: copy pdfjs-dist and simplecc-dist to public directory
run: pnpm --filter @readest/readest-app setup-vendors
- name: install Rust stable
uses: dtolnay/rust-toolchain@stable
+3
View File
@@ -7,3 +7,6 @@
[submodule "packages/tauri-plugins"]
path = packages/tauri-plugins
url = https://github.com/readest/tauri-plugins-workspace.git
[submodule "packages/simplecc-wasm"]
path = packages/simplecc-wasm
url = https://github.com/readest/simplecc-wasm.git
+2 -2
View File
@@ -145,8 +145,8 @@ cd readest
# might need to rerun this when code is updated
git submodule update --init --recursive
pnpm install
# copy pdfjs-dist to Next.js public directory
pnpm --filter @readest/readest-app setup-pdfjs
# copy vendors dist libs to public directory
pnpm --filter @readest/readest-app setup-vendors
```
### 3. Verify Dependencies Installation
+4 -1
View File
@@ -14,14 +14,17 @@
"lint": "eslint .",
"test": "dotenv -e .env -e .env.test.local vitest",
"tauri": "tauri",
"prepare-public-vendor": "mkdirp ./public/vendor/pdfjs",
"prepare-public-vendor": "mkdirp ./public/vendor/pdfjs ./public/vendor/simplecc",
"copy-pdfjs-js": "cpx \"../../packages/foliate-js/node_modules/pdfjs-dist/legacy/build/{pdf.worker.min.mjs,pdf.mjs,pdf.d.mts}\" ./public/vendor/pdfjs",
"copy-pdfjs-fonts": "cpx \"../../packages/foliate-js/node_modules/pdfjs-dist/{cmaps,standard_fonts}/*\" ./public/vendor/pdfjs",
"copy-flatten-pdfjs-annotation-layer-css": "npx postcss \"../../packages/foliate-js/vendor/pdfjs/annotation_layer_builder.css\" --no-map -u postcss-nested > ./public/vendor/pdfjs/annotation_layer_builder.css",
"copy-flatten-pdfjs-text-layer-css": "npx postcss \"../../packages/foliate-js/vendor/pdfjs/text_layer_builder.css\" --no-map -u postcss-nested > ./public/vendor/pdfjs/text_layer_builder.css",
"copy-flatten-pdfjs-css": "pnpm copy-flatten-pdfjs-annotation-layer-css && pnpm copy-flatten-pdfjs-text-layer-css",
"copy-pdfjs": "pnpm copy-pdfjs-js && pnpm copy-pdfjs-fonts && pnpm copy-flatten-pdfjs-css",
"copy-simplecc": "cpx \"../../packages/simplecc-wasm/dist/web/*\" ./public/vendor/simplecc",
"setup-pdfjs": "pnpm prepare-public-vendor && pnpm copy-pdfjs",
"setup-simplecc": "pnpm prepare-public-vendor && pnpm copy-simplecc",
"setup-vendors": "pnpm setup-pdfjs && pnpm setup-simplecc",
"build-win-x64": "dotenv -e .env.tauri.local -- tauri build --target i686-pc-windows-msvc --bundles nsis",
"build-win-arm64": "dotenv -e .env.tauri.local -- tauri build --target aarch64-pc-windows-msvc --bundles nsis",
"build-linux-x64": "dotenv -e .env.tauri.local -- tauri build --target x86_64-unknown-linux-gnu --bundles appimage",
@@ -675,5 +675,16 @@
"Unable to open book": "غير قادر على فتح الكتاب",
"Punctuation": "علامات الترقيم",
"Replace Quotation Marks": "استبدال علامات الاقتباس",
"Enabled only in vertical layout.": "مفعل فقط في التخطيط الرأسي."
"Enabled only in vertical layout.": "مفعل فقط في التخطيط الرأسي.",
"No Conversion": "لا تحويل",
"Simplified to Traditional": "من المبسّط إلى التقليدي",
"Traditional to Simplified": "من التقليدي إلى المبسّط",
"Simplified to Traditional (Taiwan)": "مبسّط → تقليدي (تايوان)",
"Simplified to Traditional (Hong Kong)": "مبسّط → تقليدي (هونغ كونغ)",
"Simplified to Traditional (Taiwan), with phrases": "مبسّط → تقليدي (تايوان • عبارات)",
"Traditional (Taiwan) to Simplified": "تقليدي (تايوان) → مبسّط",
"Traditional (Hong Kong) to Simplified": "تقليدي (هونغ كونغ) → مبسّط",
"Traditional (Taiwan) to Simplified, with phrases": "تقليدي (تايوان • عبارات) → مبسّط",
"Convert Simplified and Traditional Chinese": "تحويل المبسّط/التقليدي",
"Convert Mode": "وضع التحويل"
}
@@ -659,5 +659,16 @@
"Unable to open book": "বই খুলতে অক্ষম",
"Punctuation": "বিরামচিহ্ন",
"Replace Quotation Marks": "উদ্ধৃতি চিহ্ন প্রতিস্থাপন করুন",
"Enabled only in vertical layout.": "শুধুমাত্র উল্লম্ব বিন্যাসে সক্রিয়।"
"Enabled only in vertical layout.": "শুধুমাত্র উল্লম্ব বিন্যাসে সক্রিয়।",
"No Conversion": "রূপান্তর নয়",
"Simplified to Traditional": "সরল → প্রথাগত",
"Traditional to Simplified": "প্রথাগত → সরল",
"Simplified to Traditional (Taiwan)": "সরল → প্রথাগত (তাইওয়ান)",
"Simplified to Traditional (Hong Kong)": "সরল → প্রথাগত (হংকং)",
"Simplified to Traditional (Taiwan), with phrases": "সরল → প্রথাগত (তাইওয়ান • বাক্য)",
"Traditional (Taiwan) to Simplified": "প্রথাগত (তাইওয়ান) → সরল",
"Traditional (Hong Kong) to Simplified": "প্রথাগত (হংকং) → সরল",
"Traditional (Taiwan) to Simplified, with phrases": "প্রথাগত (তাইওয়ান • বাক্য) → সরল",
"Convert Simplified and Traditional Chinese": "সরল/প্রথাগত রূপান্তর",
"Convert Mode": "রূপান্তর মোড"
}
@@ -655,5 +655,16 @@
"Unable to open book": "དེབ་ཀྱི་སྤྱོད་བྱས་མ་ཐུབ།",
"Punctuation": "ཚིག་གྲུབ།",
"Replace Quotation Marks": "འདྲེན་འབྲེལ་མཐུད་ཐིག་བརྗེ་བ།",
"Enabled only in vertical layout.": "གཡས་སྒྲིག་ནང་མིང་བརྗེ་བ།"
"Enabled only in vertical layout.": "གཡས་སྒྲིག་ནང་མིང་བརྗེ་བ།",
"No Conversion": "བསྒྱུར་བཤེར་མེད་",
"Simplified to Traditional": "སྟོང་བཟོས → སྲོལ་རྒྱུན",
"Traditional to Simplified": "སྲོལ་རྒྱུན → སྟོང་བཟོས",
"Simplified to Traditional (Taiwan)": "སྟོང་བཟོས → སྲོལ་རྒྱུན (ཏའི་ཝན)",
"Simplified to Traditional (Hong Kong)": "སྟོང་བཟོས → སྲོལ་རྒྱུན (ཧོང་ཀོང)",
"Simplified to Traditional (Taiwan), with phrases": "སྟོང་བཟོས → སྲོལ་རྒྱུན (ཏའི་ཝན • ཚིག་ཕྲེང)",
"Traditional (Taiwan) to Simplified": "སྲོལ་རྒྱུན (ཏའི་ཝན) → སྟོང་བཟོས",
"Traditional (Hong Kong) to Simplified": "སྲོལ་རྒྱུན (ཧོང་ཀོང) → སྟོང་བཟོས",
"Traditional (Taiwan) to Simplified, with phrases": "སྲོལ་རྒྱུན (ཏའི་ཝན • ཚིག་ཕྲེང) → སྟོང་བཟོས",
"Convert Simplified and Traditional Chinese": "རྒྱ་ཡིག སྟོང་བཟོས/སྲོལ་རྒྱུན བསྒྱུར་བ",
"Convert Mode": "བསྒྱུར་བའི་རྣམ་པ"
}
@@ -659,5 +659,16 @@
"Unable to open book": "Buch kann nicht geöffnet werden",
"Punctuation": "Interpunktion",
"Replace Quotation Marks": "Anführungszeichen ersetzen",
"Enabled only in vertical layout.": "Nur im vertikalen Layout aktiviert."
"Enabled only in vertical layout.": "Nur im vertikalen Layout aktiviert.",
"No Conversion": "Keine Konvertierung",
"Simplified to Traditional": "Vereinfacht → Traditionell",
"Traditional to Simplified": "Traditionell → Vereinfacht",
"Simplified to Traditional (Taiwan)": "Vereinfacht → Traditionell (Taiwan)",
"Simplified to Traditional (Hong Kong)": "Vereinfacht → Traditionell (Hongkong)",
"Simplified to Traditional (Taiwan), with phrases": "Vereinfacht → Traditionell (Taiwan • Phrasen)",
"Traditional (Taiwan) to Simplified": "Traditionell (Taiwan) → Vereinfacht",
"Traditional (Hong Kong) to Simplified": "Traditionell (Hongkong) → Vereinfacht",
"Traditional (Taiwan) to Simplified, with phrases": "Traditionell (Taiwan • Phrasen) → Vereinfacht",
"Convert Simplified and Traditional Chinese": "Vereinfach./Traditionell konvertieren",
"Convert Mode": "Konvertierungsmodus"
}
@@ -659,5 +659,16 @@
"Unable to open book": "Αδύνατη η άνοιγμα του βιβλίου",
"Punctuation": "Στίξη",
"Replace Quotation Marks": "Αντικατάσταση εισαγωγικών",
"Enabled only in vertical layout.": "Ενεργοποιημένο μόνο σε κάθετη διάταξη."
"Enabled only in vertical layout.": "Ενεργοποιημένο μόνο σε κάθετη διάταξη.",
"No Conversion": "Χωρίς μετατροπή",
"Simplified to Traditional": "Απλοπ. → Παραδ.",
"Traditional to Simplified": "Παραδ. → Απλοπ.",
"Simplified to Traditional (Taiwan)": "Απλοπ. → Παραδ. (Ταϊβάν)",
"Simplified to Traditional (Hong Kong)": "Απλοπ. → Παραδ. (Χονγκ Κονγκ)",
"Simplified to Traditional (Taiwan), with phrases": "Απλοπ. → Παραδ. (Ταϊβάν • φράσεις)",
"Traditional (Taiwan) to Simplified": "Παραδ. (Ταϊβάν) → Απλοπ.",
"Traditional (Hong Kong) to Simplified": "Παραδ. (Χονγκ Κονγκ) → Απλοπ.",
"Traditional (Taiwan) to Simplified, with phrases": "Παραδ. (Ταϊβάν • φράσεις) → Απλοπ.",
"Convert Simplified and Traditional Chinese": "Μετατροπή Απλοπ./Παραδ. Κινέζικων",
"Convert Mode": "Λειτουργία μετατροπής"
}
@@ -663,5 +663,16 @@
"Unable to open book": "No se puede abrir el libro",
"Punctuation": "Signos de puntuación",
"Replace Quotation Marks": "Reemplazar comillas",
"Enabled only in vertical layout.": "Habilitado solo en diseño vertical."
"Enabled only in vertical layout.": "Habilitado solo en diseño vertical.",
"No Conversion": "Sin conversión",
"Simplified to Traditional": "Simpl. → Trad.",
"Traditional to Simplified": "Trad. → Simpl.",
"Simplified to Traditional (Taiwán)": "Simpl. → Trad. (Taiwán)",
"Simplified to Traditional (Hong Kong)": "Simpl. → Trad. (Hong Kong)",
"Simplified to Traditional (Taiwán), with phrases": "Simpl. → Trad. (Taiwán • frases)",
"Traditional (Taiwán) to Simplified": "Trad. (Taiwán) → Simpl.",
"Traditional (Hong Kong) to Simplified": "Trad. (Hong Kong) → Simpl.",
"Traditional (Taiwán) to Simplified, with phrases": "Trad. (Taiwán • frases) → Simpl.",
"Convert Simplified and Traditional Chinese": "Convertir chino Simpl./Trad.",
"Convert Mode": "Modo de conversión"
}
@@ -659,5 +659,16 @@
"Unable to open book": "قادر به باز کردن کتاب نیست",
"Punctuation": "علامت نگارشی",
"Replace Quotation Marks": "جایگزینی علامت نقل قول",
"Enabled only in vertical layout.": "فقط در طرح عمودی فعال است."
"Enabled only in vertical layout.": "فقط در طرح عمودی فعال است.",
"No Conversion": "بدون تبدیل",
"Simplified to Traditional": "ساده → سنتی",
"Traditional to Simplified": "سنتی → ساده",
"Simplified to Traditional (Taiwan)": "ساده → سنتی (تایوان)",
"Simplified to Traditional (Hong Kong)": "ساده → سنتی (هنگ‌کنگ)",
"Simplified to Traditional (Taiwan), with phrases": "ساده → سنتی (تایوان • عبارات)",
"Traditional (Taiwan) to Simplified": "سنتی (تایوان) → ساده",
"Traditional (Hong Kong) to Simplified": "سنتی (هنگ‌کنگ) → ساده",
"Traditional (Taiwan) to Simplified, with phrases": "سنتی (تایوان • عبارات) → ساده",
"Convert Simplified and Traditional Chinese": "تبدیل چینی ساده/سنتی",
"Convert Mode": "حالت تبدیل"
}
@@ -663,5 +663,16 @@
"Unable to open book": "Impossible d'ouvrir le livre",
"Punctuation": "Ponctuation",
"Replace Quotation Marks": "Remplacer les guillemets",
"Enabled only in vertical layout.": "Activé uniquement en disposition verticale."
"Enabled only in vertical layout.": "Activé uniquement en disposition verticale.",
"No Conversion": "Pas de conversion",
"Simplified to Traditional": "Simp. → Trad.",
"Traditional to Simplified": "Trad. → Simp.",
"Simplified to Traditional (Taiwan)": "Simp. → Trad. (Taïwan)",
"Simplified to Traditional (Hong Kong)": "Simp. → Trad. (Hong Kong)",
"Simplified to Traditional (Taiwan), with phrases": "Simp. → Trad. (Taïwan • phrases)",
"Traditional (Taiwan) to Simplified": "Trad. (Taïwan) → Simp.",
"Traditional (Hong Kong) to Simplified": "Trad. (Hong Kong) → Simp.",
"Traditional (Taiwan) to Simplified, with phrases": "Trad. (Taïwan • phrases) → Simp.",
"Convert Simplified and Traditional Chinese": "Convertir chinois simp./trad.",
"Convert Mode": "Mode de conversion"
}
@@ -659,5 +659,16 @@
"Unable to open book": "पुस्तक खोलने में असमर्थ",
"Punctuation": "विराम चिह्न",
"Replace Quotation Marks": "उद्धरण चिह्न बदलें",
"Enabled only in vertical layout.": "केवल ऊर्ध्वाधर लेआउट में सक्षम।"
"Enabled only in vertical layout.": "केवल ऊर्ध्वाधर लेआउट में सक्षम।",
"No Conversion": "कोई रूपांतरण नहीं",
"Simplified to Traditional": "सरलीकृत → पारंपरिक",
"Traditional to Simplified": "पारंपरिक → सरलीकृत",
"Simplified to Traditional (Taiwan)": "सरलीकृत → पारंपरिक (ताइवान)",
"Simplified to Traditional (Hong Kong)": "सरलीकृत → पारंपरिक (हांगकांग)",
"Simplified to Traditional (Taiwan), with phrases": "सरलीकृत → पारंपरिक (ताइवान • वाक्यांश)",
"Traditional (Taiwan) to Simplified": "पारंपरिक (ताइवान) → सरलीकृत",
"Traditional (Hong Kong) to Simplified": "पारंपरिक (हांगकांग) → सरलीकृत",
"Traditional (Taiwan) to Simplified, with phrases": "पारंपरिक (ताइवान • वाक्यांश) → सरलीकृत",
"Convert Simplified and Traditional Chinese": "सरलीकृत/पारंपरिक चीनी रूपांतरण",
"Convert Mode": "रूपांतरण मोड"
}
@@ -655,5 +655,16 @@
"Unable to open book": "Tidak dapat membuka buku",
"Punctuation": "Tanda Baca",
"Replace Quotation Marks": "Ganti Tanda Kutip",
"Enabled only in vertical layout.": "Hanya diaktifkan dalam tata letak vertikal."
"Enabled only in vertical layout.": "Hanya diaktifkan dalam tata letak vertikal.",
"No Conversion": "Tanpa konversi",
"Simplified to Traditional": "Sederhana → Tradisional",
"Traditional to Simplified": "Tradisional → Sederhana",
"Simplified to Traditional (Taiwan)": "Sederhana → Tradisional (Taiwan)",
"Simplified to Traditional (Hong Kong)": "Sederhana → Tradisional (Hong Kong)",
"Simplified to Traditional (Taiwan), with phrases": "Sederhana → Tradisional (Taiwan • frasa)",
"Traditional (Taiwan) to Simplified": "Tradisional (Taiwan) → Sederhana",
"Traditional (Hong Kong) to Simplified": "Tradisional (Hong Kong) → Sederhana",
"Traditional (Taiwan) to Simplified, with phrases": "Tradisional (Taiwan • frasa) → Sederhana",
"Convert Simplified and Traditional Chinese": "Konversi Tionghoa Sederhana/Tradisional",
"Convert Mode": "Mode Konversi"
}
@@ -663,5 +663,16 @@
"Unable to open book": "Impossibile aprire il libro",
"Punctuation": "Segni di punteggiatura",
"Replace Quotation Marks": "Sostituisci le virgolette",
"Enabled only in vertical layout.": "Abilitato solo in layout verticale."
"Enabled only in vertical layout.": "Abilitato solo in layout verticale.",
"No Conversion": "Nessuna conversione",
"Simplified to Traditional": "Semplificato → Tradizionale",
"Traditional to Simplified": "Tradizionale → Semplificato",
"Simplified to Traditional (Taiwan)": "Semplificato → Tradizionale (Taiwan)",
"Simplified to Traditional (Hong Kong)": "Semplificato → Tradizionale (Hong Kong)",
"Simplified to Traditional (Taiwan), with phrases": "Semplificato → Tradizionale (Taiwan • frasi)",
"Traditional (Taiwan) to Simplified": "Tradizionale (Taiwan) → Semplificato",
"Traditional (Hong Kong) to Simplified": "Tradizionale (Hong Kong) → Semplificato",
"Traditional (Taiwan) to Simplified, with phrases": "Tradizionale (Taiwan • frasi) → Semplificato",
"Convert Simplified and Traditional Chinese": "Converti Cinese Semplificato/Tradizionale",
"Convert Mode": "Modalità conversione"
}
@@ -655,5 +655,16 @@
"Unable to open book": "本を開くことができません",
"Punctuation": "句読点",
"Replace Quotation Marks": "引用符を置き換える",
"Enabled only in vertical layout.": "縦書きレイアウトでのみ有効です。"
"Enabled only in vertical layout.": "縦書きレイアウトでのみ有効です。",
"No Conversion": "変換なし",
"Simplified to Traditional": "簡体字 → 繁体字",
"Traditional to Simplified": "繁体字 → 簡体字",
"Simplified to Traditional (Taiwan)": "簡体字 → 繁体字(台湾)",
"Simplified to Traditional (Hong Kong)": "簡体字 → 繁体字(香港)",
"Simplified to Traditional (Taiwan), with phrases": "簡体字 → 繁体字(台湾)• フレーズ",
"Traditional (Taiwan) to Simplified": "繁体字(台湾) → 簡体字",
"Traditional (Hong Kong) to Simplified": "繁体字(香港) → 簡体字",
"Traditional (Taiwan) to Simplified, with phrases": "繁体字(台湾) → 簡体字 • フレーズ",
"Convert Simplified and Traditional Chinese": "簡体字/繁体字変換",
"Convert Mode": "変換モード"
}
@@ -655,5 +655,16 @@
"Unable to open book": "책을 열 수 없습니다",
"Punctuation": "구두점",
"Replace Quotation Marks": "인용 부호 바꾸기",
"Enabled only in vertical layout.": "세로 레이아웃에서만 활성화됩니다."
"Enabled only in vertical layout.": "세로 레이아웃에서만 활성화됩니다.",
"No Conversion": "변환 없음",
"Simplified to Traditional": "간체 → 번체",
"Traditional to Simplified": "번체 → 간체",
"Simplified to Traditional (Taiwan)": "간체 → 번체 (대만)",
"Simplified to Traditional (Hong Kong)": "간체 → 번체 (홍콩)",
"Simplified to Traditional (Taiwan), with phrases": "간체 → 번체 (대만) • 문구",
"Traditional (Taiwan) to Simplified": "번체 (대만) → 간체",
"Traditional (Hong Kong) to Simplified": "번체 (홍콩) → 간체",
"Traditional (Taiwan) to Simplified, with phrases": "번체 (대만) → 간체 • 문구",
"Convert Simplified and Traditional Chinese": "간체/번체 변환",
"Convert Mode": "변환 모드"
}
@@ -659,5 +659,16 @@
"Unable to open book": "Kan boek niet openen",
"Punctuation": "Interpunctie",
"Replace Quotation Marks": "Aanhalingstekens vervangen",
"Enabled only in vertical layout.": "Alleen ingeschakeld in verticale lay-out."
"Enabled only in vertical layout.": "Alleen ingeschakeld in verticale lay-out.",
"No Conversion": "Geen conversie",
"Simplified to Traditional": "Vereenvoudigd → Traditioneel",
"Traditional to Simplified": "Traditioneel → Vereenvoudigd",
"Simplified to Traditional (Taiwan)": "Vereenvoudigd → Traditioneel (Taiwan)",
"Simplified to Traditional (Hong Kong)": "Vereenvoudigd → Traditioneel (Hong Kong)",
"Simplified to Traditional (Taiwan), with phrases": "Vereenvoudigd → Traditioneel (Taiwan • zinnen)",
"Traditional (Taiwan) to Simplified": "Traditioneel (Taiwan) → Vereenvoudigd",
"Traditional (Hong Kong) to Simplified": "Traditioneel (Hong Kong) → Vereenvoudigd",
"Traditional (Taiwan) to Simplified, with phrases": "Traditioneel (Taiwan • zinnen) → Vereenvoudigd",
"Convert Simplified and Traditional Chinese": "Converteer Vereenvoudigd/Traditioneel Chinees",
"Convert Mode": "Conversiemodus"
}
@@ -667,5 +667,16 @@
"Unable to open book": "Nie można otworzyć książki",
"Punctuation": "Interpunkcja",
"Replace Quotation Marks": "Zamień cudzysłowy",
"Enabled only in vertical layout.": "Włączone tylko w układzie pionowym."
"Enabled only in vertical layout.": "Włączone tylko w układzie pionowym.",
"No Conversion": "Brak konwersji",
"Simplified to Traditional": "Uproszczony → Tradycyjny",
"Traditional to Simplified": "Tradycyjny → Uproszczony",
"Simplified to Traditional (Taiwan)": "Uproszczony → Tradycyjny (Tajwan)",
"Simplified to Traditional (Hong Kong)": "Uproszczony → Tradycyjny (Hongkong)",
"Simplified to Traditional (Taiwan), with phrases": "Uproszczony → Tradycyjny (Tajwan • frazy)",
"Traditional (Taiwan) to Simplified": "Tradycyjny (Tajwan) → Uproszczony",
"Traditional (Hong Kong) to Simplified": "Tradycyjny (Hongkong) → Uproszczony",
"Traditional (Taiwan) to Simplified, with phrases": "Tradycyjny (Tajwan • frazy) → Uproszczony",
"Convert Simplified and Traditional Chinese": "Konwertuj chiński uproszczony/tradycyjny",
"Convert Mode": "Tryb konwersji"
}
@@ -663,5 +663,16 @@
"Unable to open book": "Não foi possível abrir o livro",
"Punctuation": "Pontuação",
"Replace Quotation Marks": "Substituir Aspas",
"Enabled only in vertical layout.": "Habilitado apenas no layout vertical."
"Enabled only in vertical layout.": "Habilitado apenas no layout vertical.",
"No Conversion": "Sem conversão",
"Simplified to Traditional": "Simplificado → Tradicional",
"Traditional to Simplified": "Tradicional → Simplificado",
"Simplified to Traditional (Taiwan)": "Simplificado → Tradicional (Taiwan)",
"Simplified to Traditional (Hong Kong)": "Simplificado → Tradicional (Hong Kong)",
"Simplified to Traditional (Taiwan), with phrases": "Simplificado → Tradicional (Taiwan • frases)",
"Traditional (Taiwan) to Simplified": "Tradicional (Taiwan) → Simplificado",
"Traditional (Hong Kong) to Simplified": "Tradicional (Hong Kong) → Simplificado",
"Traditional (Taiwan) to Simplified, with phrases": "Tradicional (Taiwan • frases) → Simplificado",
"Convert Simplified and Traditional Chinese": "Converter Chinês Simpl./Trad.",
"Convert Mode": "Modo de conversão"
}
@@ -667,5 +667,16 @@
"Unable to open book": "Не удалось открыть книгу",
"Punctuation": "Пунктуация",
"Replace Quotation Marks": "Заменить кавычки",
"Enabled only in vertical layout.": "Включено только в вертикальной раскладке."
"Enabled only in vertical layout.": "Включено только в вертикальной раскладке.",
"No Conversion": "Без преобразования",
"Simplified to Traditional": "Упрощённый → Традиционный",
"Traditional to Simplified": "Традиционный → Упрощённый",
"Simplified to Traditional (Taiwan)": "Упрощённый → Традиционный (Тайвань)",
"Simplified to Traditional (Hong Kong)": "Упрощённый → Традиционный (Гонконг)",
"Simplified to Traditional (Taiwan), with phrases": "Упрощённый → Традиционный (Тайвань • фразы)",
"Traditional (Taiwan) to Simplified": "Традиционный (Тайвань) → Упрощённый",
"Traditional (Hong Kong) to Simplified": "Традиционный (Гонконг) → Упрощённый",
"Traditional (Taiwan) to Simplified, with phrases": "Традиционный (Тайвань • фразы) → Упрощённый",
"Convert Simplified and Traditional Chinese": "Преобразовать упрощённый/традиционный китайский",
"Convert Mode": "Режим преобразования"
}
@@ -659,5 +659,16 @@
"Unable to open book": "පොත විවෘත කිරීමට නොහැක",
"Punctuation": "ලකුණු",
"Replace Quotation Marks": "උද්ධෘත ලකුණු ප්‍රතිස්ථාපනය කරන්න",
"Enabled only in vertical layout.": "සිරස් ආකෘතියේ පමණක් සක්‍රීයයි."
"Enabled only in vertical layout.": "සිරස් ආකෘතියේ පමණක් සක්‍රීයයි.",
"No Conversion": "ප්‍රතිවර්තනයක් නැත",
"Simplified to Traditional": "සරල → සාම්ප්‍රදායික",
"Traditional to Simplified": "සාම්ප්‍රදායික → සරල",
"Simplified to Traditional (Taiwan)": "සරල → සාම්ප්‍රදායික (තායිවான்)",
"Simplified to Traditional (Hong Kong)": "සරල → සාම්ප්‍රදායික (හොං කොං)",
"Simplified to Traditional (Taiwan), with phrases": "සරල → සාම්ප්‍රදායික (තායිවාන • වාක්‍ය)",
"Traditional (Taiwan) to Simplified": "සාම්ප්‍රදායික (තායිවාන) → සරල",
"Traditional (Hong Kong) to Simplified": "සාම්ප්‍රදායික (හොං කොං) → සරල",
"Traditional (Taiwan) to Simplified, with phrases": "සාම්ප්‍රදායික (තායිවාන • වාක්‍ය) → සරල",
"Convert Simplified and Traditional Chinese": "සරල/සාම්ප්‍රදායික චීන පරිවර්තනය",
"Convert Mode": "පරිවර්තන මෝඩියුලය"
}
@@ -659,5 +659,16 @@
"Unable to open book": "Kunde inte öppna bok",
"Punctuation": "Interpunktion",
"Replace Quotation Marks": "Ersätt citattecken",
"Enabled only in vertical layout.": "Aktiverad endast i vertikal layout."
"Enabled only in vertical layout.": "Aktiverad endast i vertikal layout.",
"No Conversion": "Ingen konvertering",
"Simplified to Traditional": "Förenklad → Traditionell",
"Traditional to Simplified": "Traditionell → Förenklad",
"Simplified to Traditional (Taiwan)": "Förenklad → Traditionell (Taiwan)",
"Simplified to Traditional (Hong Kong)": "Förenklad → Traditionell (Hongkong)",
"Simplified to Traditional (Taiwan), with phrases": "Förenklad → Traditionell (Taiwan • fraser)",
"Traditional (Taiwan) to Simplified": "Traditionell (Taiwan) → Förenklad",
"Traditional (Hong Kong) to Simplified": "Traditionell (Hongkong) → Förenklad",
"Traditional (Taiwan) to Simplified, with phrases": "Traditionell (Taiwan • fraser) → Förenklad",
"Convert Simplified and Traditional Chinese": "Konvertera förenklad/traditionell kinesiska",
"Convert Mode": "Konverteringsläge"
}
@@ -659,5 +659,16 @@
"Unable to open book": "புத்தகத்தைத் திறக்க முடியவில்லை",
"Punctuation": "விருத்தி",
"Replace Quotation Marks": "உதயம்சுட்டிகளை மாற்றவும்",
"Enabled only in vertical layout.": "செங்குத்து அமைப்பில் மட்டுமே இயலுமைப்படுத்தப்பட்டது."
"Enabled only in vertical layout.": "செங்குத்து அமைப்பில் மட்டுமே இயலுமைப்படுத்தப்பட்டது.",
"No Conversion": "மாற்றம் செய்யவில்லை",
"Simplified to Traditional": "எளிய → பாரம்பரிய",
"Traditional to Simplified": "பாரம்பரிய → எளிய",
"Simplified to Traditional (Taiwan)": "எளிய → பாரம்பரிய (தைவான்)",
"Simplified to Traditional (Hong Kong)": "எளிய → பாரம்பரிய (ஹாங்காங்)",
"Simplified to Traditional (Taiwan), with phrases": "எளிய → பாரம்பரிய (தைவான் • வசனங்கள்)",
"Traditional (Taiwan) to Simplified": "பாரம்பரிய (தைவான்) → எளிய",
"Traditional (Hong Kong) to Simplified": "பாரம்பரிய (ஹாங்காங்) → எளிய",
"Traditional (Taiwan) to Simplified, with phrases": "பாரம்பரிய (தைவான் • வசனங்கள்) → எளிய",
"Convert Simplified and Traditional Chinese": "எளிய/பாரம்பரிய சீன மொழி மாற்றம்",
"Convert Mode": "மாற்ற முறை"
}
@@ -655,5 +655,16 @@
"Unable to open book": "ไม่สามารถเปิดหนังสือได้",
"Punctuation": "เครื่องหมายวรรคตอน",
"Replace Quotation Marks": "แทนที่เครื่องหมายคำพูด",
"Enabled only in vertical layout.": "เปิดใช้งานเฉพาะในเค้าโครงแนวตั้งเท่านั้น"
"Enabled only in vertical layout.": "เปิดใช้งานเฉพาะในเค้าโครงแนวตั้งเท่านั้น",
"No Conversion": "ไม่แปลงค่า",
"Simplified to Traditional": "ตัวย่อ → ตัวเต็ม",
"Traditional to Simplified": "ตัวเต็ม → ตัวย่อ",
"Simplified to Traditional (Taiwan)": "ตัวย่อ → ตัวเต็ม (ไต้หวัน)",
"Simplified to Traditional (Hong Kong)": "ตัวย่อ → ตัวเต็ม (ฮ่องกง)",
"Simplified to Traditional (Taiwan), with phrases": "ตัวย่อ → ตัวเต็ม (ไต้หวัน • วลี)",
"Traditional (Taiwan) to Simplified": "ตัวเต็ม (ไต้หวัน) → ตัวย่อ",
"Traditional (Hong Kong) to Simplified": "ตัวเต็ม (ฮ่องกง) → ตัวย่อ",
"Traditional (Taiwan) to Simplified, with phrases": "ตัวเต็ม (ไต้หวัน • วลี) → ตัวย่อ",
"Convert Simplified and Traditional Chinese": "แปลงจีนตัวย่อ/ตัวเต็ม",
"Convert Mode": "โหมดแปลงค่า"
}
@@ -659,5 +659,16 @@
"Unable to open book": "Kitap açılamıyor",
"Punctuation": "Noktalama İşaretleri",
"Replace Quotation Marks": "Tırnak İşaretlerini Değiştir",
"Enabled only in vertical layout.": "Yalnızca dikey düzenle etkinleştirildi."
"Enabled only in vertical layout.": "Yalnızca dikey düzenle etkinleştirildi.",
"No Conversion": "Dönüştürme yok",
"Simplified to Traditional": "Basitleştirilmiş → Geleneksel",
"Traditional to Simplified": "Geleneksel → Basitleştirilmiş",
"Simplified to Traditional (Taiwan)": "Basitleştirilmiş → Geleneksel (Tayvan)",
"Simplified to Traditional (Hong Kong)": "Basitleştirilmiş → Geleneksel (Hong Kong)",
"Simplified to Traditional (Taiwan), with phrases": "Basitleştirilmiş → Geleneksel (Tayvan • ifadeler)",
"Traditional (Taiwan) to Simplified": "Geleneksel (Tayvan) → Basitleştirilmiş",
"Traditional (Hong Kong) to Simplified": "Geleneksel (Hong Kong) → Basitleştirilmiş",
"Traditional (Taiwan) to Simplified, with phrases": "Geleneksel (Tayvan • ifadeler) → Basitleştirilmiş",
"Convert Simplified and Traditional Chinese": "Basitleştirilmiş/Geleneksel Çince Dönüştür",
"Convert Mode": "Dönüştürme Modu"
}
@@ -667,5 +667,16 @@
"Unable to open book": "Не вдалося відкрити книгу",
"Punctuation": "Пунктуація",
"Replace Quotation Marks": "Замінити лапки",
"Enabled only in vertical layout.": "Активовано лише у вертикальному макеті."
"Enabled only in vertical layout.": "Активовано лише у вертикальному макеті.",
"No Conversion": "Без конвертації",
"Simplified to Traditional": "Спрощене → Традиційне",
"Traditional to Simplified": "Традиційне → Спрощене",
"Simplified to Traditional (Taiwan)": "Спрощене → Традиційне (Тайвань)",
"Simplified to Traditional (Hong Kong)": "Спрощене → Традиційне (Гонконг)",
"Simplified to Traditional (Taiwan), with phrases": "Спрощене → Традиційне (Тайвань • фрази)",
"Traditional (Taiwan) to Simplified": "Традиційне (Тайвань) → Спрощене",
"Traditional (Hong Kong) to Simplified": "Традиційне (Гонконг) → Спрощене",
"Traditional (Taiwan) to Simplified, with phrases": "Традиційне (Тайвань • фрази) → Спрощене",
"Convert Simplified and Traditional Chinese": "Конвертувати спрощену/традиційну китайську",
"Convert Mode": "Режим конвертації"
}
@@ -655,5 +655,16 @@
"Unable to open book": "Không thể mở sách",
"Punctuation": "Dấu câu",
"Replace Quotation Marks": "Thay thế dấu ngoặc kép",
"Enabled only in vertical layout.": "Chỉ bật trong bố cục dọc."
"Enabled only in vertical layout.": "Chỉ bật trong bố cục dọc.",
"No Conversion": "Không chuyển đổi",
"Simplified to Traditional": "Giản thể → Phồn thể",
"Traditional to Simplified": "Phồn thể → Giản thể",
"Simplified to Traditional (Taiwan)": "Giản thể → Phồn thể (Đài Loan)",
"Simplified to Traditional (Hong Kong)": "Giản thể → Phồn thể (Hồng Kông)",
"Simplified to Traditional (Taiwan), with phrases": "Giản thể → Phồn thể (Đài Loan • cụm từ)",
"Traditional (Taiwan) to Simplified": "Phồn thể (Đài Loan) → Giản thể",
"Traditional (Hong Kong) to Simplified": "Phồn thể (Hồng Kông) → Giản thể",
"Traditional (Taiwan) to Simplified, with phrases": "Phồn thể (Đài Loan • cụm từ) → Giản thể",
"Convert Simplified and Traditional Chinese": "Chuyển đổi Trung giản/Phồn thể",
"Convert Mode": "Chế độ chuyển đổi"
}
@@ -655,5 +655,16 @@
"Unable to open book": "无法打开书籍",
"Punctuation": "标点符号",
"Replace Quotation Marks": "替换引号",
"Enabled only in vertical layout.": "仅在竖排布局中启用"
"Enabled only in vertical layout.": "仅在竖排布局中启用",
"No Conversion": "不转换",
"Simplified to Traditional": "简体 → 繁体",
"Traditional to Simplified": "繁体 → 简体",
"Simplified to Traditional (Taiwan)": "简体 → 繁体(台湾)",
"Simplified to Traditional (Hong Kong)": "简体 → 繁体(香港)",
"Simplified to Traditional (Taiwan), with phrases": "简体 → 繁体(台湾)习惯用语",
"Traditional (Taiwan) to Simplified": "繁体(台湾) → 简体",
"Traditional (Hong Kong) to Simplified": "繁体(香港) → 简体",
"Traditional (Taiwan) to Simplified, with phrases": "繁体(台湾) → 简体习惯用语",
"Convert Simplified and Traditional Chinese": "简繁中文转换",
"Convert Mode": "转换模式"
}
@@ -655,5 +655,16 @@
"Unable to open book": "無法打開書籍",
"Punctuation": "標點符號",
"Replace Quotation Marks": "替換引號",
"Enabled only in vertical layout.": "僅在直排佈局中啟用"
"Enabled only in vertical layout.": "僅在直排佈局中啟用",
"No Conversion": "不轉換",
"Simplified to Traditional": "簡體 → 繁體",
"Traditional to Simplified": "繁體 → 簡體",
"Simplified to Traditional (Taiwan)": "簡體 → 繁體(台灣)",
"Simplified to Traditional (Hong Kong)": "簡體 → 繁體(香港)",
"Simplified to Traditional (Taiwan), with phrases": "簡體 → 繁體(台灣)慣用語",
"Traditional (Taiwan) to Simplified": "繁體(台灣) → 簡體",
"Traditional (Hong Kong) to Simplified": "繁體(香港) → 簡體",
"Traditional (Taiwan) to Simplified, with phrases": "繁體(台灣) → 簡體慣用語",
"Convert Simplified and Traditional Chinese": "簡繁中文轉換",
"Convert Mode": "轉換模式"
}
@@ -0,0 +1,42 @@
import { describe, test, expect, beforeAll } from 'vitest';
import init, { simplecc } from '@simplecc/simplecc_wasm';
import { readFile } from 'fs/promises';
import { join } from 'path';
describe.concurrent('suite', () => {
beforeAll(async () => {
const wasmPath = join(process.cwd(), 'public/vendor/simplecc/simplecc_wasm_bg.wasm');
const wasmBuffer = await readFile(wasmPath);
await init(wasmBuffer);
await init();
});
test('basic s2t and t2s', () => {
expect(simplecc('发财了去植发', 's2t')).toBe('發財了去植髮');
expect(simplecc('發財了去植髮', 't2s')).toBe('发财了去植发');
});
test('s2tw - Simplified to Traditional (Taiwan)', () => {
expect(simplecc('鼠标', 's2tw')).toBe('鼠標');
expect(simplecc('软件', 's2tw')).toBe('軟件');
expect(simplecc('信息', 's2tw')).toBe('信息');
});
test('s2twp - Simplified to Traditional (Taiwan) with phrases', () => {
expect(simplecc('计算机', 's2twp')).toBe('計算機');
expect(simplecc('打印机', 's2twp')).toBe('印表機');
expect(simplecc('激光', 's2twp')).toBe('雷射');
});
test('tw2s - Traditional (Taiwan) to Simplified', () => {
expect(simplecc('滑鼠', 'tw2s')).toBe('滑鼠');
expect(simplecc('軟體', 'tw2s')).toBe('软体');
expect(simplecc('資訊', 'tw2s')).toBe('资讯');
});
test('tw2sp - Traditional (Taiwan) to Simplified with phrases', () => {
expect(simplecc('電腦', 'tw2sp')).toBe('电脑');
expect(simplecc('印表機', 'tw2sp')).toBe('打印机');
expect(simplecc('雷射', 'tw2sp')).toBe('激光');
});
});
@@ -147,6 +147,7 @@ const FoliateViewer: React.FC<{
'whitespace',
'language',
'sanitizer',
'simplecc',
],
};
return Promise.resolve(transformContent(ctx));
+4 -1
View File
@@ -26,7 +26,10 @@ export default function Select({
value={value}
onChange={onChange}
onKeyDown={(e) => e.stopPropagation()}
className={clsx('select bg-base-200 h-8 min-h-8 rounded-md border-none text-sm', className)}
className={clsx(
'select bg-base-200 h-8 min-h-8 max-w-[60%] truncate rounded-md border-none text-sm',
className,
)}
disabled={disabled}
style={{
textAlignLast: 'end',
@@ -9,6 +9,7 @@ import { saveViewSettings } from '@/helpers/settings';
import { getTranslators } from '@/services/translators';
import { useResetViewSettings } from '@/hooks/useResetSettings';
import { TRANSLATED_LANGS, TRANSLATOR_LANGS } from '@/services/constants';
import { ConvertChineseVariant } from '@/types/book';
import { SettingsPanelPanelProp } from './SettingsDialog';
import { isCJKEnv } from '@/utils/misc';
import Select from '@/components/Select';
@@ -30,6 +31,9 @@ const LangPanel: React.FC<SettingsPanelPanelProp> = ({ bookKey, onRegisterReset
const [replaceQuotationMarks, setReplaceQuotationMarks] = useState(
viewSettings.replaceQuotationMarks,
);
const [convertChineseVariant, setConvertChineseVariant] = useState(
viewSettings.convertChineseVariant,
);
const resetToDefaults = useResetViewSettings();
@@ -195,6 +199,46 @@ const LangPanel: React.FC<SettingsPanelPanelProp> = ({ bookKey, onRegisterReset
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [replaceQuotationMarks]);
const getConvertModeOptions: () => { value: ConvertChineseVariant; label: string }[] = () => {
return [
{ value: 'none', label: _('No Conversion') },
{ value: 's2t', label: _('Simplified to Traditional') },
{ value: 't2s', label: _('Traditional to Simplified') },
{ value: 's2tw', label: _('Simplified to Traditional (Taiwan)') },
{ value: 's2hk', label: _('Simplified to Traditional (Hong Kong)') },
{ value: 's2twp', label: _('Simplified to Traditional (Taiwan), with phrases') },
{ value: 'tw2s', label: _('Traditional (Taiwan) to Simplified') },
{ value: 'hk2s', label: _('Traditional (Hong Kong) to Simplified') },
{ value: 'tw2sp', label: _('Traditional (Taiwan) to Simplified, with phrases') },
];
};
const getConvertModeOption = () => {
const value = convertChineseVariant;
const availableOptions = getConvertModeOptions();
return availableOptions.find((o) => o.value === value) || availableOptions[0]!;
};
const handleSelectConvertMode = (event: React.ChangeEvent<HTMLSelectElement>) => {
const option = event.target.value as ConvertChineseVariant;
setConvertChineseVariant(option);
};
useEffect(() => {
if (convertChineseVariant === viewSettings.convertChineseVariant) return;
saveViewSettings(
envConfig,
bookKey,
'convertChineseVariant',
convertChineseVariant,
true,
false,
).then(() => {
recreateViewer(envConfig, bookKey);
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [convertChineseVariant]);
return (
<div className={clsx('my-4 w-full space-y-6')}>
<div className='w-full'>
@@ -288,6 +332,24 @@ const LangPanel: React.FC<SettingsPanelPanelProp> = ({ bookKey, onRegisterReset
</div>
</div>
)}
{isCJKEnv() && (
<div className='w-full'>
<h2 className='mb-2 font-medium'>{_('Convert Simplified and Traditional Chinese')}</h2>
<div className='card border-base-200 bg-base-100 border shadow'>
<div className='divide-base-200'>
<div className='config-item'>
<span className=''>{_('Convert Mode')}</span>
<Select
value={getConvertModeOption().value}
onChange={handleSelectConvertMode}
options={getConvertModeOptions()}
/>
</div>
</div>
</div>
</div>
)}
</div>
);
};
@@ -38,6 +38,7 @@ import {
DEFAULT_BOOK_LAYOUT,
DEFAULT_BOOK_STYLE,
DEFAULT_BOOK_FONT,
DEFAULT_BOOK_LANGUAGE,
DEFAULT_VIEW_CONFIG,
DEFAULT_READSETTINGS,
SYSTEM_SETTINGS_VERSION,
@@ -169,6 +170,7 @@ export abstract class BaseAppService implements AppService {
...DEFAULT_BOOK_LAYOUT,
...DEFAULT_BOOK_STYLE,
...DEFAULT_BOOK_FONT,
...DEFAULT_BOOK_LANGUAGE,
...(this.isMobile ? DEFAULT_MOBILE_VIEW_SETTINGS : {}),
...(isCJKEnv() ? DEFAULT_CJK_VIEW_SETTINGS : {}),
...DEFAULT_VIEW_CONFIG,
+6 -1
View File
@@ -1,5 +1,6 @@
import {
BookFont,
BookLanguage,
BookLayout,
BookSearchConfig,
BookStyle,
@@ -148,11 +149,15 @@ export const DEFAULT_BOOK_LAYOUT: BookLayout = {
writingMode: 'auto',
vertical: false,
rtl: false,
replaceQuotationMarks: true,
scrollingOverlap: 0,
allowScript: false,
};
export const DEFAULT_BOOK_LANGUAGE: BookLanguage = {
replaceQuotationMarks: true,
convertChineseVariant: 'none',
};
export const DEFAULT_BOOK_STYLE: BookStyle = {
zoomLevel: 100,
paragraphMargin: 0.6,
@@ -4,6 +4,7 @@ import { languageTransformer } from './language';
import { punctuationTransformer } from './punctuation';
import { whitespaceTransformer } from './whitespace';
import { sanitizerTransformer } from './sanitizer';
import { simpleccTransformer } from './simplecc';
import { styleTransformer } from './style';
export const availableTransformers: Transformer[] = [
@@ -13,5 +14,6 @@ export const availableTransformers: Transformer[] = [
styleTransformer,
whitespaceTransformer,
sanitizerTransformer,
simpleccTransformer,
// Add more transformers here
];
@@ -0,0 +1,46 @@
import type { Transformer } from './types';
import { simplecc, initSimpleCC } from '@/utils/simplecc';
export const simpleccTransformer: Transformer = {
name: 'simplecc',
transform: async (ctx) => {
const convertChineseVariant = ctx.viewSettings.convertChineseVariant;
if (!convertChineseVariant || convertChineseVariant === 'none') {
return ctx.content;
}
await initSimpleCC();
const parser = new DOMParser();
const doc = parser.parseFromString(ctx.content, 'text/html');
const walker = document.createTreeWalker(
doc.body || doc.documentElement,
NodeFilter.SHOW_TEXT,
{
acceptNode: (node) => {
const parent = node.parentElement;
if (parent && (parent.tagName === 'SCRIPT' || parent.tagName === 'STYLE')) {
return NodeFilter.FILTER_REJECT;
}
return node.textContent?.trim() ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_REJECT;
},
},
);
const textNodes: Text[] = [];
let currentNode: Node | null;
while ((currentNode = walker.nextNode())) {
textNodes.push(currentNode as Text);
}
for (const textNode of textNodes) {
if (textNode.textContent) {
textNode.textContent = simplecc(textNode.textContent, convertChineseVariant);
}
}
const serializer = new XMLSerializer();
return serializer.serializeToString(doc);
},
};
+5 -1
View File
@@ -156,7 +156,11 @@ export const useReaderStore = create<ReaderStore>((set, get) => ({
const { file, config } = content;
console.log('Loading book', key);
const { book: bookDoc } = await new DocumentLoader(file).open();
updateToc(bookDoc, config.viewSettings?.sortedTOC ?? false);
await updateToc(
bookDoc,
config.viewSettings?.sortedTOC ?? false,
config.viewSettings?.convertChineseVariant ?? 'none',
);
if (!bookDoc.metadata.title) {
bookDoc.metadata.title = getBaseFilename(file.name);
}
+17 -1
View File
@@ -112,7 +112,6 @@ export interface BookLayout {
writingMode: WritingMode;
vertical: boolean;
rtl: boolean;
replaceQuotationMarks: boolean;
scrollingOverlap: number;
allowScript: boolean;
}
@@ -156,6 +155,22 @@ export interface BookFont {
fontWeight: number;
}
export type ConvertChineseVariant =
| 'none'
| 's2t'
| 't2s'
| 's2tw'
| 's2hk'
| 's2twp'
| 'tw2s'
| 'hk2s'
| 'tw2sp';
export interface BookLanguage {
replaceQuotationMarks: boolean;
convertChineseVariant: ConvertChineseVariant;
}
export interface ViewConfig {
sideBarTab: string;
uiLanguage: string;
@@ -197,6 +212,7 @@ export interface ViewSettings
extends BookLayout,
BookStyle,
BookFont,
BookLanguage,
ViewConfig,
TTSConfig,
TranslatorConfig,
+12
View File
@@ -0,0 +1,12 @@
import init, { simplecc } from '@simplecc/simplecc_wasm';
let initialized = false;
const initSimpleCC = async () => {
if (initialized) return;
await init('/vendor/simplecc/simplecc_wasm_bg.wasm');
initialized = true;
};
export { simplecc, initSimpleCC };
+26 -2
View File
@@ -1,4 +1,6 @@
import { ConvertChineseVariant } from '@/types/book';
import { SectionItem, TOCItem, CFI, BookDoc } from '@/libs/document';
import { simplecc, initSimpleCC } from '@/utils/simplecc';
export const findParentPath = (toc: TOCItem[], href: string): TOCItem[] => {
for (const item of toc) {
@@ -37,10 +39,21 @@ export const findTocItemBS = (toc: TOCItem[], cfi: string): TOCItem | null => {
return result;
};
export const updateToc = (bookDoc: BookDoc, sortedTOC: boolean): void => {
export const updateToc = async (
bookDoc: BookDoc,
sortedTOC: boolean,
convertChineseVariant: ConvertChineseVariant,
) => {
const items = bookDoc?.toc || [];
if (!items.length) return;
if (convertChineseVariant && convertChineseVariant !== 'none') {
await initSimpleCC();
convertTocLabels(items, convertChineseVariant);
}
const sections = bookDoc?.sections || [];
if (!items.length || !sections.length) return;
if (!sections.length) return;
const sizes = sections.map((s) => (s.linear != 'no' && s.size > 0 ? s.size : 0));
let cumulativeSize = 0;
@@ -71,6 +84,17 @@ export const updateToc = (bookDoc: BookDoc, sortedTOC: boolean): void => {
}
};
const convertTocLabels = (items: TOCItem[], convertChineseVariant: ConvertChineseVariant) => {
items.forEach((item) => {
if (item.label) {
item.label = simplecc(item.label, convertChineseVariant);
}
if (item.subitems) {
convertTocLabels(item.subitems, convertChineseVariant);
}
});
};
const updateTocData = (
bookDoc: BookDoc,
items: TOCItem[],
+3
View File
@@ -30,6 +30,9 @@
"@pdfjs/*": [
"./public/vendor/pdfjs/*"
],
"@simplecc/*": [
"./public/vendor/simplecc/*"
]
}
},
"include": [