[Bug] GRASS won't start for unknown locale
Hello!
GRASS latest version, give the following error message at startup and won't start:
`Failed to enforce user specified language 'bn' with error: 'unsupported locale setting'
A LANGUAGE environmental variable has been set.
Part of messages will be displayed in the requested language.
Starting GRASS GIS...
WARNING: Ignoring unsupported debug level (must be >=0 and <=5): unknown locale: bn
__________ ___ __________ _______________
/ ____/ __ \/ | / ___/ ___/ / ____/ _/ ___/
/ / __/ /_/ / /| | \__ \\_ \ / / __ / / \__ \
/ /_/ / _, _/ ___ |___/ /__/ / / /_/ // / ___/ /
\____/_/ |_/_/ |_/____/____/ \____/___//____/
Welcome to GRASS GIS 8.4.0dev (4d2dac4789)
GRASS GIS homepage: https://grass.osgeo.org
This version running through: Bash Shell (/bin/bash)
Help is available with the command: g.manual -i
See the licence terms with: g.version -c
See citation options with: g.version -x
If required, restart the GUI with: g.gui wxpython
When ready to quit enter: exit
Launching <wxpython> GUI in the background, please wait...
GRASS Italia/PERMANENT:~ > Traceback (most recent call last):
File "/usr/local/grass84/etc/python/grass/script/utils.py", line 163, in _get_encoding
encoding = locale.getencoding()
AttributeError: module 'locale' has no attribute 'getencoding'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/bin/grass", line 2768, in <module>
main()
File "/usr/local/bin/grass", line 2735, in main
gui_process = start_gui(grass_gui)
File "/usr/local/bin/grass", line 1794, in start_gui
if is_debug() or "WX_DEBUG" in gs.gisenv():
File "/usr/local/grass84/etc/python/grass/script/core.py", line 1151, in gisenv
s = read_command("g.gisenv", flags="n", env=env)
File "/usr/local/grass84/etc/python/grass/script/core.py", line 525, in read_command
stdout = _make_unicode(stdout, encoding)
File "/usr/local/grass84/etc/python/grass/script/core.py", line 117, in _make_unicode
return decode(val)
File "/usr/local/grass84/etc/python/grass/script/utils.py", line 193, in decode
enc = _get_encoding()
File "/usr/local/grass84/etc/python/grass/script/utils.py", line 165, in _get_encoding
encoding = locale.getdefaultlocale()[1]
File "/usr/lib/python3.10/locale.py", line 584, in getdefaultlocale
return _parse_localename(localename)
File "/usr/lib/python3.10/locale.py", line 511, in _parse_localename
raise ValueError('unknown locale: %s' % localename)
ValueError: unknown locale: bn
My locales look OK:
$ locale
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC=it_IT.UTF-8
LC_TIME=it_IT.UTF-8
LC_COLLATE="en_US.UTF-8"
LC_MONETARY=it_IT.UTF-8
LC_MESSAGES="en_US.UTF-8"
LC_PAPER=it_IT.UTF-8
LC_NAME=it_IT.UTF-8
LC_ADDRESS=it_IT.UTF-8
LC_TELEPHONE=it_IT.UTF-8
LC_MEASUREMENT=it_IT.UTF-8
LC_IDENTIFICATION=it_IT.UTF-8
LC_ALL=
System description (please complete the following information):
- Operating System:
uname -a Linux ThinkPad-P53 5.15.0-94-generic #104-Ubuntu SMP Tue Jan 9 15:25:40 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux - GRASS GIS version GRASS GIS 8.4.0dev (4d2dac4789)
Thanks
Unless you are testing GRASS in Bengali language, your .grass8/wx.json file most likely is toast. Check its lc_all parameter.
There is nothing wrong with your locale, as the key is user specified language – a language override has been set in the GUI settings.
Not sure what could be the problem, you can try debug with (both outside and in GRASS session):
printenv
python -c "import locale; print(locale.getdefaultlocale())"
(I also see you have set DEBUG level out of the 0-5 range WARNING: Ignoring unsupported debug level (must be >=0 and <=5): but that shouldn't have anything to do with the problem).
Not sure what could be the problem, you can try debug with (both outside and in GRASS session):
There is also an legit error in the code – locale.getdefaultlocale can rise a ValueError and thus failback to UTF-8 will not work. Thus this is a code shortcoming exposed by a (most likely) erroneous settings file.
Test: LC_ALL=wrong python3 -c "import locale; print(locale.getdefaultlocale())"
Could @madi post command locale -a output from the emulator terminal, please?
Could @madi post command
locale -aoutput from the emulator terminal, please?
locale -a C C.utf8 en_AG en_AG.utf8 en_AU.utf8 en_BW.utf8 en_CA.utf8 en_DK.utf8 en_GB.utf8 en_HK.utf8 en_IE.utf8 en_IL en_IL.utf8 en_IN en_IN.utf8 en_NG en_NG.utf8 en_NZ.utf8 en_PH.utf8 en_SG.utf8 en_US.utf8 en_ZA.utf8 en_ZM en_ZM.utf8 en_ZW.utf8 it_CH.utf8 it_IT.utf8 POSIX
LC_ALL=wrong python3 -c "import locale; print(locale.getdefaultlocale())"
LC_ALL=wrong python3 -c "import locale; print(locale.getdefaultlocale())"
Traceback (most recent call last):
File "
printenv python -c "import locale; print(locale.getdefaultlocale())"
printenv python -c "import locale; print(locale.getdefaultlocale())" SHELL=/bin/bash SESSION_MANAGER=local/ThinkPad-P53:@/tmp/.ICE-unix/2790,unix/ThinkPad-P53:/tmp/.ICE-unix/2790 QT_ACCESSIBILITY=1 COLORTERM=truecolor XDG_CONFIG_DIRS=/etc/xdg/xdg-ubuntu:/etc/xdg SSH_AGENT_LAUNCHER=gnome-keyring XDG_MENU_PREFIX=gnome- JDK_HOME=/usr/lib/jvm/java-8-openjdk-amd64 GNOME_DESKTOP_SESSION_ID=this-is-deprecated GTK_IM_MODULE=ibus LC_ADDRESS=it_IT.UTF-8 JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 GNOME_SHELL_SESSION_MODE=ubuntu LC_NAME=it_IT.UTF-8 SSH_AUTH_SOCK=/run/user/1000/keyring/ssh XMODIFIERS=@im=ibus DESKTOP_SESSION=ubuntu LC_MONETARY=it_IT.UTF-8 SNAP_HOME=/home/madi/src/esa-snappy/src/main/resources/ GTK_MODULES=gail:atk-bridge PWD=/home/madi LOGNAME=madi XDG_SESSION_DESKTOP=ubuntu XDG_SESSION_TYPE=x11 GPG_AGENT_INFO=/run/user/1000/gnupg/S.gpg-agent:0:1 SYSTEMD_EXEC_PID=2813 XAUTHORITY=/run/user/1000/gdm/Xauthority WINDOWPATH=2 HOME=/home/madi USERNAME=madi IM_CONFIG_PHASE=1 LC_PAPER=it_IT.UTF-8 LANG=en_US.UTF-8 LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:.tar=01;31:.tgz=01;31:.arc=01;31:.arj=01;31:.taz=01;31:.lha=01;31:.lz4=01;31:.lzh=01;31:.lzma=01;31:.tlz=01;31:.txz=01;31:.tzo=01;31:.t7z=01;31:.zip=01;31:.z=01;31:.dz=01;31:.gz=01;31:.lrz=01;31:.lz=01;31:.lzo=01;31:.xz=01;31:.zst=01;31:.tzst=01;31:.bz2=01;31:.bz=01;31:.tbz=01;31:.tbz2=01;31:.tz=01;31:.deb=01;31:.rpm=01;31:.jar=01;31:.war=01;31:.ear=01;31:.sar=01;31:.rar=01;31:.alz=01;31:.ace=01;31:.zoo=01;31:.cpio=01;31:.7z=01;31:.rz=01;31:.cab=01;31:.wim=01;31:.swm=01;31:.dwm=01;31:.esd=01;31:.jpg=01;35:.jpeg=01;35:.mjpg=01;35:.mjpeg=01;35:.gif=01;35:.bmp=01;35:.pbm=01;35:.pgm=01;35:.ppm=01;35:.tga=01;35:.xbm=01;35:.xpm=01;35:.tif=01;35:.tiff=01;35:.png=01;35:.svg=01;35:.svgz=01;35:.mng=01;35:.pcx=01;35:.mov=01;35:.mpg=01;35:.mpeg=01;35:.m2v=01;35:.mkv=01;35:.webm=01;35:.webp=01;35:.ogm=01;35:.mp4=01;35:.m4v=01;35:.mp4v=01;35:.vob=01;35:.qt=01;35:.nuv=01;35:.wmv=01;35:.asf=01;35:.rm=01;35:.rmvb=01;35:.flc=01;35:.avi=01;35:.fli=01;35:.flv=01;35:.gl=01;35:.dl=01;35:.xcf=01;35:.xwd=01;35:.yuv=01;35:.cgm=01;35:.emf=01;35:.ogv=01;35:.ogx=01;35:.aac=00;36:.au=00;36:.flac=00;36:.m4a=00;36:.mid=00;36:.midi=00;36:.mka=00;36:.mp3=00;36:.mpc=00;36:.ogg=00;36:.ra=00;36:.wav=00;36:.oga=00;36:.opus=00;36:.spx=00;36:.xspf=00;36: XDG_CURRENT_DESKTOP=ubuntu:GNOME VTE_VERSION=6800 GNOME_TERMINAL_SCREEN=/org/gnome/Terminal/screen/93b934d3_224e_4dfb_a718_83a391b23af0 LESSCLOSE=/usr/bin/lesspipe %s %s XDG_SESSION_CLASS=user TERM=xterm-256color LC_IDENTIFICATION=it_IT.UTF-8 LESSOPEN=| /usr/bin/lesspipe %s USER=madi GNOME_TERMINAL_SERVICE=:1.105 DISPLAY=:1 SHLVL=1 LC_TELEPHONE=it_IT.UTF-8 QT_IM_MODULE=ibus LC_MEASUREMENT=it_IT.UTF-8 LD_LIBRARY_PATH=/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so: XDG_RUNTIME_DIR=/run/user/1000 LC_TIME=it_IT.UTF-8 XDG_DATA_DIRS=/usr/share/ubuntu:/usr/share/gnome:/usr/local/share/:/usr/share/:/var/lib/snapd/desktop PATH=/home/madi/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin GDMSESSION=ubuntu DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus LC_NUMERIC=it_IT.UTF-8 _=/usr/bin/printenv ('en_US', 'UTF-8')
What will be happened if @madi manually edit $EDITOR $HOME/.grass8/wx.json and change lang locale lc_all from bn to en, and then try to launch GRASS GIS again please?
"language": {
"locale": {
"lc_all": "en"
}
},
What will be happened if @madi manually edit
$EDITOR $HOME/.grass8/wx.jsonand change lang locale lc_all from bn to en, and then try to launch GRASS GIS again please?"language": { "locale": { "lc_all": "en" } },
It worked. Thank you! Closing the issue and thanks to all!
Reopening as better handling of unknown locales needs to be implemented.
Under my distribution Gentoo GNU/Linux I have enabled these locales:
tomas@gentoo-gnu-linux:~$ locale -a
C
cs_CZ
cs_CZ.iso88592
cs_CZ.utf8
C.utf8
en_US
en_US.iso88591
en_US.utf8
POSIX
sk_SK
sk_SK.iso88592
sk_SK.utf8
Current locale settings
tomas@gentoo-gnu-linux:~$ locale
LANG=en_US.utf8
LC_CTYPE="en_US.utf8"
LC_NUMERIC="en_US.utf8"
LC_TIME="en_US.utf8"
LC_COLLATE="en_US.utf8"
LC_MONETARY="en_US.utf8"
LC_MESSAGES="en_US.utf8"
LC_PAPER="en_US.utf8"
LC_NAME="en_US.utf8"
LC_ADDRESS="en_US.utf8"
LC_TELEPHONE="en_US.utf8"
LC_MEASUREMENT="en_US.utf8"
LC_IDENTIFICATION="en_US.utf8"
LC_ALL=
When I change GRASS GIS lang to bn (via GUI settings) and relaunch GRASS GIS, I get
- CLI warning message Failed to enforce user specified language 'bn' with error: 'unsupported locale setting' A LANGUAGE environmental variable has been set.
tomas@gentoo-gnu-linux:~$ grass
Failed to enforce user specified language 'bn' with error: 'unsupported locale setting'
A LANGUAGE environmental variable has been set.
Part of messages will be displayed in the requested language.
Starting GRASS GIS...
__________ ___ __________ _______________
/ ____/ __ \/ | / ___/ ___/ / ____/ _/ ___/
/ / __/ /_/ / /| | \__ \\_ \ / / __ / / \__ \
/ /_/ / _, _/ ___ |___/ /__/ / / /_/ // / ___/ /
\____/_/ |_/_/ |_/____/____/ \____/___//____/
Welcome to GRASS GIS 8.4.0dev (f01e1ba3f)
GRASS GIS homepage: https://grass.osgeo.org
This version running through: Bash Shell (/bin/bash)
Help is available with the command: g.manual -i
See the licence terms with: g.version -c
See citation options with: g.version -x
Start the GUI with: g.gui wxpython
When ready to quit enter: exit
GRASS nc_basic_spm_grass7/PERMANENT:~ >
- GUI show warning message Cannot set locale to language "".
@madi
$ locale -a | grep bn
bn_BD
bn_IN
I think the locale should be either bn_BD or bn_IN.
$ LC_CTYPE=bn_BD.UTF-8 strace grass --text 2> /dev/stdout | grep /bn/.*grass.*mo
newfstatat(AT_FDCWD, "/usr/local/src/grass/dist.x86_64-pc-linux-gnu/locale/bn/LC_MESSAGES/grasslibs.mo", {st_mode=S_IFREG|0644, st_size=2405, ...}, 0) = 0
openat(AT_FDCWD, "/usr/local/src/grass/dist.x86_64-pc-linux-gnu/locale/bn/LC_MESSAGES/grasslibs.mo", O_RDONLY|O_CLOEXEC) = 3
newfstatat(AT_FDCWD, "/usr/local/src/grass/dist.x86_64-pc-linux-gnu/locale/bn/LC_MESSAGES/grasslibs.mo", {st_mode=S_IFREG|0644, st_size=2405, ...}, 0) = 0
newfstatat(AT_FDCWD, "/usr/local/src/grass/dist.x86_64-pc-linux-gnu/locale/bn/LC_MESSAGES/grassmods.mo", {st_mode=S_IFREG|0644, st_size=395, ...}, 0) = 0
openat(AT_FDCWD, "/usr/local/src/grass/dist.x86_64-pc-linux-gnu/locale/bn/LC_MESSAGES/grassmods.mo", O_RDONLY|O_CLOEXEC) = 3
newfstatat(AT_FDCWD, "/usr/local/src/grass/dist.x86_64-pc-linux-gnu/locale/bn/LC_MESSAGES/grasswxpy.mo", {st_mode=S_IFREG|0644, st_size=2825, ...}, 0) = 0
openat(AT_FDCWD, "/usr/local/src/grass/dist.x86_64-pc-linux-gnu/locale/bn/LC_MESSAGES/grasswxpy.mo", O_RDONLY|O_CLOEXEC) = 3
$ LC_CTYPE=bn_IN.UTF-8 strace grass --text 2> /dev/stdout | grep /bn/.*grass.*mo
newfstatat(AT_FDCWD, "/usr/local/src/grass/dist.x86_64-pc-linux-gnu/locale/bn/LC_MESSAGES/grasslibs.mo", {st_mode=S_IFREG|0644, st_size=2405, ...}, 0) = 0
openat(AT_FDCWD, "/usr/local/src/grass/dist.x86_64-pc-linux-gnu/locale/bn/LC_MESSAGES/grasslibs.mo", O_RDONLY|O_CLOEXEC) = 3
newfstatat(AT_FDCWD, "/usr/local/src/grass/dist.x86_64-pc-linux-gnu/locale/bn/LC_MESSAGES/grasslibs.mo", {st_mode=S_IFREG|0644, st_size=2405, ...}, 0) = 0
newfstatat(AT_FDCWD, "/usr/local/src/grass/dist.x86_64-pc-linux-gnu/locale/bn/LC_MESSAGES/grassmods.mo", {st_mode=S_IFREG|0644, st_size=395, ...}, 0) = 0
openat(AT_FDCWD, "/usr/local/src/grass/dist.x86_64-pc-linux-gnu/locale/bn/LC_MESSAGES/grassmods.mo", O_RDONLY|O_CLOEXEC) = 3
newfstatat(AT_FDCWD, "/usr/local/src/grass/dist.x86_64-pc-linux-gnu/locale/bn/LC_MESSAGES/grasswxpy.mo", {st_mode=S_IFREG|0644, st_size=2825, ...}, 0) = 0
openat(AT_FDCWD, "/usr/local/src/grass/dist.x86_64-pc-linux-gnu/locale/bn/LC_MESSAGES/grasswxpy.mo", O_RDONLY|O_CLOEXEC) = 3
$ LC_CTYPE=bn.UTF-8 strace grass --text 2> /dev/stdout | grep /bn/.*grass.*mo
$ LC_CTYPE=bn strace grass --text 2> /dev/stdout | grep /bn/.*grass.*mo
Those locales pick up the translation files, but the language is not really translated much.
# translated
$ grep 'msgstr "[^"]' *bn*.po | sed 's/.*://' | wc -l
58
# not translated
$ grep 'msgstr ""' *bn*.po | sed 's/.*://' | wc -l
18750
@madi does this problem persist with GRASS GIS 8.4.0RC1?
@madi does this problem persist with GRASS GIS 8.4.0RC1?
Markus, there is no more problem for Madi, it is only now left to make GRASS startup code more robust to not fail if GRASS settings file is toast. Thus this bug should only be closed from a PR.