Package: translate-shell
translate-shellTranslate text by:online translatorsgooglebingyoudaozhiyunhaicioffline dictionariesstardictLLMOpenAIllama: use your local modelSupports:CLIGUIGNU/LinuxAndroidmacOSWindowsREPLscript:pythonshellvim:DEPRECATION: vim port will be replaced by language serverlanguage serverCI/CDgithub actionUsageUICLItrans--translators=google,bing,haici,stardictcrushREPL$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 filehacker> 画家  # translate textpainter; artist> !  # enter shell$echo$SHELL# execute a shell command/usr/bin/zsh$exit# exit shell>TUIVimTranslate--translators=google,bing FreeasinFreedomGUIGNU/LinuxAndroidScriptPython>>>fromtranslate_shell.translateimporttranslate>>>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 Script$xsel-o|trans--formatjson|jq-r'"《\(.results[].paraphrase)》的英文是 \(.text)."'《大教堂和集市》的英文是 the cathedral and the bazaar.Vim Script:letg:text='Just for Fun':letg:translation=json_decode(translate_shell#call('--format=json',g:text)):echog:text'is'g:translation.results[0].paraphrase'in Chinese.'JustforFunis纯娱乐inChinese.Language serverdocument hover: display translated resultscompletions: complete translated wordsCI/CDGithub ActionThis repo provides an action to translate*.poof a repository. Seeinputs.
For example, you have a repository which contains translations of another
project's documents (upstream), you can write a github workflow to detect if
upstream has update. If a new version exist, update the version and
generate new.pos,
then translate the changed.pos andgit commit.Examples:tmux-zhon:schedule:# Run this CI/CD at 0:00 on Friday-cron:0 0 * * 5workflow_dispatch:jobs:translate:runs-on:ubuntu-lateststeps:-uses:actions/checkout@v3-name:Generate new .poid:versionrun:|# update version# then use perl / sed / ... to replace the version string of your file# then generate new .poecho VERSION=XXX > $GITHUB_OUTPUT-name:Translate your *.pouses:Freed-Wu/translate-shell@main-name:Git commitrun:|git add **.pogit 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 pushgit push --tagsenv:VERSION:${{steps.version.outputs.VERSION}}GH_TOKEN:${{secrets.GH_TOKEN}}You can use the following commands to get the new version:# get a github repo's version:curlhttps://api.github.com/repos/user/repo/releases/latest|jq-r.tag_name# get a gitlab repo's versioncurl'https://gitlab.com/api/v4/projects/41218592/repository/tags?per_page=1'|jq-r'.[].name'You can use the following tools to generate the new.pos:sphinx-intl: Generate.pofor any
project using sphinx to generate document.po4a: Generate.pofor any project which use markdown,LaTeX, man, ... to write document.Similar ProjectsSeecomparison.FeaturesTranslate with different translators at same time, liketranslatorTranslate clipboard contents automatically, likeydcvSpeak the pronunciation of wordsSupport online translate enginesSupport offline dictionariesMany methods to use, from shell, python and vimMagic text, likeen:to change source language,:zh_CNto change target
language,<fileto translate file, etc.Allow customization byconfig.pyGood shell completions, especially forzsh,
complete options and translation historyManpage:man transBeautiful UICross platformsRich API, can be easily called from shell and pythonGood documentUnit test, keep code qualityCI/CDclean codeRespectPEP484RespectPEP621RespectXDGThe last but not least:it is a libre software.Seedocumentto know more.PS: PR is welcome! Please make code clean and keep test pass!