A professional translation toolkit based on Doubao API
Project description
DoubaoTranslator | 豆包翻译器
🌍 English
DoubaoTranslator is a professional translation toolkit based on Doubao API, providing features such as multilingual translation, glossary management, context-aware translation, and style customization.
Features
- Multilingual Support: Translation between 17 mainstream languages
- Context-Aware Translation: Maintains semantic coherence with context window
- Glossary Management: Custom terminology mapping for professional accuracy
- Style Templates: Predefined styles (formal, casual, technical, creative)
- Streaming Translation: Real-time translation with partial results
- Batch Processing: Efficient bulk translation with concurrency control
- Enhanced Language Detection: Combined results from multiple detectors
- Performance Optimization: Caching, retry mechanisms, HTTP/2 support
- Document Translation: Context-aware translation for long documents
- Translation Evaluation: Quality assessment functionality
- Async Support: Complete async operation support, including context managers
Installation
pip install doubaotrans
Quick Start
from doubaotrans import DoubaoTranslator
# Initialize translator
translator = DoubaoTranslator(api_key="your_api_key")
# Basic translation
result = await translator.doubao_translate("Hello, World!", dest="zh")
print(result.text) # 你好,世界!
# Batch translation
texts = ["Hello", "World", "AI"]
results = await translator.translate_batch(texts, dest="zh")
for result in results:
print(f"{result.origin} -> {result.text}")
# Context-aware translation
context = "This article discusses the history of Apple Inc."
text = "Apple released an innovative product."
result = await translator.translate_with_context(
text=text,
context=context,
dest="zh"
)
print(result.text) # Will translate "Apple" as the company, not the fruit
For detailed documentation and examples, please visit our GitHub repository.
🌏 中文
DoubaoTranslator 是一个基于豆包 API 的专业翻译工具包,提供多语言翻译、术语表管理、上下文感知翻译和风格定制等功能。
功能特点
- 多语言支持:支持 17 种主流语言之间的互译
- 上下文感知:使用上下文窗口维持语义连贯性
- 术语管理:自定义术语映射,确保专业准确性
- 风格模板:预定义风格(正式、随意、技术、创意)
- 流式翻译:实时翻译并返回部分结果
- 批量处理:高效的批量翻译与并发控制
- 增强语言检测:结合多个检测器提高准确率
- 性能优化:缓存、重试机制、HTTP/2 支持
- 文档翻译:支持长文档的上下文感知翻译
- 翻译评估:提供翻译质量评估功能
- 异步支持:完整的异步操作支持,包括上下文管理器
安装
pip install doubaotrans
快速开始
from doubaotrans import DoubaoTranslator
# 初始化翻译器
translator = DoubaoTranslator(api_key="your_api_key")
# 基本翻译
result = await translator.doubao_translate("你好,世界!", dest="en")
print(result.text) # Hello, World!
# 批量翻译
texts = ["你好", "世界", "人工智能"]
results = await translator.translate_batch(texts, dest="en")
for result in results:
print(f"{result.origin} -> {result.text}")
# 上下文感知翻译
context = "这篇文章讨论了苹果公司的发展历程。"
text = "苹果推出了革新性的产品。"
result = await translator.translate_with_context(
text=text,
context=context,
dest="en"
)
print(result.text) # 会将"苹果"翻译为公司而不是水果
详细文档和示例请访问我们的 GitHub 仓库。
📝 Notes | 注意事项
English
-
API Limitations
- Maximum text length per request: 5000 characters
- API rate limiting may apply
- Async methods recommended for handling large volumes
-
Performance Optimization
- HTTP/2 support requires the
hyperpackage - Caching mechanism reduces duplicate requests
- Batch processing improves efficiency
- HTTP/2 support requires the
中文
-
API 限制
- 每次请求的最大文本长度:5000 字符
- 可能受 API 速率限制
- 建议使用异步方法处理大量请求
-
性能优化
- 使用 HTTP/2 需要安装
hyper包 - 缓存机制可以减少重复请求
- 批量处理可以提高效率
- 使用 HTTP/2 需要安装
📄 License | 许可证
This project is licensed under the MIT License - see the LICENSE file for details.
本项目采用 MIT 许可证 - 查看 LICENSE 文件了解详情。
🙏 Acknowledgments | 致谢
- Thanks to all contributors
- 感谢所有贡献者
📧 Contact | 联系方式
- Author | 作者: kilon
- Email | 邮箱: a15607467772@163.com
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file doubaotrans-1.2.2.1.tar.gz.
File metadata
- Download URL: doubaotrans-1.2.2.1.tar.gz
- Upload date:
- Size: 27.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
be117f0e3815f7d90588f15abb65b335cd893cb2a346c65d111bca80773d08cd
|
|
| MD5 |
8323183ce909bf64c16b42e0a360279d
|
|
| BLAKE2b-256 |
d9bf3c9ac6473dc14a36b447a50bb5a6dc40a75f3c00b60bc1cbfbd510eeb833
|
File details
Details for the file doubaotrans-1.2.2.1-py2.py3-none-any.whl.
File metadata
- Download URL: doubaotrans-1.2.2.1-py2.py3-none-any.whl
- Upload date:
- Size: 21.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fe385f65c260cadb4360b860335eee3dfe20bbdda824deacea61d7a542209e4a
|
|
| MD5 |
3337aff6d2f8505abc35dc0576ce887a
|
|
| BLAKE2b-256 |
3a1ff467eb4ce8fd442cb9751608147547844de8bfbafe7a694ec21afdb02f8e
|