Going through the bash manual I found the Locale-specific translation section Bash Reference Manual → Locale-Specific Translation: Locale-Specific Translation

A double-quoted string preceded by a dollar sign (‘$’) will cause the string to be translated according to the current locale. If the current locale is C or POSIX, the dollar sign is ignored. If the string is translated and replaced, the replacement is double-quoted.

Some systems use the message catalog selected by the LC_MESSAGES shell variable. Others create the name of the message catalog from the value of the TEXTDOMAIN shell variable, possibly adding a suffix of ‘.mo’. If you use the TEXTDOMAIN variable, you may need to set the TEXTDOMAINDIR variable to the location of the message catalog files. Still others use both variables in this fashion: TEXTDOMAINDIR/LC_MESSAGES/LC_MESSAGES/TEXTDOMAIN.mo.

So I decided to test it.

My machine uses the English US locale:

$ echo $LANG

And writing an English word worked well:

$ echo $"Hello"

I checked which locales are available here and found out many:

$ locale -a

So I decided to test this functionallity with Spanish. However, changing the locale did not make the translation to be triggered:

$ LANG=es_ES.UTF8 echo $"Hello"
Hello              # Still in English. Should be "Hola", in Spanish

Why is that? What am I missing here? I suspect there is a set of words that are translated somewhere, but I cannot find out where.

This is my Bash version:

$ bash --version
GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu)

1 Answer 1


You are missing making the actual translation. (The computer does not know English or Spanish, all it knows is to look up the string in a catalog.) See Localization in the Advanced Bash Scripting Guide. See the FAQ for a worked-out example. There is security warning for the construct $"..."; in practice this means that you must protect the translations file as well as the script itself.

  • Interesting, so it is not that straight-forward. I somehow imagined a set of dictionaries with some bijections among words. I will give a try to the useful links, thanks.
    – fedorqui
    Jan 4, 2017 at 11:40
  • @fedorqui: Word-by-word translations are between bad and incomprehensible, not to mention that very often words in different languages do not have a one-to-one correspondence. For example, French "chaîne de caractères" is not a "chain of characters" but a "character string"; conversely, the French for "character string" is not "corde de caractère".
    – AlexP
    Jan 4, 2017 at 11:51
  • 1
    OK so going through the article you linked How to add localization support to your bash scripts in BashFAQ made it.
    – fedorqui
    Jan 4, 2017 at 15:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.