diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 53400b0..059c3c9 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -6,7 +6,8 @@ - + + - { + "keyToString": { + "DefaultHtmlFileTemplate": "HTML File", + "JavaScript 调试.output.html (1).executor": "Run", + "JavaScript 调试.output.html.executor": "Run", + "JavaScript 调试.regex_中文.html.executor": "Run", + "JavaScript 调试.test2.html.executor": "Run", + "JavaScript 调试.test2_英文.html.executor": "Run", + "JavaScript 调试.test4-1_中文.html.executor": "Run", + "JavaScript 调试.互联网认证授权机制.html.executor": "Run", + "JavaScript 调试.互联网认证授权机制_英文.html.executor": "Run", + "JavaScript 调试.毕业论文_英文.html.executor": "Run", + "ModuleVcsDetector.initialDetectionPerformed": "true", + "Python 测试.Python 测试 (markdown_mask.py 内).executor": "Run", + "Python 测试.markdown_mask.Test.test_basic_link_masking 的 Python 测试.executor": "Run", + "Python.PDFtranslater (1).executor": "Run", + "Python.PDFtranslater (2).executor": "Run", + "Python.agent.executor": "Debug", + "Python.agent_utils.executor": "Run", + "Python.convert.executor": "Run", + "Python.markdown_splitter.executor": "Debug", + "Python.markdown_utils.executor": "Run", + "Python.test.executor": "Run", + "Python.test1.executor": "Run", + "Python.test2.executor": "Run", + "Python.test3.executor": "Run", + "Python.test4.executor": "Run", + "Python.translater.executor": "Run", + "RunOnceActivity.ShowReadmeOnStart": "true", + "RunOnceActivity.git.unshallow": "true", + "git-widget-placeholder": "main", + "last_opened_file_path": "C:/Users/jxgm/Desktop/FileTranslate/tests", + "node.js.detected.package.eslint": "true", + "node.js.detected.package.tslint": "true", + "node.js.selected.package.eslint": "(autodetect)", + "node.js.selected.package.tslint": "(autodetect)", + "nodejs_package_manager_path": "npm", + "settings.editor.selected.configurable": "preferences.general", + "vue.rearranger.settings.migration": "true" } -}]]> +} @@ -383,7 +384,10 @@ - + + + + diff --git a/docutranslate/translater.py b/docutranslate/translater.py index 61e05d3..0b64983 100644 --- a/docutranslate/translater.py +++ b/docutranslate/translater.py @@ -72,7 +72,7 @@ class FileTranslater: } 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, refine_agent: Agent | None = None): ds = DocumentStream(name=name, stream=BytesIO(file)) @@ -262,3 +262,19 @@ class FileTranslater: filename = f"{file_path.stem}_{to_lang}.html" self.save_as_html(filename=filename, output_dir=output_dir) 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 diff --git a/pyproject.toml b/pyproject.toml index 8a6ab68..8ddf0d9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "docutranslate" -version = "0.1.6" +version = "0.1.7.dev" description = "文件翻译工具" readme = "README.md" requires-python = ">=3.10"