mirror of
https://github.com/chinayangxiaowei/marktext-chinese-language-pack.git
synced 2025-05-02 19:50:18 +08:00
Optimizing the search and matching of Label tags in main.js
This commit is contained in:
parent
41d84aa77a
commit
be1d0c9a21
@ -8,12 +8,13 @@ marktext 简体中文汉化包
|
||||
|
||||
1. 通过资源替换方式,修复MacOS下导入文档与图床上传失败的Bug;
|
||||
2. 加入自动翻译脚本,在编译的时候自动编译。
|
||||
3. 优化main.js中Label标记的搜索与匹配
|
||||
|
||||
###### 当前状态:
|
||||
|
||||
本预计发布多国语版本,考虑修改地方太多后期与官方代码同步将是非常繁重的任务,正在寻求一个更好的源码同步方案,暂不发布多国语版本。不过先把资源翻译代码开源,有兴趣的可以尝试自己编译所需要的操作系统版本。
|
||||
|
||||
如果其它国家的朋友也需要自己的语言包,可以翻译translate-resources/main_dict_zh-cn.txt、translate-resources/renderer_dict_zh-cn.txt文件,并命名为translate-resources/main_dict_[lang].txt, translate-resources/renderer_dict_[lang].txt并编辑,编译时请设置环境变量lang=你的语言缩写,如果你希望分享你的翻译成果,可以在[Issues](https://github.com/chinayangxiaowei/marktext-chinese-language-pack/issues)提交报告。
|
||||
如果其它国家的朋友也需要自己的语言包,可以翻译translate-resources/xxx_zh-cn.txt文件并命名为translate-resources/xxx_[lang].txt,编译时请设置环境变量lang=你的语言缩写,如果你希望分享你的翻译成果,可以在[Issues](https://github.com/chinayangxiaowei/marktext-chinese-language-pack/issues)提交报告。
|
||||
|
||||
###### 下载地址:
|
||||
|
||||
|
@ -45,44 +45,83 @@ function searchLabelsFromFile( fileName:string, exclude: void|string[]) : string
|
||||
return labels;
|
||||
}
|
||||
|
||||
function replaceLabelsFromFile( fileName:string, enDict: string[], toDict: string[]) : string {
|
||||
function replaceLabelsFromFile( fileName:string, toDict: string[]) : string {
|
||||
let content:string = ""
|
||||
if (enDict.length == toDict.length){
|
||||
if (fs.existsSync(fileName)) {
|
||||
let buffer = fs.readFileSync(fileName, "utf-8")
|
||||
let pat = /(label):"(.*?)"/gms
|
||||
content = buffer.replace(pat, (match, key, value) => {
|
||||
const idx = enDict.indexOf(value)
|
||||
if (idx != -1) {
|
||||
return key + ':"' + toDict[idx] + '"'
|
||||
}
|
||||
return match
|
||||
})
|
||||
let toKeys:string[] = []
|
||||
let toVals:string[] = []
|
||||
for (let i = 0; i < toDict.length; i++) {
|
||||
if (toDict[i].trim().length > 0) {
|
||||
const tow_cell = toDict[i].split('|')
|
||||
if (tow_cell.length == 2 ){
|
||||
toKeys.push(tow_cell[0])
|
||||
toVals.push(tow_cell[1])
|
||||
}
|
||||
}
|
||||
}
|
||||
if (fs.existsSync(fileName)) {
|
||||
let buffer = fs.readFileSync(fileName, "utf-8")
|
||||
let pat = /(label):"(.*?)"/gms
|
||||
content = buffer.replace(pat, (match, key, value) => {
|
||||
const idx = toKeys.indexOf(value)
|
||||
if (idx != -1) {
|
||||
return key + ':"' + toVals[idx] + '"'
|
||||
}
|
||||
return match
|
||||
})
|
||||
}
|
||||
|
||||
return content
|
||||
}
|
||||
|
||||
function replaceMain(fileName:string, langRootPath:string, enDict:string[], toLang:string, outFileName:string) : boolean {
|
||||
if (enDict.length == 0){
|
||||
return false
|
||||
}
|
||||
const toDictFileName = path.join(langRootPath, "translate-resources/main_dict_" + toLang + ".txt")
|
||||
const toDict = readStringArrayFromFile(toDictFileName)
|
||||
function replaceMainLabelDict(fileName:string, langRootPath:string, toDict:string[], toLang:string, outFileName:string) : boolean {
|
||||
if (toDict.length == 0){
|
||||
console.log("error in replaceMain, readStringArrayFromFile failed, not found "+ toDictFileName +".")
|
||||
return false
|
||||
}
|
||||
const main_content = replaceLabelsFromFile( fileName, enDict, toDict);
|
||||
const main_content = replaceLabelsFromFile( fileName, toDict);
|
||||
if (main_content.length>0) {
|
||||
fs.writeFileSync( outFileName, main_content )
|
||||
return true
|
||||
}else{
|
||||
console.log("error in replaceMain, replaceLabelsFromFile failed.")
|
||||
console.log("error in replaceMainLabelDict, replaceLabelsFromFile failed.")
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
function replaceMain(fileName:string, langRootPath:string, toLang:string, outFileName:string): boolean {
|
||||
const toDictFileName = path.join(langRootPath, "translate-resources/main_dict_" + toLang + ".txt")
|
||||
const toDict = readStringArrayFromFile(toDictFileName)
|
||||
if (toDict.length == 0){
|
||||
console.log("error in replaceMain, readStringArrayFromFile failed, not found "+ toDictFileName +".")
|
||||
return false
|
||||
}
|
||||
|
||||
if (!fs.existsSync(fileName)) {
|
||||
console.log("error in replaceMain, not found "+ fileName +".")
|
||||
return false
|
||||
}
|
||||
|
||||
let content = fs.readFileSync(fileName, "utf-8")
|
||||
|
||||
for (let i = 0; i < toDict.length; i++) {
|
||||
if (toDict[i].trim().length > 0) {
|
||||
const tow_cell = toDict[i].split('|')
|
||||
if (tow_cell.length == 2 ){
|
||||
content = content.replace(tow_cell[0], tow_cell[1])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (content.length>0) {
|
||||
fs.writeFileSync( outFileName, content )
|
||||
return true
|
||||
}else{
|
||||
console.log("error in replaceMain, readFileSync or replace failed.")
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
function replaceRenderer(fileName:string, langRootPath:string, toLang:string, outFileName:string): boolean {
|
||||
const toDictFileName = path.join(langRootPath, "translate-resources/renderer_dict_" + toLang + ".txt")
|
||||
const toDict = readStringArrayFromFile(toDictFileName)
|
||||
@ -118,39 +157,68 @@ function replaceRenderer(fileName:string, langRootPath:string, toLang:string, ou
|
||||
}
|
||||
|
||||
|
||||
function initMainEnDict(fileName:string, langRootPath:string) : string[] {
|
||||
const enDictFileName = path.join(langRootPath, "translate-resources/main_dict_en.txt")
|
||||
let enDict = readStringArrayFromFile(enDictFileName)
|
||||
function initMainLabelDict(fileName:string, langRootPath:string, toLang:string) : string[] {
|
||||
|
||||
if (enDict.length==0){
|
||||
const excludeDict = readStringArrayFromFile( path.join(langRootPath, "translate-resources/exclude.txt"))
|
||||
enDict = searchLabelsFromFile(fileName, excludeDict)
|
||||
if (enDict.length>0){
|
||||
writeStringArrayToFile(enDictFileName, enDict)
|
||||
const toDictFileName = path.join(langRootPath, "translate-resources/main_label_dict_" + toLang + ".txt")
|
||||
let toDict = readStringArrayFromFile(toDictFileName)
|
||||
let toKeys:string[] = []
|
||||
for (let i = 0; i < toDict.length; i++) {
|
||||
if (toDict[i].trim().length > 0) {
|
||||
const tow_cell = toDict[i].split('|')
|
||||
if (tow_cell.length == 2 ){
|
||||
toKeys.push(tow_cell[0])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (enDict.length==0){
|
||||
console.log("error in initMainEnDict, enDict is Empty.")
|
||||
}
|
||||
return enDict
|
||||
}
|
||||
|
||||
export function markTextAsarTranslate(langRootPath:string, toLang:string, mainJsFileName:string, outMainJsFileName:string, rendererJsFileName:string, outRendererJsFileName:string): void {
|
||||
|
||||
const enDict = initMainEnDict(mainJsFileName, langRootPath)
|
||||
|
||||
const excludeDict = readStringArrayFromFile( path.join(langRootPath, "translate-resources/exclude.txt"))
|
||||
let enDict = searchLabelsFromFile(fileName, excludeDict)
|
||||
if (enDict.length>0){
|
||||
if (replaceMain(mainJsFileName, langRootPath, enDict, toLang, outMainJsFileName)){
|
||||
console.log("replaceMain success.")
|
||||
}else{
|
||||
console.log("replaceMain failed.")
|
||||
let nAdd = 0
|
||||
for (let i=0; i<enDict.length; i++){
|
||||
if (toKeys.indexOf(enDict[i]) == -1){
|
||||
toDict.push(enDict[i]+'|'+enDict[i])
|
||||
toKeys.push(enDict[i])
|
||||
nAdd++
|
||||
}
|
||||
}
|
||||
if (nAdd!=0){
|
||||
//UI Label change, need to rewrite.
|
||||
writeStringArrayToFile(toDictFileName, toDict)
|
||||
}
|
||||
}
|
||||
|
||||
if (replaceRenderer(rendererJsFileName, langRootPath, toLang, outRendererJsFileName)){
|
||||
console.log("replaceRenderer success.")
|
||||
}else{
|
||||
console.log("replaceRenderer failed.")
|
||||
if (toDict.length==0){
|
||||
console.log("warring in initMainLabelDict, toDict is Empty.")
|
||||
}
|
||||
return toDict
|
||||
}
|
||||
|
||||
export function markTextAsarTranslate(langRootPath:string, toLang:string, mainJsFileName:string, outMainJsFileName:string, rendererJsFileName:string, outRendererJsFileName:string): boolean {
|
||||
|
||||
const toDict = initMainLabelDict(mainJsFileName, langRootPath, toLang)
|
||||
|
||||
if (toDict.length>0){
|
||||
if (replaceMainLabelDict(mainJsFileName, langRootPath, toDict, toLang, outMainJsFileName)){
|
||||
console.log("replaceMainLabelDict success.")
|
||||
}else{
|
||||
console.log("replaceMainLabelDict failed.")
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
if (replaceMain(mainJsFileName, langRootPath, toLang, outMainJsFileName)){
|
||||
console.log("replaceMain success.")
|
||||
}else{
|
||||
console.log("replaceMain failed.")
|
||||
return false
|
||||
}
|
||||
|
||||
if (replaceRenderer(rendererJsFileName, langRootPath, toLang, outRendererJsFileName)){
|
||||
console.log("replaceRenderer success.")
|
||||
}else{
|
||||
console.log("replaceRenderer failed.")
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
@ -1,121 +0,0 @@
|
||||
&Edit
|
||||
Undo
|
||||
Redo
|
||||
Cut
|
||||
Copy
|
||||
Paste
|
||||
Copy as Markdown
|
||||
Copy as HTML
|
||||
Paste as Plain Text
|
||||
Select All
|
||||
Duplicate
|
||||
Create Paragraph
|
||||
Delete Paragraph
|
||||
Find
|
||||
Find Next
|
||||
Find Previous
|
||||
Replace
|
||||
Find in Folder
|
||||
Screenshot
|
||||
Line Ending
|
||||
Carriage return and line feed (CRLF)
|
||||
Line feed (LF)
|
||||
Edit
|
||||
&File
|
||||
New Tab
|
||||
New Window
|
||||
Open File...
|
||||
Open Folder...
|
||||
Open Recent
|
||||
Clear Recently Used
|
||||
Save
|
||||
Save As...
|
||||
Auto Save
|
||||
Move To...
|
||||
Rename...
|
||||
Import...
|
||||
Export
|
||||
HTML
|
||||
PDF
|
||||
Print
|
||||
Preferences...
|
||||
Close Tab
|
||||
Close Window
|
||||
Quit
|
||||
&Help
|
||||
Quick Start...
|
||||
Markdown Reference...
|
||||
Changelog...
|
||||
Donate via Open Collective...
|
||||
Feedback via Twitter...
|
||||
Report Issue or Request Feature...
|
||||
Website...
|
||||
Watch on GitHub...
|
||||
Follow us on Github...
|
||||
Follow us on Twitter...
|
||||
License...
|
||||
Check for updates...
|
||||
About MarkText...
|
||||
MarkText
|
||||
About MarkText
|
||||
Preferences
|
||||
Services
|
||||
Hide MarkText
|
||||
Hide Others
|
||||
Show All
|
||||
Quit MarkText
|
||||
&View
|
||||
Command Palette...
|
||||
Source Code Mode
|
||||
Typewriter Mode
|
||||
Focus Mode
|
||||
Show Sidebar
|
||||
Show Tab Bar
|
||||
Toggle Table of Contents
|
||||
Reload Images
|
||||
Show Developer Tools
|
||||
Reload window
|
||||
&Window
|
||||
Minimize
|
||||
Always on Top
|
||||
Zoom In
|
||||
Zoom Out
|
||||
Show in Full Screen
|
||||
Bring All to Front
|
||||
&Paragraph
|
||||
Heading 1
|
||||
Heading 2
|
||||
Heading 3
|
||||
Heading 4
|
||||
Heading 5
|
||||
Heading 6
|
||||
Promote Heading
|
||||
Demote Heading
|
||||
Table
|
||||
Code Fences
|
||||
Quote Block
|
||||
Math Block
|
||||
Html Block
|
||||
Ordered List
|
||||
Bullet List
|
||||
Task List
|
||||
Loose List Item
|
||||
Paragraph
|
||||
Horizontal Rule
|
||||
Front Matter
|
||||
F&ormat
|
||||
Bold
|
||||
Italic
|
||||
Underline
|
||||
Superscript
|
||||
Subscript
|
||||
Highlight
|
||||
Inline Code
|
||||
Inline Math
|
||||
Strikethrough
|
||||
Hyperlink
|
||||
Image
|
||||
Clear Formatting
|
||||
&Theme
|
||||
Open...
|
||||
Clear Recent
|
@ -1,121 +1,9 @@
|
||||
编辑
|
||||
撤销
|
||||
重做
|
||||
剪切
|
||||
复制
|
||||
粘贴
|
||||
复制为 Markdown
|
||||
复制为 HTML
|
||||
粘贴为纯文本
|
||||
全选
|
||||
复写到新段落
|
||||
新建段落
|
||||
删除段落
|
||||
查找
|
||||
查找下一个
|
||||
查找上一个
|
||||
替换
|
||||
在文件夹中查找
|
||||
截屏
|
||||
行结束符号
|
||||
回车换行 (CRLF)
|
||||
换行 (LF)
|
||||
编辑
|
||||
文件
|
||||
新建标签页
|
||||
新建窗口
|
||||
打开文件...
|
||||
打开文件夹...
|
||||
最近使用的文件
|
||||
清空最近文件列表
|
||||
保存
|
||||
另存为...
|
||||
自动保存
|
||||
移动到...
|
||||
重命名...
|
||||
导入...
|
||||
导出
|
||||
HTML
|
||||
PDF
|
||||
打印
|
||||
偏好设置...
|
||||
关闭标签页
|
||||
关闭窗口
|
||||
退出
|
||||
帮助
|
||||
快速入门...
|
||||
Markdown 参考指南...
|
||||
更新日志...
|
||||
通过 Open Collective 捐助我们...
|
||||
在 Twitter 上和我们反馈...
|
||||
反馈问题或功能建议...
|
||||
访问官网...
|
||||
在 GitHub 关注 MarkText...
|
||||
在 Github 上关注我们...
|
||||
在 Twitter 上关注我们...
|
||||
许可协议...
|
||||
检查更新...
|
||||
关于 MarkText...
|
||||
MarkText
|
||||
关于 MarkText
|
||||
偏好设置
|
||||
服务
|
||||
隐藏 MarkText
|
||||
隐藏其它
|
||||
显示全部
|
||||
退出 MarkText
|
||||
视图
|
||||
命令面板...
|
||||
源代码模式
|
||||
打字机模式
|
||||
专注模式
|
||||
显示侧边栏
|
||||
显示标签栏
|
||||
显示/隐藏目录
|
||||
重新加载图像
|
||||
显示开发者工具
|
||||
重新加载窗口
|
||||
窗口
|
||||
最小化
|
||||
总在最前面
|
||||
放大
|
||||
缩小
|
||||
全屏显示
|
||||
前置全部窗口
|
||||
段落
|
||||
标题 1
|
||||
标题 2
|
||||
标题 3
|
||||
标题 4
|
||||
标题 5
|
||||
标题 6
|
||||
提升标题级别
|
||||
降低标题级别
|
||||
表格
|
||||
代码块
|
||||
引用块
|
||||
数学公式块
|
||||
Html块
|
||||
有序列表
|
||||
无序列表
|
||||
任务列表
|
||||
松散列表项
|
||||
段落
|
||||
水平线
|
||||
前文(Front Matter)
|
||||
格式
|
||||
粗体
|
||||
斜体
|
||||
下划线
|
||||
上标
|
||||
下标
|
||||
高亮
|
||||
行内代码
|
||||
行内数学公式
|
||||
删除线
|
||||
超链接
|
||||
图片
|
||||
清除格式
|
||||
主题
|
||||
打开...
|
||||
清空最近文件列表
|
||||
role:"recentdocuments"|label:"最近使用的文件",role:"recentdocuments"
|
||||
role:"clearrecentdocuments"|label:"清空最近文件列表",role:"clearrecentdocuments"
|
||||
"Save","Cancel","Don't save"|"保存","取消","不保存"
|
||||
Do you want to save the changes you made to ${t.length} ${1===t.length?"file":"files"}?|是否要保存对${t.length}个文件所做的更改?
|
||||
Your changes will be lost if you don't save them.|如果您不保存更改,您的更改将会丢失。
|
||||
title:"Exported successfully"|title:"导出成功"
|
||||
message:`Exported "${ne().basename(i)}" successfully!`|message:`导出 "${ne().basename(i)}" 成功!`
|
||||
title:"Import Warning"|title:"导入警告"
|
||||
message:"Install pandoc before you want to import files."|message:"在导入文件之前先安装 pandoc。"
|
||||
|
121
translate-resources/main_label_dict_zh-cn.txt
Normal file
121
translate-resources/main_label_dict_zh-cn.txt
Normal file
@ -0,0 +1,121 @@
|
||||
&Edit|编辑
|
||||
Undo|撤销
|
||||
Redo|重做
|
||||
Cut|剪切
|
||||
Copy|复制
|
||||
Paste|粘贴
|
||||
Copy as Markdown|复制为 Markdown
|
||||
Copy as HTML|复制为 HTML
|
||||
Paste as Plain Text|粘贴为纯文本
|
||||
Select All|全选
|
||||
Duplicate|复写到新段落
|
||||
Create Paragraph|新建段落
|
||||
Delete Paragraph|删除段落
|
||||
Find|查找
|
||||
Find Next|查找下一个
|
||||
Find Previous|查找上一个
|
||||
Replace|替换
|
||||
Find in Folder|在文件夹中查找
|
||||
Screenshot|截屏
|
||||
Line Ending|行结束符号
|
||||
Carriage return and line feed (CRLF)|回车换行 (CRLF)
|
||||
Line feed (LF)|换行 (LF)
|
||||
Edit|编辑
|
||||
&File|文件
|
||||
New Tab|新建标签页
|
||||
New Window|新建窗口
|
||||
Open File...|打开文件...
|
||||
Open Folder...|打开文件夹...
|
||||
Open Recent|最近使用的文件
|
||||
Clear Recently Used|清空最近文件列表
|
||||
Save|保存
|
||||
Save As...|另存为...
|
||||
Auto Save|自动保存
|
||||
Move To...|移动到...
|
||||
Rename...|重命名...
|
||||
Import...|导入...
|
||||
Export|导出
|
||||
HTML|HTML
|
||||
PDF|PDF
|
||||
Print|打印
|
||||
Preferences...|偏好设置...
|
||||
Close Tab|关闭标签页
|
||||
Close Window|关闭窗口
|
||||
Quit|退出
|
||||
&Help|帮助
|
||||
Quick Start...|快速入门...
|
||||
Markdown Reference...|Markdown 参考指南...
|
||||
Changelog...|更新日志...
|
||||
Donate via Open Collective...|通过 Open Collective 捐助我们...
|
||||
Feedback via Twitter...|在 Twitter 上和我们反馈...
|
||||
Report Issue or Request Feature...|反馈问题或功能建议...
|
||||
Website...|访问官网...
|
||||
Watch on GitHub...|在 GitHub 关注 MarkText...
|
||||
Follow us on Github...|在 Github 上关注我们...
|
||||
Follow us on Twitter...|在 Twitter 上关注我们...
|
||||
License...|许可协议...
|
||||
Check for updates...|检查更新...
|
||||
About MarkText...|关于 MarkText...
|
||||
MarkText|MarkText
|
||||
About MarkText|关于 MarkText
|
||||
Preferences|偏好设置
|
||||
Services|服务
|
||||
Hide MarkText|隐藏 MarkText
|
||||
Hide Others|隐藏其它
|
||||
Show All|显示全部
|
||||
Quit MarkText|退出 MarkText
|
||||
&View|视图
|
||||
Command Palette...|命令面板...
|
||||
Source Code Mode|源代码模式
|
||||
Typewriter Mode|打字机模式
|
||||
Focus Mode|专注模式
|
||||
Show Sidebar|显示侧边栏
|
||||
Show Tab Bar|显示标签栏
|
||||
Toggle Table of Contents|显示/隐藏目录
|
||||
Reload Images|重新加载图像
|
||||
Show Developer Tools|显示开发者工具
|
||||
Reload window|重新加载窗口
|
||||
&Window|窗口
|
||||
Minimize|最小化
|
||||
Always on Top|总在最前面
|
||||
Zoom In|放大
|
||||
Zoom Out|缩小
|
||||
Show in Full Screen|全屏显示
|
||||
Bring All to Front|前置全部窗口
|
||||
&Paragraph|段落
|
||||
Heading 1|标题 1
|
||||
Heading 2|标题 2
|
||||
Heading 3|标题 3
|
||||
Heading 4|标题 4
|
||||
Heading 5|标题 5
|
||||
Heading 6|标题 6
|
||||
Promote Heading|提升标题级别
|
||||
Demote Heading|降低标题级别
|
||||
Table|表格
|
||||
Code Fences|代码块
|
||||
Quote Block|引用块
|
||||
Math Block|数学公式块
|
||||
Html Block|Html块
|
||||
Ordered List|有序列表
|
||||
Bullet List|无序列表
|
||||
Task List|任务列表
|
||||
Loose List Item|松散列表项
|
||||
Paragraph|段落
|
||||
Horizontal Rule|水平线
|
||||
Front Matter|前文(Front Matter)
|
||||
F&ormat|格式
|
||||
Bold|粗体
|
||||
Italic|斜体
|
||||
Underline|下划线
|
||||
Superscript|上标
|
||||
Subscript|下标
|
||||
Highlight|高亮
|
||||
Inline Code|行内代码
|
||||
Inline Math|行内数学公式
|
||||
Strikethrough|删除线
|
||||
Hyperlink|超链接
|
||||
Image|图片
|
||||
Clear Formatting|清除格式
|
||||
&Theme|主题
|
||||
Open...|打开...
|
||||
Clear Recent|清空最近文件列表
|
Loading…
Reference in New Issue
Block a user