Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Explain the effects of export LANG, LC_CTYPE, and LC_ALL [closed]

Tags:

linux

I've just installed Linux Mint 17 and faced a problem that I couldn't use the Russian language in the terminal. (I see ? instead of letters.)

On one forum I found this solution:

Added in ~/.profile:

export LANG=ru_RU.UTF-8 export LC_CTYPE=ru_RU.UTF-8 export LC_ALL=ru_RU.UTF-8 

It helped, but also changed my interface language to Russian (which I didn't want). That's not even a problem, but anyway, I would like to know, how this code works (every line).

like image 863
Maxim Zagoruyko Avatar asked May 27 '15 10:05

Maxim Zagoruyko


People also ask

What does Lc_all do?

The LC_ALL variable sets all locale variables output by the command 'locale -a'. It is a convenient way of specifying a language environment with one variable, without having to specify each LC_* variable. Processes launched in that environment will run in the specified locale.

What is Lc_ctype?

The LC_CTYPE category determines character handling rules governing the interpretation of sequences of bytes of text data characters (that is, single-byte versus multibyte characters), the classification of characters (for example, alpha, digit, and so on), and the behavior of character classes.

What does Lang C mean?

LANG=C is a way to disable localization. It's used in scripts to predict program output which may vary based on current language. For more information read this. Follow this answer to receive notifications.

What is Lang in Linux?

Most UNIX or Linux systems use the LANG variable to specify the desired locale. However, different UNIX and Linux operating systems require different locale name values to specify the same language. Always use a value for LANG that is supported by the UNIX or Linux operating system you are using.


1 Answers

I'll explain with detail:

export LANG=ru_RU.UTF-8 

That is a shell command that will export an environment variable named LANG with the given value ru_RU.UTF-8. That instructs internationalized programs to use the Russian language (ru), variant from Russia (RU), and the UTF-8 encoding for console output.

Generally this single line is enough.

This other one:

export LC_CTYPE=ru_RU.UTF-8 

Does a similar thing, but it tells the program not to change the language, but only the CTYPE to Russian. If a program can change a text to uppercase, then it will use the Russian rules to do so, even though the text itself may be in English.

It is worth saying that mixing LANG and LC_CTYPE can give unexpected results, because few people do that, so it is quite untested, unless maybe:

export LANG=ru_RU.UTF-8 export LC_CTYPE=C 

That will make the program output in Russian, but the CTYPE standard old C style.

The last line, LC_ALL is a last resort override, that will make the program ignore all the other LC_* variables and use this. I think that you should never write it in a profile line, but use it to run a program in a given language. For example, if you want to write a bug report, and you don't want any kind of localized output, and you don't know which LC_* variables are set:

LC_ALL=C program 

About changing the language of all your programs or only the console, that depends on where you put these lines. I put mine in ~/.bashrc so they don't apply to the GUI, only to the bash consoles.

like image 160
rodrigo Avatar answered Oct 16 '22 09:10

rodrigo