Locales mini-HOWTO: Questions and Answers.

Rate this post

prev-4355715 next-1881276 toc-9266857

This section could grow into a FAQ, but isn’t really one yet.

8.1 msgcat question

I am an user of LINUX, and have written the following test program:


main(int argc, char ** argv)
 nl_catd catd;

 setlocale(LC_MESSAGES, "");
 catd = catopen("msg", MCLoadBySet);
 fprintf(stderr,catgets(catd, 1, 1, "locale message fail\n"));
$ msg.m
$set 1

1 locale message pass\n

If I use absolute path in catopen like catopen("/etc/locale/msg.cat",MCLoadBySet); ,I got the right result. But,if I use above example,catopen return -1 (failure).

8.2 msgcat answer

This question is sort of answered in the previous section, but here is some additional information.

There are a number of valid places where you can put your message catalogs. Even though you may not have NLSPATH explicitly defined in your environment settings it is defined in libc as follows :

$ strings /lib/libc.so.5.4.17 | grep locale | grep %L

so you if you have done one of :

$ export LC_MESSAGES=en_CA
$ export LC_ALL=en_CA
$ export LANG=en_CA

With the NLSPATH above and the specified environment , the catopen("msg", MCLoadBySet); should work if your message catalog has been copied to any one of :


This, however, will not work if you don’t have the en_CA locale installed because the setlocale will fail, and « C » will be substituted for « %L » in the catopen routine ( rather than « en_CA » ).

prev-4355715 next-1881276 toc-9266857

Lire aussi...  Linux Gazette MailBag LG #50