translate-shell icon indicating copy to clipboard operation
translate-shell copied to clipboard

Feature request: Don't translate to source language

Open ein-shved opened this issue 6 years ago • 5 comments

Mostly I want to translate from en to ru and vise versa, depending on the detected language. For now I have next config:

{                                                                                
    :verbose         false                                                       
    :join-sentence   true                                                        
    :identify        true                                                        
    :tl              [ "ru" "en" ]                                               
}

Trans correctly translate both en and ru, but shows result for both en and ru at once:

>  trans Где мой отчет
Где мой отчет
Where is my report
>  trans Where is my report
Где мой отчет
Where is my report

How can I make it to hide translations from ru to ru and from en to en? Like that:

>  trans Где мой отчет
Where is my report
>  trans Where is my report
Где мой отчет

ein-shved avatar Apr 26 '19 13:04 ein-shved

This is basically the same feature as #153, which is yet to be implemented.

soimort avatar Apr 26 '19 13:04 soimort

@soimort yep it is. So for example, implementation of flag like '-no-same-language', will be a good solution for both issues.

ein-shved avatar Apr 26 '19 14:04 ein-shved

I found a way to make this work, for google translate. Perhaps in the future I will expand this and make it more robust (maybe add a flag to turn this on or off) and open a PR. It's definitely not perfect, and I'm sure there will be some bugs here or there, but it does the job for my needs.

  1. Clone the git repo
  2. Edit the include/Translators/GoogleTranslate.awk file: Add an if statement around the # Generate output section (see comments for changes):
    if (!(tl == il)) { # this is a new line
    if (!isVerbose) {
   ...
   return r 
  } # this is also a new line
} 
  1. Edit the include/Translate.awk file: Replace the following line: p(getTranslation(text, Option["sl"], Option["tl"][i], Option["hl"], Option["verbose"], Option["play"] || Option["download-audio"], playlist, il))with:
transOutput = getTranslation(text, Option["sl"], Option["tl"][i], Option["hl"], Option["verbose"], Option["play"] || Option["download-audio"], playlist, il)
                    if (transOutput) # output is not an empty string
                        p(transOutput)

  1. Install with make && sudo make install

After these changes you can select the desired target languages, and the translate-shell will not translate into the source language.

yuvalginor avatar Dec 24 '20 13:12 yuvalginor

Hiding the translation whenever tl == il does not sound an optimal solution; sometimes people do use trans to look up an English word in the dictionary (without translating into any other language), in which case the detected language (il) is expected to be identical to the target language (tl).

Instead of simply hiding the translation, I prefer having an option that behaves like Google Translate's "Swap languages":

$ trans -b en:ru -autoswap 'hello world'
Привет, мир

$ trans -b en:ru -autoswap 'Привет, мир'
Hello World

basically when you specify source and target languages, they're swapped automatically if trans knows it should be the other way around.

soimort avatar Dec 28 '20 17:12 soimort

@soimort That would be an incredible feature that I would love to see added to this project - I'm sure tons of people would benefit from it. My comment was a simple (and definitely not perfect) workaround that worked for my use case. Ping me if you have an idea of how to implement this, I may be interested in tackling it in my spare time

yuvalginor avatar Jan 31 '21 14:01 yuvalginor