增加translate_bytes 方法
This commit is contained in:
88
.idea/workspace.xml
generated
88
.idea/workspace.xml
generated
@@ -6,7 +6,8 @@
|
|||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="6b18b44a-df57-4212-a857-9e291ebe5dd2" name="更改" comment="">
|
<list default="true" id="6b18b44a-df57-4212-a857-9e291ebe5dd2" name="更改" comment="">
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/uv.lock" beforeDir="false" afterPath="$PROJECT_DIR$/uv.lock" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/docutranslate/translater.py" beforeDir="false" afterPath="$PROJECT_DIR$/docutranslate/translater.py" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/pyproject.toml" beforeDir="false" afterPath="$PROJECT_DIR$/pyproject.toml" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
@@ -32,47 +33,47 @@
|
|||||||
<option name="hideEmptyMiddlePackages" value="true" />
|
<option name="hideEmptyMiddlePackages" value="true" />
|
||||||
<option name="showLibraryContents" value="true" />
|
<option name="showLibraryContents" value="true" />
|
||||||
</component>
|
</component>
|
||||||
<component name="PropertiesComponent"><![CDATA[{
|
<component name="PropertiesComponent">{
|
||||||
"keyToString": {
|
"keyToString": {
|
||||||
"DefaultHtmlFileTemplate": "HTML File",
|
"DefaultHtmlFileTemplate": "HTML File",
|
||||||
"JavaScript 调试.output.html (1).executor": "Run",
|
"JavaScript 调试.output.html (1).executor": "Run",
|
||||||
"JavaScript 调试.output.html.executor": "Run",
|
"JavaScript 调试.output.html.executor": "Run",
|
||||||
"JavaScript 调试.regex_中文.html.executor": "Run",
|
"JavaScript 调试.regex_中文.html.executor": "Run",
|
||||||
"JavaScript 调试.test2.html.executor": "Run",
|
"JavaScript 调试.test2.html.executor": "Run",
|
||||||
"JavaScript 调试.test2_英文.html.executor": "Run",
|
"JavaScript 调试.test2_英文.html.executor": "Run",
|
||||||
"JavaScript 调试.test4-1_中文.html.executor": "Run",
|
"JavaScript 调试.test4-1_中文.html.executor": "Run",
|
||||||
"JavaScript 调试.互联网认证授权机制.html.executor": "Run",
|
"JavaScript 调试.互联网认证授权机制.html.executor": "Run",
|
||||||
"JavaScript 调试.互联网认证授权机制_英文.html.executor": "Run",
|
"JavaScript 调试.互联网认证授权机制_英文.html.executor": "Run",
|
||||||
"JavaScript 调试.毕业论文_英文.html.executor": "Run",
|
"JavaScript 调试.毕业论文_英文.html.executor": "Run",
|
||||||
"ModuleVcsDetector.initialDetectionPerformed": "true",
|
"ModuleVcsDetector.initialDetectionPerformed": "true",
|
||||||
"Python 测试.Python 测试 (markdown_mask.py 内).executor": "Run",
|
"Python 测试.Python 测试 (markdown_mask.py 内).executor": "Run",
|
||||||
"Python 测试.markdown_mask.Test.test_basic_link_masking 的 Python 测试.executor": "Run",
|
"Python 测试.markdown_mask.Test.test_basic_link_masking 的 Python 测试.executor": "Run",
|
||||||
"Python.PDFtranslater (1).executor": "Run",
|
"Python.PDFtranslater (1).executor": "Run",
|
||||||
"Python.PDFtranslater (2).executor": "Run",
|
"Python.PDFtranslater (2).executor": "Run",
|
||||||
"Python.agent.executor": "Debug",
|
"Python.agent.executor": "Debug",
|
||||||
"Python.agent_utils.executor": "Run",
|
"Python.agent_utils.executor": "Run",
|
||||||
"Python.convert.executor": "Run",
|
"Python.convert.executor": "Run",
|
||||||
"Python.markdown_splitter.executor": "Debug",
|
"Python.markdown_splitter.executor": "Debug",
|
||||||
"Python.markdown_utils.executor": "Run",
|
"Python.markdown_utils.executor": "Run",
|
||||||
"Python.test.executor": "Run",
|
"Python.test.executor": "Run",
|
||||||
"Python.test1.executor": "Run",
|
"Python.test1.executor": "Run",
|
||||||
"Python.test2.executor": "Run",
|
"Python.test2.executor": "Run",
|
||||||
"Python.test3.executor": "Run",
|
"Python.test3.executor": "Run",
|
||||||
"Python.test4.executor": "Run",
|
"Python.test4.executor": "Run",
|
||||||
"Python.translater.executor": "Run",
|
"Python.translater.executor": "Run",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"RunOnceActivity.git.unshallow": "true",
|
"RunOnceActivity.git.unshallow": "true",
|
||||||
"git-widget-placeholder": "main",
|
"git-widget-placeholder": "main",
|
||||||
"last_opened_file_path": "C:/Users/jxgm/Desktop/FileTranslate/tests",
|
"last_opened_file_path": "C:/Users/jxgm/Desktop/FileTranslate/tests",
|
||||||
"node.js.detected.package.eslint": "true",
|
"node.js.detected.package.eslint": "true",
|
||||||
"node.js.detected.package.tslint": "true",
|
"node.js.detected.package.tslint": "true",
|
||||||
"node.js.selected.package.eslint": "(autodetect)",
|
"node.js.selected.package.eslint": "(autodetect)",
|
||||||
"node.js.selected.package.tslint": "(autodetect)",
|
"node.js.selected.package.tslint": "(autodetect)",
|
||||||
"nodejs_package_manager_path": "npm",
|
"nodejs_package_manager_path": "npm",
|
||||||
"settings.editor.selected.configurable": "preferences.general",
|
"settings.editor.selected.configurable": "preferences.general",
|
||||||
"vue.rearranger.settings.migration": "true"
|
"vue.rearranger.settings.migration": "true"
|
||||||
}
|
}
|
||||||
}]]></component>
|
}</component>
|
||||||
<component name="RecentsManager">
|
<component name="RecentsManager">
|
||||||
<key name="CopyFile.RECENT_KEYS">
|
<key name="CopyFile.RECENT_KEYS">
|
||||||
<recent name="C:\Users\jxgm\Desktop\FileTranslate\tests" />
|
<recent name="C:\Users\jxgm\Desktop\FileTranslate\tests" />
|
||||||
@@ -383,7 +384,10 @@
|
|||||||
<workItem from="1746851812490" duration="334000" />
|
<workItem from="1746851812490" duration="334000" />
|
||||||
<workItem from="1746864516470" duration="2291000" />
|
<workItem from="1746864516470" duration="2291000" />
|
||||||
<workItem from="1746877808294" duration="1364000" />
|
<workItem from="1746877808294" duration="1364000" />
|
||||||
<workItem from="1746882518324" duration="4599000" />
|
<workItem from="1746882518324" duration="4691000" />
|
||||||
|
<workItem from="1746887311759" duration="14000" />
|
||||||
|
<workItem from="1746894355924" duration="651000" />
|
||||||
|
<workItem from="1746923054682" duration="383000" />
|
||||||
</task>
|
</task>
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ class FileTranslater:
|
|||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def read(self, name: str, file: bytes, formula=False, code=False, save=False,
|
def read_bytes(self, name: str, file: bytes, formula=False, code=False, save=False,
|
||||||
save_format: Literal["markdown", "html"] = "markdown", refine=False,
|
save_format: Literal["markdown", "html"] = "markdown", refine=False,
|
||||||
refine_agent: Agent | None = None):
|
refine_agent: Agent | None = None):
|
||||||
ds = DocumentStream(name=name, stream=BytesIO(file))
|
ds = DocumentStream(name=name, stream=BytesIO(file))
|
||||||
@@ -262,3 +262,19 @@ class FileTranslater:
|
|||||||
filename = f"{file_path.stem}_{to_lang}.html"
|
filename = f"{file_path.stem}_{to_lang}.html"
|
||||||
self.save_as_html(filename=filename, output_dir=output_dir)
|
self.save_as_html(filename=filename, output_dir=output_dir)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
def translate_bytes(self, name:str,file: bytes, to_lang="中文", output_dir="./output",
|
||||||
|
formula=False,
|
||||||
|
code=False, output_format: Literal["markdown", "html"] = "markdown", refine=False,
|
||||||
|
refine_agent: Agent | None = None, translate_agent: Agent | None = None):
|
||||||
|
self.read_bytes(name=name,file=file, formula=formula, code=code)
|
||||||
|
if refine:
|
||||||
|
self.refine_markdown_by_agent(refine_agent)
|
||||||
|
self.translate_markdown_by_agent(translate_agent, to_lang=to_lang)
|
||||||
|
if output_format == "markdown":
|
||||||
|
filename = f"{name}_{to_lang}.md"
|
||||||
|
self.save_as_markdown(filename=filename, output_dir=output_dir)
|
||||||
|
elif output_format == "html":
|
||||||
|
filename = f"{name}_{to_lang}.html"
|
||||||
|
self.save_as_html(filename=filename, output_dir=output_dir)
|
||||||
|
return self
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "docutranslate"
|
name = "docutranslate"
|
||||||
version = "0.1.6"
|
version = "0.1.7.dev"
|
||||||
description = "文件翻译工具"
|
description = "文件翻译工具"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.10"
|
requires-python = ">=3.10"
|
||||||
|
|||||||
Reference in New Issue
Block a user