Skip to main content

一个集成国内外翻译服务的第三方库,方便开发者快速集成翻译功能

Project description

translatehub

没有任何依赖的翻译库,API 统一简单易用,适合快速集成翻译功能而不想引入庞大的依赖库。

  • 简单易用
  • 支持多种翻译服务
  • 没有任何依赖(连 requests 都没有)
  • 屏蔽各大翻译api语言代码,内置了常用语言的映射
  • 支持多种秘钥传入方式,无需每次都输入(直接传入,本地存储,环境变量)
  • 完整的单元测试

目前支持的国内翻译服务(均为有免费额度):

  • 百度翻译
  • 有道翻译
  • 腾讯翻译
  • 阿里翻译

目前支持的国外翻译服务:

  • deepl翻译
  • 支持谷歌翻译

Installation 安装说明

pip install translatehub

QuickStart 快速开始

只需要定义一个翻译器对象,传入秘钥,然后调用 translate 方法即可。

同时支持直接传入,本地存储秘钥以及从环境变量获取秘钥

from translatehub import BaiduAPI

translator = BaiduAPI('your appid', 'secret_key')
result = translator.translate('hello')

print(result)  # 你好

自定义翻译语言,使用 Languages 枚举类来实现屏蔽各大翻译api语言代码

from translatehub import GoogleApi, Languages

# 谷歌无需传入秘钥
translator = GoogleApi()

# 自动检测后翻译成中文
print(translator.translate("hello", Languages.AUTO, Languages.CHINESE))  # 你好

# 手动说明语言,然后翻译成日文
print(translator.translate("hello", Languages.ENGLISH, Languages.Japanese))  # こんにちは

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

translation_hub-0.1.0.tar.gz (20.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

translation_hub-0.1.0-py3-none-any.whl (26.7 kB view details)

Uploaded Python 3

File details

Details for the file translation_hub-0.1.0.tar.gz.

File metadata

  • Download URL: translation_hub-0.1.0.tar.gz
  • Upload date:
  • Size: 20.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.2

File hashes

Hashes for translation_hub-0.1.0.tar.gz
Algorithm Hash digest
SHA256 93adc6120ea0b3162715e646a8cb6713e71a9bb6df4a7bc921ba98c7db8cbc04
MD5 f9674ea08e1c3188c4f643ffde55b8fa
BLAKE2b-256 788e3b42e7832b519799b4494a0ddb8260ecce34c850d18f5983ce347658eb8b

See more details on using hashes here.

File details

Details for the file translation_hub-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for translation_hub-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f84c52b29c7ac5583cfd08b95f79e13aaba5c01563df57d49eb9626b66d875d0
MD5 1b9071f3717962e80efd0a1590351b72
BLAKE2b-256 ec187119b1ca7778aee5a583a3e967b4b435b5685d42826984651989b681a25b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page