Giter Site home page Giter Site logo

sheepla / strans Goto Github PK

View Code? Open in Web Editor NEW
32.0 1.0 0.0 67 KB

πŸ“– A command line translate tool with interactive mode inspired by translate-shell

License: MIT License

Go 96.23% Makefile 3.77%
cli go-cli translate translate-shell translate-cli lingva repl lingva-translate

strans's Introduction

golangci-lint Release

strans

A command line translate tool written in Go with GNU Readline-like interactive mode (--repl) inspired by translate-shell

Language:Go License:MIT Latest Release

Features

  • Non-interactive mode: A mode that can be used in the same way as a general command line tool
  • Interactive mode: GNU Readline-like line editing mode for instant translation
  • Read translated text aloud: The option to read the translated text aloud after performing the translation

Usage

Specifying languages for translations source and targets

To specify the translation source/target language, specify values for the arguments of the -s, --source and -t, --target options, or set values in the environment variable STRANS_SOURCE_LANG, STRANS_TARGET_LANG.

If you specify ? as the --source or --target option's value, a fzf-like menu will be displayed, allowing you to interactively select the language.

To check the list of languages, run the command with -S, --list-source or -T, --list-target options.

Non-interactive mode

If you specify text as a non-option argument, that text will be translated. Multiple arguments are allowed, and arguments are joined by spaces.

strans [OPTIONS] TEXT...

# e.g.
strans -s en -t ja "Hello, World" # => "γ“γ‚“γ«γ‘γ―δΈ–η•Œ"

A non-option argument of - will read text from standard input and translate it. You can also output the translated text as speech.

strans [OPTIONS] -

# e.g.
echo "Hello, World" | strans -s en -t ja - # => "γ“γ‚“γ«γ‘γ―δΈ–η•Œ"
strans -s en -t ja < README.md # => The contents of the README.md will translated.

Interactive mode

To use interactive mode, run the command with the -r, --repl flag. Enter your text and it will be translated instantly.

You can use GNU Readline-like line editing, scroll back (Ctrl-N, Ctrl-P) and incremental search (Ctrl-R) the execution history.

Empty inputs (just typing Enter) are ignored and no translation is performed.

Typing Ctrl-D exits interactive mode and returns you to the shell you were running from.

The history is kept in the file strans_history.txt in the OS temporary directory and can be recalled when executing the command again.

[you@your-computer]$ strans --repl -s ja -t en

[ja -> en]
> γ“γ‚“γ«γ‘γ―δΈ–η•Œ
hello world

[ja -> en]
> bye

[you@your-computer]$ 

Read text as speech (beta)

Running the command with the --audio flag, after executing the translation, read the translated text aloud and you can check the pronunciation.

This feature is available in both interactive and non-interactive mode.

Options

Specify the source language name (e.g. en, ja, etc.) for --source option, and specify the target language name for --target option.

To change the instance, specify the hostname of the instance in the --instance option.

NAME:
   strans - a command line translate tool with GNU Readline like interactive mode

USAGE:
   strans [OPTIONS] TEXT...
   echo TEXT... | strans [OPTIONS] -
   strans [OPTIONS] - < FILE

VERSION:
   unknown-unknown

COMMANDS:
   help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --source value, -s value, --from value  Source language to translate; specifying the value '?' will shows a selectable menu [$STRANS_SOURCE_LANG]
   --target value, -t value, --to value    Target language to translate; specifying the value '?' will shows a selectable menu [$STRANS_TARGET_LANG]
   --instance value, -i value              Instance host name of Lingva Translate [$STRANS_INSTANCE]
   --repl, -r                              Start interactive mode (default: false)
   --audio, -a                             Read translated text aloud (default: false)
   --list-source, -S                       Show a list of source languages (default: false)
   --list-target, -T                       Show a list of target languages (default: false)
   --help, -h                              show help (default: false)
   --version, -v                           print the version (default: false)

Various options can specify default values not only from command line arguments, but also by setting environment variables.

STRANS_TARGET_LANG="ja" strans "Hello, World" # => "γ“γ‚“γ«γ‘γ―δΈ–η•Œ"

export STRANS_SOURCE_LANG="en"
export STRANS_TARGET_LANG="ja"
strans "Hello, World" # => γ“γ‚“γ«γ‘γ―δΈ–η•Œ

This tool is a program that calls Lingva Translate's public API. See the Lingva Translate README.md for details.

Installation

go install github.com/sheepla/strans@latest

Roadmap

  • Distribute pre-built binaries on GitHub release page
  • Print more translate info (definitions, similar words, examples, pronunciation, etc.)

Thanks

strans's People

Contributors

sheepla avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

strans's Issues

Support voice read aloud

Getting audio in a byte array from this point of API and play the audio: /api/v1/audio/:lang/:query

Error `404 Not Found` `panic: runtime error: invalid memory address or nil pointer dereference`

Translation may fail with a 404 error if the source text contains / symbol(s):

[auto -> en]
> こんにけは/δΈ–η•Œ
an error occurred on executing HTTP method: https://lingva.ml/api/v1/auto/en/%E3%81%93%E3%82%93%E3%81%AB%E3%81%A1%E3%81%AF/%E4%B8%96%E7%95%8C 404 Not Found
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x0 pc=0xb00467]

goroutine 1 [running]:
github.com/sheepla/strans/repl.Start(0xc000027140, 0x0)
        C:/Users/admin/ghq/github.com/sheepla/strans/repl/repl.go:78 +0x487
main.run(0xc000026540)
        C:/Users/admin/ghq/github.com/sheepla/strans/main.go:165 +0x471
github.com/urfave/cli/v2.(*Command).Run(0xc000002c80, 0xc000026540, {0xc000026080, 0x4, 0x4})
        C:/Users/admin/go/pkg/mod/github.com/urfave/cli/[email protected]/command.go:271 +0xa42
github.com/urfave/cli/v2.(*App).RunContext(0xc000108000, {0xcc32d0?, 0xc00000e0d8}, {0xc000026080, 0x4, 0x4})
        C:/Users/admin/go/pkg/mod/github.com/urfave/cli/[email protected]/app.go:333 +0x665
github.com/urfave/cli/v2.(*App).Run(...)
        C:/Users/admin/go/pkg/mod/github.com/urfave/cli/[email protected]/app.go:310
main.main()
        C:/Users/admin/ghq/github.com/sheepla/strans/main.go:38 +0x45

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.