[root tip] Troubleshooting locale errors

Difficulty: ★☆☆☆☆

Locale Errors

Locale errors are not always obvious and some applications simply stop working without any hints at all - e.g. Gnome Terminal is very sensitive to incorrect configuration of locale.

TL:DR

  1. As root edit the file /etc/locale.gen
  2. Enable the needed locales - including en_US.UTF-8 UTF-8 as fallback.
  3. Rebuild the locale database using the locale-gen script

The Calamares installer adds the locales chosen to the end of /etc/locale.gen so check the bottom of the file before editing - it looks something like this

###
#
# Locales enabled by Calamares
en_US.UTF-8 UTF-8
en_DK.UTF-8 UTF-8
da_DK.UTF-8 UTF-8

General locale configuration

From time to time an update may install locale.gen as locale.gen.pacnew - do not blindly overwrite your existing locale.gen. Before applying the new file - check the locales in use and reapply the configuration after applying the .pacnew file.

If you have been modifying locale and are having locale trouble (:point_right: KDE) it can be difficult to locate the offending setting because scripts and rc configurations can change locale outside the obvious locations.

Locale error message

From my notepad

When you get errors like these examples - it is not obvious what causes it

$ rofi

(process:1628): Rofi-WARNING **: 07:34:43.942: Failed to set locale.
$ sterminal
couldn't read from shell: Input/output error
child exited with status 1
tmux: invalid LC_ALL, LC_CTYPE or LANG

Check your settings

:information_source: Obviously you need to replace the locale with something relevant for your system. I have written this using my system’s locale - en_DK for messages and da_DK for the rest of the system.

Check locale settings

$ localectl      
   System Locale: LANG=en_DK.UTF-8
                  LC_NUMERIC=da_DK.UTF-8
                  LC_TIME=da_DK.UTF-8
                  LC_MONETARY=da_DK.UTF-8
                  LC_PAPER=da_DK.UTF-8
                  LC_NAME=da_DK.UTF-8
                  LC_ADDRESS=da_DK.UTF-8
                  LC_TELEPHONE=da_DK.UTF-8
                  LC_MEASUREMENT=da_DK.UTF-8
                  LC_IDENTIFICATION=da_DK.UTF-8
       VC Keymap: dk-latin1
      X11 Layout: dk
       X11 Model: pc105

Check installed locales

$ locale -a
C
en_DK.utf8
en_US.utf8
POSIX

The installed locales does not match the settings listed by localectl - as you can see the da_DK part is missing.

Fix locale error

It is recommended to use the utf8 version unless you have compelling reasons to select otherwise.

Method 1

Edit /etc/locale.gen and ensure that all in-use locales has been uncommented. For fallback messages enable en_US as well

$ sudo nano /etc/locale.gen
...
#cy_GB ISO-8859-14  
da_DK.UTF-8 UTF-8  
#da_DK ISO-8859-1  
....
#en_CA ISO-8859-1  
en_DK.UTF-8 UTF-8  
#en_DK ISO-8859-1  
...
#en_SG ISO-8859-1  
en_US.UTF-8 UTF-8  
#en_US ISO-8859-1  
...

Method 2

Based on the comment by @nam1962 (see below).

Check if the locale you want to use is available in the locale list (/etc/locale.gen)

$ cat /etc/locale.gen | grep 'da_DK'
#da_DK.UTF-8 UTF-8  
#da_DK ISO-8859-1

Use sed command

  • To enable a locale (uncommenting the line)

    $ sudo sed -i '/en_DK.UTF-8/s/^#//g' /etc/locale.gen
    $ sudo sed -i '/en_US.UTF-8/s/^#//g' /etc/locale.gen
    
  • To disable a locale (aka commenting the locale)

    $ sudo sed -i '/en_DK.UTF-8/s/^/#/g' /etc/locale.gen
    

Rebuild locales

$ sudo locale-gen
Generating locales...
  da_DK.UTF-8... done
  en_DK.UTF-8... done
  en_US.UTF-8... done
Generation complete.

Recheck your locales

$ locale -a      
C
da_DK.utf8
en_DK.utf8
en_US.utf8
POSIX

Verify it works

➜  ~ rofi -r
Rofi is unsure what to show.
Please specify the mode you want to show.

    rofi -show {mode}

The following modi are enabled:
 * window
 * run
 * ssh

The following can be enabled:
 * windowcd
 * drun
 * combi
 * keys

To activate a mode, add it to the list of modi in the modi setting.
17 Likes
I lost the terminal
Locale settings broken again after update
Terminal not opening after updating Manjaro 9th Feb, 2021
[Stable Update] 2020-09-08 - Kernels, Mesa, Browsers, KDE Apps 20.08.1, Systemd, LibreOffice 7.0.1, Deepin
Gnome-terminal won't open
How do I set manjaro language do PT-BR?
[Stable Update] 2021-04-18 - Kernels, Mesa, Wine, Plasma5, KDE Frameworks, LibreOffice, Bluez
[Stable Update] 2021-02-09 - Kernels, Gnome 40-Alpha, KDE Apps 20.12.2, Systemd, Mesa, LibreOffice
Gnome-terminal wont open after update
Localization breakdown
Kwalletmanager, do i need it?
I can't use accents in browsers
Language issue, can't change languange
After installing deno terminal not starting, pulseeffects not detecting audio devices, can't install software
Language settings Issue
[Stable Update] 2021-02-28 - Kernels, Plasma 5.21.1, Frameworks 5.79, Firefox, Thunderbird, Python
Language lost after reboot (German locale)
[Stable Update] 2021-02-19 - Kernels, AMDVLK, Palemoon, Firefox-dev, Firefox, Haskell, Python
Latin keyboard-layouts should display comma on KP_Decimal
Как установить английский интерфейс с поддержкой кирилицы?
Typing quote character with shift now activates accents
Zsh prompt broken after this week update
[SOLVED] Zsh prompt problem/error after update
Zsh prompt broken after this week update
Problem with locale configuration settings
Anyone know how to fix this message?
Gnome Terminal & en_US.UTF-8 UTF-8
After installing Steam from pamac language switches partly to english & terminal can't be opened
Man: can't set the locale; make sure $LC_* and $LANG are correct
After update problem with terminal app and Touchpad
Locales gone wild
Canberra-gtk-module warning
[Stable Update] 2021-04-09 - Kernels, Systemd, Gnome 40 Apps, Mesa 21.0.1, Kernels, Browsers
[Stable Staging Update] 2021-03-17 - Kernels, Plasma, Frameworks, LibreOffice, Firefox, Systemd
Problem tlp.service longtime booting and longtime shutdown - Gnome
[Stable Update] 2021-03-08- Kernels, Plasma 5.21.2, Haskell, Kodi, Grub, KDE-Dev
[Testing Update] 2021-02-05 - Kernels, Gnome 40-Alpha, KDE Apps 20.12.2, Systemd, Mesa, LibreOffice 7.1
Kde locale swedish
No terminal after fresh install
Terminal won't load
[Stable-Staging Update] 2021-04-05 - Kernels, Systemd, Gnome 40 Apps, Mesa 21.0.1, Kernels, Browsers
Unable to change GDM keyboard layout
[Stable Update] 2021-03-18 - Kernels, Plasma, Frameworks, LibreOffice, Firefox, Systemd

Moved to #contributions:Tutorials so it appears at the top instead of all the way at the bottom of #contributions

3 Likes

I have french user I installed, they don’t even know nano exists.

Thus I told them :

sudo sed -i '/en_US.UTF-8/s/^#//g' /etc/locale.gen
sudo sed -i '/fr_FR.UTF-8/s/^#//g' /etc/locale.gen
sudo locale-gen

For other languages, just replace fr_FR with the proper locale

[Edit] to reverse & comment out :
sed -i '/fr_FR.UTF-8/s/^/#/g' /etc/locale.gen
with the proper locale :wink:

4 Likes

Nice idea - I will add it to the guide :slight_smile: thank you.

1 Like

Thank you for praising :wink:

By the way, my checking outcome is a little different :

[meuh@ordi1 ~]$ localectl
   System Locale: LANG=fr_FR.UTF-8
   VC Keymap: fr
  X11 Layout: fr
   X11 Model: pc105
[meuh@ordi1 ~]$ locale -a
C
en_US.utf8
fr_FR.utf8
POSIX
[meuh@ordi1 ~]$
1 Like

2 posts were split to a new topic: Inxi reports locale error

A post was split to a new topic: Locale issues on gnome