set locale on commandline without system-config-language

General support questions
janxy
Posts: 3
Joined: 2011/07/23 12:15:21

set locale on commandline without system-config-language

Post by janxy » 2011/07/23 12:47:38

Dear others,

i'm proud and relieved user of a fresh CentOS6 installation, which is running as minimal installation (no X) with the determination to be server soon.

I installed using the GUI-mode (still highly disappointed that text-mode does not provide all the crucial features any longer, which i deem totally uncool, ungeeky and un-enterprise, REDHAT!).

I had chosen english (US) as interface language, the only german thing i picked during installation was keyboard layout and timezone (UTC Europe Berlin).

Now: when i log in (as root or any other local account), the system's default locale is "en_EN.UTF-8" as expected, but for all users the (effective) locale is "de_DE.UTF-8".

I dont want this.

Usually i would heal this via "system-config-language",


but 1st) this is for wimps,

and 2nd) this would have to be installed before, loading "lot" of stuff i don't want on my server (some x-libs, pango, ...), all just for setting my language? NO!

A 2nd) attempt using "setlocale" also failed with the same phenomen (specimen below) that all users encounter, who also misunderstood, that this is used on the command line (which is wrong i now guess).

The 3rd) solution: to set an english locale actively via "export" in my bash_profile works of course, but would leave me dump, not knowing where CentOS-system actually configures the user's locale?!?

I skimmed all the promising files (skeleton, profile, ...), but to no avail.

Thus: geeks to the rescue: where does RHEL-class systems set user's locale/language which obviously subersedes the system's default setting done in "/etc/sysconfig/i18n"?

Eagerly waiting for the solution:

cheers

janxy


=====================================
[root@w ~]# env
HOSTNAME= ...
SELINUX_ROLE_REQUESTED=
TERM=xterm-color
SHELL=/bin/bash
HISTSIZE=1000
SSH_CLIENT=SELINUX_USE_CURRENT_RANGE=
SSH_TTY=/dev/pts/0
USER=root
LS_COLORS=rs=0:di= ...
MAIL=/var/spool/mail/root
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
PWD=/root
LANG=de_DE.UTF-8
SELINUX_LEVEL_REQUESTED=
HISTCONTROL=ignoredups
SHLVL=1
HOME=/root
LOGNAME=root
SSH_CONNECTION= ...
LESSOPEN=|/usr/bin/lesspipe.sh %s
G_BROKEN_FILENAMES=1
_=/bin/env
=====================================

=====================================
[root@w ~]# locale
LANG=de_DE.UTF-8
LC_CTYPE="de_DE.UTF-8"
LC_NUMERIC="de_DE.UTF-8"
LC_TIME="de_DE.UTF-8"
LC_COLLATE="de_DE.UTF-8"
LC_MONETARY="de_DE.UTF-8"
LC_MESSAGES="de_DE.UTF-8"
LC_PAPER="de_DE.UTF-8"
LC_NAME="de_DE.UTF-8"
LC_ADDRESS="de_DE.UTF-8"
LC_TELEPHONE="de_DE.UTF-8"
LC_MEASUREMENT="de_DE.UTF-8"
LC_IDENTIFICATION="de_DE.UTF-8"
LC_ALL=
[root@w ~]# cat /etc/sysconfig/i18n
LANG="en_US.UTF-8"
SYSFONT="latarcyrheb-sun16"
[root@w ~]#
=====================================

=====================================
[root@w ~]# cat .bashrc
# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
=====================================

=====================================
[root@w ~]# cat .bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
#unset LANG
[root@w ~]#
=====================================

=====================================
[root@w ~]# setlocale en_US.utf-8
-bash: setlocale: Kommando nicht gefunden.
[root@w ~]#
=====================================

pschaff
Retired Moderator
Posts: 18276
Joined: 2006/12/13 20:15:34
Location: Tidewater, Virginia, North America
Contact:

set locale on commandline without system-config-language

Post by pschaff » 2011/07/23 15:07:35

Welcome to the CentOS fora. Please see the recommended reading for new users linked in my signature.
[code]# yum whatprovides \*/setlocale
Loaded plugins: priorities, refresh-packagekit
No Matches found
[/code]
No EL6 package provides setlocale. There are man pages related to the setlocale() function.

What does the following command find?[code]find /etc -type f -exec fgrep de_DE.UTF-8 {} \; -ls[/code]

majun
Posts: 145
Joined: 2010/03/11 11:33:59

Re: set locale on commandline without system-config-language

Post by majun » 2011/07/23 15:11:29

Haven't tried CentOS 6 yet but in CentOS 5 it's enough to edit /etc/sysconfig/i18n and reboot.

User avatar
TrevorH
Site Admin
Posts: 33202
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: set locale on commandline without system-config-language

Post by TrevorH » 2011/07/23 21:57:12

[quote]
where does RHEL-class systems set user's locale/language which obviously subersedes the system's default setting done in "/etc/sysconfig/i18n"?
[/quote]

As far as I know, you just set it to whatever you want in ~/.bashrc e.g.

[code]
export LANG=en_GB.UTF-8
[/code]

janxy
Posts: 3
Joined: 2011/07/23 12:15:21

Re: set locale on commandline without system-config-language

Post by janxy » 2011/07/26 09:23:51

Dear Phil,

thanks for this hint. That was initially what really puzzled me and finally triggered this SOS:

since that search yields absolutely nothing and buried my hope it would be s.th. noted somewhere explicitly where i just had to remove it:

[root@w ~]# find /etc -type f -exec fgrep de_DE.UTF-8 {} \; -ls
[root@w ~]#

Thus i suspect it's generated dynamically, e.g. in accordance to the current timezone maybe?



@Trevor: thanks also, i actually did s.th. similar by:

[root@w ~]# cat /etc/environment
LANG=en_US.utf-8
LC_ALL=en_US.utf-8
[root@w ~]#

as an intermediate "fix" to get my things done.

But still that is unsatisfying, i'd really would like to know where and how...

My last resort could possibly be to scrutinize the source code of the "system-config-language" binary which could disclose what kind of magic this tool does behind the scenes.

So long and

cheers

J.

r_hartman
Posts: 711
Joined: 2009/03/23 15:08:11
Location: Netherlands
Contact:

Re: set locale on commandline without system-config-language

Post by r_hartman » 2011/07/27 09:36:06

[quote]
janxy wrote:
Thus i suspect it's generated dynamically, [/quote]

That just might be correct. From the CentOS5.6 /etc/gdm/locale.alias file:
[quote]# NOTE! This is a broken way to do things. Gdm currently reads languages ONLY
# from this file. This is Broken(tm). This setup will be replaced in some
# future version to be replaced by some automatic detection of available
# locales.[/quote]

EDIT: When re-reading after posting, I realised this may be unrelated. But I cannot delete posts, and maybe it's not. :-?

arlukin
Posts: 1
Joined: 2011/10/06 14:07:09
Location: Stockholm - Sweden
Contact:

Re: set locale on commandline without system-config-language

Post by arlukin » 2011/10/06 14:12:18

Did you find the answer to your questions?

I have the same kind of problem now. I don't think the locale was wrong for me after the installation. But after some tweaking of the server, I now got the wrong locale.


# locale
LANG=sv_SE.UTF-8
LC_CTYPE="sv_SE.UTF-8"
LC_NUMERIC="sv_SE.UTF-8"
LC_TIME="sv_SE.UTF-8"
LC_COLLATE="sv_SE.UTF-8"
LC_MONETARY="sv_SE.UTF-8"
LC_MESSAGES="sv_SE.UTF-8"
LC_PAPER="sv_SE.UTF-8"
LC_NAME="sv_SE.UTF-8"
LC_ADDRESS="sv_SE.UTF-8"
LC_TELEPHONE="sv_SE.UTF-8"
LC_MEASUREMENT="sv_SE.UTF-8"
LC_IDENTIFICATION="sv_SE.UTF-8"
LC_ALL=

find /etc -type f -exec fgrep sv_SE.UTF-8 {} \; -ls

gives me nothing.

Nothing done in the bash files in the /root folder.

viniciusfs
Posts: 1
Joined: 2012/01/04 22:18:05
Contact:

Re: set locale on commandline without system-config-language

Post by viniciusfs » 2012/01/04 22:46:22

It's strange, but I've noticed that language is set dynamically according host system language. I'm running CentOS 6 on a Virtual Box virtual machine, my host system is a Ubuntu Desktop in Portuguese and I found this issue exactly how described by janxy and alurkin. After change my host system language to English, everything worked fine and CentOS language was set to English.

I don't know why but when my host system is in Portuguese, CentOS language is set to Portuguese ignoring /etc/sysconfig/i18n file.

How can I prevent this behavior?

User avatar
TrevorH
Site Admin
Posts: 33202
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: set locale on commandline without system-config-language

Post by TrevorH » 2012/01/04 23:01:37

Do you have a ~/.i18n file for each user? I just found /etc/profile.d/lang.sh that reads this file and sets various bits based on it. If this is the cause then do you also have an /etc/skel/.i18n that'll be added for any new user created?

cs12
Posts: 17
Joined: 2007/11/03 16:51:58

Re: set locale on commandline without system-config-language

Post by cs12 » 2012/02/08 16:18:03

Did anyone fix this issue?

I'm running 5.3 and got the same problem.

$ cat /etc/sysconfig/i18n
LANG="en_US.UTF-8"
SYSFONT="latarcyrheb-sun16"

$ locale
LANG=
LC_CTYPE="POSIX"
LC_NUMERIC="POSIX"
LC_TIME="POSIX"
LC_COLLATE="POSIX"
LC_MONETARY="POSIX"
LC_MESSAGES="POSIX"
LC_PAPER="POSIX"
LC_NAME="POSIX"
LC_ADDRESS="POSIX"
LC_TELEPHONE="POSIX"
LC_MEASUREMENT="POSIX"
LC_IDENTIFICATION="POSIX"
LC_ALL=

# locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

So root account have the correct $LANG, all other user accounts have it wrong.
I checked all initialization files like /etc/profile etc. It seems nothing is changing $LANG on the fly. Seems a bit strange to me...

Post Reply