You are not logged in.

#1 2019-05-17 06:57:44

Risse
Member
Registered: 2019-05-17
Posts: 8

[SOLVED] Setting the locale in Bash

I have two locales set up, en_US and fi_FI. I want all the messages and ui to be in english, and dates, addresses etc to be in finnish.

Here is an example how it works now:

[risse@rissedesktop ~]$ locale
LANG=en_US.UTF-8
LC_CTYPE=fi_FI.UTF-8
LC_NUMERIC=fi_FI.UTF-8
LC_TIME=fi_FI.UTF-8
LC_COLLATE=fi_FI.UTF-8
LC_MONETARY=fi_FI.UTF-8
LC_MESSAGES=en_US.UTF-8
LC_PAPER=fi_FI.UTF-8
LC_NAME=fi_FI.UTF-8
LC_ADDRESS=fi_FI.UTF-8
LC_TELEPHONE=fi_FI.UTF-8
LC_MEASUREMENT=fi_FI.UTF-8
LC_IDENTIFICATION=fi_FI.UTF-8
LC_ALL=
[risse@rissedesktop ~]$ asdf
bash: asdf: komentoa ei löydy

As you can see, the error message for "asdf" is in finnish, even though the LANG and LC_MESSAGES are set to en_US.

So where is the locale for Bash terminal determined? I have tried googling this for hours now, and nothing seems to work.

Last edited by Risse (2019-05-18 05:38:02)

Offline

#2 2019-05-17 07:06:32

schard
Forum Moderator
From: Hannover
Registered: 2016-05-06
Posts: 2,718
Website

Re: [SOLVED] Setting the locale in Bash

What does

echo $LANG

say?
Maybe bash itself is running with previous locale settings.


Inofficial first vice president of the Rust Evangelism Strike Force

Offline

#3 2019-05-17 07:11:30

Risse
Member
Registered: 2019-05-17
Posts: 8

Re: [SOLVED] Setting the locale in Bash

schard wrote:

What does

echo $LANG

say?
Maybe bash itself is running with previous locale settings.

[risse@rissedesktop ~]$ echo $LANG
en_US.UTF-8
[risse@rissedesktop ~]$ asdf
bash: asdf: komentoa ei löydy

Offline

#4 2019-05-17 07:17:57

schard
Forum Moderator
From: Hannover
Registered: 2016-05-06
Posts: 2,718
Website

Re: [SOLVED] Setting the locale in Bash

What happens if you open a sub shell by running bash within the current shell? Does it behave the same way?

Last edited by schard (2019-05-17 07:18:48)


Inofficial first vice president of the Rust Evangelism Strike Force

Offline

#5 2019-05-17 07:20:42

Risse
Member
Registered: 2019-05-17
Posts: 8

Re: [SOLVED] Setting the locale in Bash

schard wrote:

What happens if you open a sub shell by running bash within the current shell? Does it behave the same way?

You mean like this?

[risse@rissedesktop ~]$ bash
[risse@rissedesktop ~]$ asdf
bash: asdf: komentoa ei löydy
[risse@rissedesktop ~]$ locale
LANG=en_US.UTF-8
LC_CTYPE=fi_FI.UTF-8
LC_NUMERIC=fi_FI.UTF-8
LC_TIME=fi_FI.UTF-8
LC_COLLATE=fi_FI.UTF-8
LC_MONETARY=fi_FI.UTF-8
LC_MESSAGES=en_US.UTF-8
LC_PAPER=fi_FI.UTF-8
LC_NAME=fi_FI.UTF-8
LC_ADDRESS=fi_FI.UTF-8
LC_TELEPHONE=fi_FI.UTF-8
LC_MEASUREMENT=fi_FI.UTF-8
LC_IDENTIFICATION=fi_FI.UTF-8
LC_ALL=

No difference really.

Offline

#6 2019-05-17 07:22:23

schard
Forum Moderator
From: Hannover
Registered: 2016-05-06
Posts: 2,718
Website

Re: [SOLVED] Setting the locale in Bash

Yes. Hm. I'm out of ideas here. I may try to reproduce this later.
You can also try to run the sub shell with explicitly set locales.

LANG=C bash

or

LANG=en_US.UTF-8 bash

respectively.
Also, did you build both locales using locale-gen?
What's its output if you run it?

Last edited by schard (2019-05-17 07:26:14)


Inofficial first vice president of the Rust Evangelism Strike Force

Offline

#7 2019-05-17 07:33:38

Risse
Member
Registered: 2019-05-17
Posts: 8

Re: [SOLVED] Setting the locale in Bash

Hey, localectl was the issue! I ran it, and got this:

[risse@rissedesktop ~]$ localectl status
   System Locale: LANG=en_US.UTF-8
                  LANGUAGE=en_US:en:fi_FI
                  LC_CTYPE=fi_FI.UTF-8
                  LC_NUMERIC=fi_FI.UTF-8
                  LC_TIME=fi_FI.UTF-8
                  LC_COLLATE=fi_FI.UTF-8
                  LC_MONETARY=fi_FI.UTF-8
                  LC_PAPER=fi_FI.UTF-8
                  LC_NAME=fi_FI.UTF-8
                  LC_ADDRESS=fi_FI.UTF-8
                  LC_TELEPHONE=fi_FI.UTF-8
                  LC_MEASUREMENT=fi_FI.UTF-8
                  LC_IDENTIFICATION=fi_FI.UTF-8
       VC Keymap: fi
      X11 Layout: fi

I then ran:

[risse@rissedesktop ~]$ localectl set-locale LANGUAGE=en_US.UTF-8

Restarted the machine, and bash messages seem to be correct now:

[risse@rissedesktop ~]$ asdf
bash: asdf: command not found

Thanks for the help schard!

Last edited by Risse (2019-05-17 07:38:47)

Offline

#8 2019-05-17 07:35:06

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 78,500

Re: [SOLVED] Setting the locale in Bash

locale -a
cat /etc/locale.conf
tr '\0' '\n' < /proc/$$/environ

Edit: ninja'd by OP

Last edited by seth (2019-05-17 07:35:46)

Online

#9 2019-05-17 13:11:04

2ManyDogs
Forum Fellow
Registered: 2012-01-15
Posts: 4,648

Re: [SOLVED] Setting the locale in Bash

Please remember to mark your thread [SOLVED] (edit the title of your first post).

Offline

Board footer

Powered by FluxBB