Bug 37778 - man looks for localized message catalogs by looking for LC_ALL, LC_MESSAGES and LANG in the wrong(?) order.
Bug#: 37778 Product:  Gentoo Linux Version: unspecified Platform: All
OS/Version: Linux Status: RESOLVED Severity: minor Priority: P2
Resolution: FIXED Assigned To: base-system@gentoo.org Reported By: magnus.lind@sverige.nu
Component: Core system
URL: 
Summary: man looks for localized message catalogs by looking for LC_ALL, LC_MESSAGES and LANG in the wrong(?) order.
Keywords:  
Status Whiteboard: 
Opened: 2004-01-10 03:38 0000
Description:   Opened: 2004-01-10 03:38 0000
If there is no message catalog for a given locale, for instance sv_SE, man will
show an annoying message like this:

  Failed to open the message catalog "man" for locale "sv_SE"
  (NLSPATH="/usr/share/locale/%L/%N")

Contrary to what the man manpage seems to indicate, I can't avoid this message
by having man search for english messages by setting LC_MESSAGES to an English
locale.

According to the man manpage LC_MESSAGES can be used to set the locale to use
for messages. If not LC_MESSAGES is set, then man will look for the value of
LANG instead. But currently man operates in the opposite way, looking for LANG
first and then LC_MESSAGES (or LC_ALL, which should override all other LC_*
variables).


Reproducible: Always
Steps to Reproduce:
set LANG to "sv_SE"
set LC_MESSAGES (or LC_ALL) to "en_US" (or any other locale - has no effect)
try to use a man page that doesn't exist
Actual Results:  
Output:
  Failed to open the message catalog "man" for locale "sv_SE"
  (NLSPATH="/usr/share/locale/%L/%N")

  What manual page do you want?


Expected Results:  
Output:
  What manual page do you want?

emerge info output follows:

Portage 2.0.49-r20 (default-x86-1.4, gcc-3.2.3, glibc-2.3.2-r3, 2.4.24)
=================================================================
System uname: 2.4.24 i686 AMD Athlon(tm) processor
Gentoo Base System version 1.4.3.10
ACCEPT_KEYWORDS="x86"
AUTOCLEAN="yes"
CFLAGS="-O3 -march=athlon -funroll-loops -pipe"
CHOST="i686-pc-linux-gnu"
COMPILER="gcc3"
CONFIG_PROTECT="/etc /usr/X11R6/lib/X11/xkb /usr/kde/2/share/config
/usr/kde/3.1/share/config /usr/kde/3/share/config /usr/share/config
/usr/share/texmf/tex/generic/config/ /usr/share/texmf/tex/platex/config/
/var/qmail/control"
CONFIG_PROTECT_MASK="/etc/gconf /etc/env.d"
CXXFLAGS="-O3 -march=athlon -funroll-loops -pipe"
DISTDIR="/usr/portage/distfiles"
FEATURES="autoaddcvs ccache sandbox"
GENTOO_MIRRORS="http://gentoo.oregonstate.edu
http://distro.ibiblio.org/pub/Linux/distributions/gentoo"
MAKEOPTS="-j2"
PKGDIR="/usr/portage/packages"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
PORTDIR_OVERLAY=""
SYNC="rsync://rsync.gentoo.org/gentoo-portage"
USE="X alsa apm arts avi berkdb bonobo cdr crypt cups directfb encode esd
foomaticdb gdbm gif gpm gtk2 imlib java jpeg kde libg++ libwww mad mikmod motif
mozilla mpeg mysql ncurses nls oggvorbis opengl oss pam pdflib perl png
postgres
python qt quicktime readline ruby sdl slang spell ssl svga tcpd tetex truetype
x86 xml2 xmms xv zlib linguas_sv"



Proposed fix - change the order in which man looks for locale related
environment variables to find message catalogs:

--- man-1.5l/src/gripes.c       2002-07-18 02:17:23.000000000 +0200
+++ man-1.5l/src/gripes.c       2004-01-09 22:37:17.000000000 +0100
@@ -41,11 +41,11 @@
               and LANG != "en" (or when debugging). Also accept en_ZA etc. */
            char *s, *lg;
            s = getenv("NLSPATH");
-           lg = getenv("LANG");
+           lg = getenv("LC_ALL");
            if (!lg)
                    lg = getenv("LC_MESSAGES");
            if (!lg)
-                   lg = getenv("LC_ALL");
+                   lg = getenv("LANG");
            if ((s || lg) && (!lg || strncmp(lg, "en", 2))) {
                perror(mantexts);
                fprintf(stderr,

------- Comment #1 From SpanKY 2004-02-08 12:58:12 0000 -------
does this apply to man-1.5m ?

------- Comment #2 From Antti Mäkelä 2004-08-14 03:44:55 0000 -------
Apparently, there is a solution. Man (even version man-1.5m-r1) is broken.
Check out URL 

http://linuxfromscratch.org/pipermail/lfs-support/2003-March/016106.html

I applied the changes, and now 'man' works just fine. 

I'm attaching a new ebuild with the patch that works fine for me. Please test
and integrate into portage tree.

------- Comment #3 From Antti Mäkelä 2004-08-14 03:49:36 0000 -------
Created an attachment (id=37407) [details]
Patch that fixes the catget problem (see comments)

------- Comment #4 From Antti Mäkelä 2004-08-14 03:49:55 0000 -------
Created an attachment (id=37408) [details]
Ebuild that uses the catgets patch

------- Comment #5 From SpanKY 2004-10-03 00:56:54 0000 -------
ok, thanks for doing the footwork :)

fixed in 1.5m-r2