translate-shell

Translate text by google, bing, youdaozhiyun, haici, stardict, openai, large language model of local machine, etc at same time from CLI, GUI (GNU/Linux, Android, macOS and Windows), REPL, python, shell and vim.

https://github.com/freed-wu/translate-shell

Science Score: 54.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
    1 of 5 committers (20.0%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (7.4%) to scientific vocabulary

Keywords

bing chatgpt commandline-tool google haici lftp llama llamacpp lsp-server openai prompt python repl shell stardict translate vim youdao

Keywords from Contributors

dice-roller archive-webpage medical-images
Last synced: 6 months ago · JSON representation ·

Repository

Translate text by google, bing, youdaozhiyun, haici, stardict, openai, large language model of local machine, etc at same time from CLI, GUI (GNU/Linux, Android, macOS and Windows), REPL, python, shell and vim.

Basic Info
Statistics
  • Stars: 40
  • Watchers: 2
  • Forks: 5
  • Open Issues: 6
  • Releases: 52
Topics
bing chatgpt commandline-tool google haici lftp llama llamacpp lsp-server openai prompt python repl shell stardict translate vim youdao
Created about 3 years ago · Last pushed 6 months ago
Metadata Files
Readme Changelog Funding License Citation

README.md

translate-shell

pre-commit.ci status github/workflow codecov readthedocs DeepSource

github/downloads github/downloads/latest github/issues github/issues-closed github/issues-pr github/issues-pr-closed github/discussions github/milestones github/forks github/stars github/watchers github/contributors github/commit-activity github/last-commit github/release-date

github/license github/languages github/languages/top github/directory-file-count github/code-size github/repo-size github/v

pypi/status pypi/v pypi/downloads pypi/format pypi/implementation pypi/pyversions

Translate text by:

  • online translators
    • google
    • bing
    • youdaozhiyun
    • haici
  • offline dictionaries
    • stardict
  • LLM
    • OpenAI
    • llama: use your local model

Supports:

  • CLI
  • GUI
    • GNU/Linux
    • Android
    • macOS
    • Windows
  • REPL
  • script:
    • python
    • shell
    • vim: DEPRECATION: vim port will be replaced by language server
  • language server
  • CI/CD
    • github action

Usage

UI

CLI

sh trans --translators=google,bing,haici,stardict crush

CLI

REPL

```console $ 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

```

REPL

TUI

Vim

vim Translate --translators=google,bing Free as in Freedom

Vim

GUI

GNU/Linux

GNU/Linux

Android

android-toast

Script

Python

```pycon

from translateshell.translate import translate translate("The Mythical Man-Month", "zhTW") ... Translations( ... status=1, ... results=[ ... Translation( ... translator="google", ... sl="auto", ... tl="zhTW", ... text="The Mythical Man-Month", ... phonetic="", ... paraphrase="神話般的人月", ... explains={}, ... details={}, ... alternatives=["神話般的月"] ... ) ... ], ... text="The Mythical Man-Month", ... tolang="zhTW", ... fromlang="auto", ... ) ```

Shell Script

console $ xsel -o | trans --format json | jq -r '"《\(.results[].paraphrase)》的英文是 \(.text)."' 《大教堂和集市》的英文是 the cathedral and the bazaar.

Vim Script

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.

Language server

  • [x] document hover: display translated results
  • [x] completions: complete translated words

CI/CD

Github Action

This repo provides an action to translate *.po of a repository. See inputs. 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 and git commit.

Examples:

```yaml 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 > $GITHUBOUTPUT - 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:$GHTOKEN@github.com/$GITHUBREPOSITORY" git push git push --tags env: VERSION: ${{steps.version.outputs.VERSION}} GHTOKEN: ${{secrets.GH_TOKEN}} ```

You can use the following commands to get the new version:

```bash

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' ```

You can use the following tools to generate the new .pos:

  • sphinx-intl: Generate .po for any project using sphinx to generate document.
  • po4a: Generate .po for any project which use markdown, LaTeX, man, ... to write document.

Similar Projects

See comparison.

Features

  • Translate with different translators at same time, like translator
  • Translate clipboard contents automatically, like ydcv
  • Speak the pronunciation of words
  • Support online translate engines
  • Support offline dictionaries
  • Many methods to use, from shell, python and vim
  • Magic text, like en: to change source language, :zh_CN to change target language, <file to translate file, etc.
  • Allow customization by config.py
  • Good shell completions, especially for zsh, complete options and translation history
  • Manpage: man trans
  • Beautiful UI
  • Cross platforms
  • Rich API, can be easily called from shell and python
  • Good document
  • Unit test, keep code quality
  • CI/CD
  • clean code
  • Respect PEP484
  • Respect PEP621
  • Respect XDG

The last but not least: it is a libre software.

See document to know more.

PS: PR is welcome! Please make code clean and keep test pass!

Owner

  • Name: wzy
  • Login: Freed-Wu
  • Kind: user
  • Location: $HOME
  • Company: @ustc-ivclab

An adherent of hacker culture and open source.

Citation (CITATION.cff)

---
cff-version: 1.2.0
message: If you use this software, please cite it as below.
authors:
  - family-names: Wu
    given-names: Zhenyu
    orcid: https://orcid.org/0000-0001-6478-9993
title: "translate-shell: Translate text by google, bing, youdaozhiyun, haici, stardict, openai, large language model of local machine, etc at same time from CLI, GUI (GNU/Linux, Android, macOS and Windows), REPL, python, shell and vim."
date-released: 2022-12-03
url: "https://github.com/Freed-Wu/translate-shell"

GitHub Events

Total
  • Release event: 1
  • Watch event: 8
  • Push event: 71
  • Create event: 1
Last Year
  • Release event: 1
  • Watch event: 8
  • Push event: 71
  • Create event: 1

Committers

Last synced: 6 months ago

All Time
  • Total Commits: 160
  • Total Committers: 5
  • Avg Commits per committer: 32.0
  • Development Distribution Score (DDS): 0.075
Past Year
  • Commits: 1
  • Committers: 1
  • Avg Commits per committer: 1.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Wu Zhenyu w****u@u****u 148
deepsource-autofix[bot] 6****] 9
DeepSource Bot b****t@d****o 1
minyu m****u@o****m 1
SIDB 999 b****b@i****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 13
  • Total pull requests: 32
  • Average time to close issues: 3 days
  • Average time to close pull requests: about 1 month
  • Total issue authors: 6
  • Total pull request authors: 5
  • Average comments per issue: 0.69
  • Average comments per pull request: 0.78
  • Merged pull requests: 8
  • Bot issues: 0
  • Bot pull requests: 31
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • Freed-Wu (8)
  • sidb999 (1)
  • navono (1)
  • CZ-Wu (1)
  • long76 (1)
  • fieri (1)
Pull Request Authors
  • dependabot[bot] (11)
  • deepsource-autofix[bot] (10)
  • pre-commit-ci[bot] (9)
  • sidb999 (1)
  • renovate[bot] (1)
Top Labels
Issue Labels
Pull Request Labels
dependencies (11) github_actions (11)

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 314 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 2
  • Total versions: 52
  • Total maintainers: 1
pypi.org: translate-shell

Translate text by google, bing, youdaozhiyun, haici, stardict, openai, large language model of local machine, etc at same time from CLI, GUI (GNU/Linux, Android, macOS and Windows), REPL, python, shell and vim.

  • Versions: 52
  • Dependent Packages: 0
  • Dependent Repositories: 2
  • Downloads: 314 Last month
Rankings
Dependent packages count: 10.1%
Downloads: 10.4%
Dependent repos count: 11.5%
Average: 12.8%
Stargazers count: 15.2%
Forks count: 16.9%
Maintainers (1)
Last synced: 6 months ago

Dependencies

.github/workflows/main.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
  • actions/upload-artifact v3 composite
  • codecov/codecov-action v3 composite
  • pypa/gh-action-pypi-publish release/v1 composite
  • rhysd/action-setup-vim v1 composite
  • softprops/action-gh-release v1 composite
docs/requirements.txt pypi
  • myst-parser *
  • sphinxcontrib-eval *
requirements/color.txt pypi
  • colorama *
requirements/dev.txt pypi
  • neovim * development
  • pexpect * development
  • pre-commit * development
  • pytest-cov * development
  • tomli >=1.0.0 development
  • tomli-w * development
requirements/keyring.txt pypi
  • keyring *
requirements/langdetect.txt pypi
  • langdetect *
requirements/notification.txt pypi
  • py-notifier *
requirements/rich.txt pypi
  • rich *
requirements/stardict.txt pypi
  • PyStarDict *
requirements/yaml.txt pypi
  • PyYAML *
action.yml actions
  • Dockerfile * docker
Dockerfile docker
  • python latest build
package.json npm
pyproject.toml pypi
requirements/llama.txt pypi
  • jinja2 *
  • llama-cpp-python *
requirements/lsp.txt pypi
  • pygls *
requirements/openai.txt pypi
  • jinja2 *
  • opneai *
requirements/po.txt pypi
  • polib *
  • tqdm *
requirements/repl.txt pypi
  • jedi *
  • repl-python-codestats *
  • rich *
requirements/wakatime.txt pypi
  • repl-python-wakatime *
requirements.txt pypi
  • tomli *
setup.py pypi