How chinayangxiaowei/marktext-chinese-language-pack works
Project type and purpose
• This is an open-source language-pack project for MarkText (an Electron-Vue based Markdown editor).
• Its purpose is to inject Simplified Chinese translations into the MarkText build by replacing resource files and running an automated translation script at compile time.
File structure
• Top level:
• .electron-vue/build.js → custom build script that overrides the official MarkText build step
• README.md → project description and instructions
• marktext_asar_translate.ts → TypeScript translation script that processes text resources
• translate-resources/ → directory containing translation dictionaries and exclusion lists
• Patterns & clues:
• A replacement approach (“resource-swap”) rather than modifying core MarkText logic
• A standalone TS script invoked at build time to generate translated assets based on environment variable lang
• Dependency on the host MarkText codebase (you copy these files into the official source)
README for additional insights
• Describes how to integrate with MarkText’s source tree (drop-in replacement of build.js)
• Explains environment variable controls and build steps (yarn install, ts-node, yarn build)
• Mentions extensibility for other languages via additional translate-resources/xxx_[lang].txt files
Main components
a. MarkText Official Codebase
– Electron-Vue application
– Original build pipeline (npm/yarn → webpack/electron-builder)
b. Custom Build Override
– .electron-vue/build.js (replaces the original)
c. Translation Engine
– marktext_asar_translate.ts (reads dictionaries, performs translation passes)
d. Translation Resources
– translate-resources/* (dictionary files and exclude lists)
e. Build Environment
– Node.js / yarn / ts-node / typescript
– Environment variable lang specifying target locale
f. Output Artifacts
– Translated resource files embedded into the ASAR package
– Final Electron app installer/bundle
Relationships & interactions
• The Developer sets lang=zh-cn (or other) in the shell
• yarn build invokes the custom build.js
• build.js triggers marktext_asar_translate.ts via ts-node
• translate script loads all files in translate-resources, applies translations to MarkText’s JSON/label files
• The modified resource files are injected back into the Electron build pipeline
• Electron-builder packages the final localized MarkText app
Architectural patterns & design principles
• Plugin/override pattern: swapping out a single build script instead of forking the entire codebase
• Resource-replacement strategy: externalizing translations for easy updates and additions of new languages
• Environment-driven configuration: building for different locales by setting an env var
• Separation of concerns: build orchestration (build.js) vs. translation logic (TS script) vs. data (dict files)