同时从CLI、GUI(GNU/Linux、Android、macOS和Windows)、REPL、Python、shell和Vim中通过google、bing、有道智云、哈词、stardict、openai、本地机器的大语言模型等翻译文本。
项目描述
translate-shell
通过
- 在线翻译器
- bing
- youdaozhiyun
- haici
- 离线词典
- stardict
- LLM
- OpenAI
- llama: 使用您的本地模型
支持
- CLI
- GUI
- GNU/Linux
- Android
- macOS
- Windows
- REPL
- 脚本
- python
- shell
- vim: 弃用: vim端口将被语言服务器取代
- 语言服务器
- CI/CD
- github action
使用方法
UI
CLI
trans --translators=google,bing,haici,stardict crush
REPL
$ trans # enter REPL
> en:ja # change source language to english and target language to japanese
> : # swap source and target languages
> =stardict # use stardict to translate text
> !cat example/test.txt # execute a shell command
ハッカー
> <example/test.txt # translate a file
hacker
> 画家 # translate text
painter; artist
> ! # enter shell
$ echo $SHELL # execute a shell command
/usr/bin/zsh
$ exit # exit shell
>
TUI
Vim
Translate --translators=google,bing Free as in Freedom
GUI
GNU/Linux
Android
脚本
Python
>>> from translate_shell.translate import translate
>>> translate("The Mythical Man-Month", "zh_TW")
... Translations(
... status=1,
... results=[
... Translation(
... translator="google",
... sl="auto",
... tl="zh_TW",
... text="The Mythical Man-Month",
... phonetic="",
... paraphrase="神話般的人月",
... explains={},
... details={},
... alternatives=["神話般的月"]
... )
... ],
... text="The Mythical Man-Month",
... to_lang="zh_TW",
... from_lang="auto",
... )
Shell脚本
$ xsel -o | trans --format json | jq -r '"《\(.results[].paraphrase)》的英文是 \(.text)."'
《大教堂和集市》的英文是 the cathedral and the bazaar.
Vim脚本
:let g:text = 'Just for Fun'
:let g:translation = json_decode(translate_shell#call('--format=json', g:text))
:echo g:text 'is' g:translation.results[0].paraphrase 'in Chinese.'
Just for Fun is 纯娱乐 in Chinese.
语言服务器
- 文档悬停:显示翻译结果
- 补全:补全翻译词
CI/CD
Github Action
本仓库提供了一个动作,用于翻译存储库中的*.po
文件。请参阅输入示例。例如,您有一个包含其他项目文档翻译(上游)的存储库,您可以编写一个GitHub工作流来检测上游是否有更新。如果存在新版本,则更新版本并生成新的.po
文件,然后翻译更改的.po
文件并git commit
。
示例
on:
schedule:
# Run this CI/CD at 0:00 on Friday
- cron: 0 0 * * 5
workflow_dispatch:
jobs:
translate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Generate new .po
id: version
run: |
# update version
# then use perl / sed / ... to replace the version string of your file
# then generate new .po
echo VERSION=XXX > $GITHUB_OUTPUT
- name: Translate your *.po
uses: Freed-Wu/translate-shell@main
- name: Git commit
run: |
git add **.po
git config --global user.name 'Github Actions'
git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com'
git commit -m ":bookmark: Dump version to $VERSION"
git tag "$VERSION"
git remote set-url origin "https://x-access-token:$GH_TOKEN@github.com/$GITHUB_REPOSITORY"
git push
git push --tags
env:
VERSION: ${{steps.version.outputs.VERSION}}
GH_TOKEN: ${{secrets.GH_TOKEN}}
您可以使用以下命令获取新版本:
# get a github repo's version:
curl https://api.github.com/repos/user/repo/releases/latest | jq -r .tag_name
# get a gitlab repo's version
curl 'https://gitlab.com/api/v4/projects/41218592/repository/tags?per_page=1' |
jq -r '.[].name'
您可以使用以下工具生成新的.po
文件:
- sphinx-intl:为任何使用sphinx生成文档的项目生成
.po
。 - po4a:为任何使用markdown、
LaTeX
、man等编写文档的项目生成.po
。
类似项目
请参阅比较。
功能
- 同时使用不同的翻译器进行翻译,如translator。
- 自动翻译剪贴板内容,如ydcv。
- 朗读单词的发音。
- 支持在线翻译引擎。
- 支持离线词典。
- 多种使用方法,从shell、python和vim。
- 魔法文本,如
en:
更改源语言,:zh_CN
更改目标语言,<file
翻译文件等。 - 允许通过
config.py
进行自定义。 - 良好的shell自动补全,特别是对于zsh,完成选项和翻译历史。
- 手册页:
man trans
- 美丽的UI
- 跨平台
- 丰富的API,可以轻松从shell和python调用。
- 良好的文档
- 单元测试,保持代码质量
- CI/CD
- 干净代码
- 尊重PEP484
- 尊重PEP621
- 尊重XDG
最后但同样重要的是:它是一个自由软件。
请参阅文档了解更多信息。
PS:欢迎提交PR!请确保代码整洁并保持测试通过!
关闭
translate-shell-0.0.51.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 0aba9c7f2507d44bda81fa1150430e768b0ae779e7428e7a47afe1c97f9e7bba |
|
MD5 | 439bd4f85bdea2957feba09cee4567a9 |
|
BLAKE2b-256 | 8adb3d2ee4595864846145241662372c0aa82c835946e122df83a72a60a517db |
关闭
translate_shell-0.0.51-py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 3af99e796fc1698e909313fcae258d8080e2983d7dae1b37a8c8333c8383e5ba |
|
MD5 | 48a62ec84588c32733abd9a630474a6e |
|
BLAKE2b-256 | b08ed8de7530f10193e0bb00bf20a4df48e37941ad0827e96846b3a26b0dc4d1 |