Feature request: Don't translate to source language
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
Где мой отчет
This is basically the same feature as #153, which is yet to be implemented.
@soimort yep it is. So for example, implementation of flag like '-no-same-language', will be a good solution for both issues.
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.
- Clone the git repo
- 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
}
- 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)
- 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.
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 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