0

I have a bash script that i need to translate to other languages. Only echo messages

Is there some automatic method, translation whole script, or tool that can help me translate all messages "echo" into other languages? (To avoid having to enter all the "echo" in the google translator)

closed as too broad by Thomas Dickey, GAD3R, techraf, HalosGhost, mdpc Oct 25 '16 at 0:11

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • that's the same as putting all the "echo" in the google translator – user167531 Oct 24 '16 at 23:04
  • can you clairfy what you want / don't want?, i don't see how "dict -d fd-eng-spa "how are you?"" is the same as google translate – mikejonesey Oct 24 '16 at 23:11
  • is the same thing as putting in the google translator "how are you" and It translated "Hola cómo estás" eng-spa. What I look for in a method to translate the whole script automatically. if possible on a single line (only messages "echo") – user167531 Oct 24 '16 at 23:17
  • 1
    Nobody is spamming. They are trying to help you. Automatic translation is extremely limited. 90% of the time it is very, very bad. Despite this, you have two users giving you solutions and you accuse them of spamming? – terdon Oct 25 '16 at 7:44
3

you can't change some language setting and your script's echo commands will magically be another language.

you can do one of the following:

  • source a language file.
  • create a bash script that converts the original bash script.
  • create a function in the bash script that translates the output.

As you're not keen on the dict solution as it's too google translatey... I'll bet sourcing would be a good solution for you.

a simple example would be;

/lang/en.sh

FILEMISSING="That file is missing..."

/lang/fr.sh

FILEMISSING="Ce fichier est manquant..."

actualscript.sh

#!/bin/bash

LANGUAGE=${LANG:0:2}
source /lang/$LANGUAGE.sh

if [ ! -f "bob.txt" ]; then
  echo "$FILEMISSING"
fi
  • there are things that can be done "magically". As gettext or other projects, but they are very complicated to manage. Also, I just want to translate messages "echo" – user167531 Oct 24 '16 at 23:45
  • Gettext is using Gilles's suggestion. – mikejonesey Oct 24 '16 at 23:56
  • yes i know, but is it is easier with google translate translator with gettext – user167531 Oct 24 '16 at 23:58
1

You can use the $"…" syntax to specify a string that is to be translated according to the locale.

The translations must be in a message catalog file; see the bash manual for where this file is located and the Glibc manual for the format of the file.

Of course, you (or somebody else) will have to supply the translation for each string. There's no way to translate text automatically, especially short strings out of context. Automatic translation is science fiction.

  • It is not science fiction. This if possible, with gettext or a simple script like this (but are difficult to handle) jkanetwork.com/verart.php?idart=114 – user167531 Oct 24 '16 at 23:47
  • @acj No. The difficult part is not the plumbing (which is what $"…" is about, it uses gettext under the hood), it's translating sentences that are more complex than “hello”. You need a human for that (you can use an automated service, but only if you don't mind producing garbage half the time). – Gilles Oct 25 '16 at 12:10