Locales mini-HOWTO: Questions and Answers.

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:


--------------------------------------------------------------------
#include 
#include 
#include 
#include 

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"));
 catclose(catd);
}
--------------------------------------------------------------------
$ 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
/etc/locale/%L/%N.cat:/usr/lib/locale/%L/%N.cat:/usr
/lib/locale/%N/%L:/usr/share/locale/%L/%N.cat:/usr/
local/share/locale/%L/%N.cat

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 :


/etc/locale/en_CA/msg.cat
/usr/lib/locale/en_CA/msg.cat
/usr/lib/locale/msg/en_CA
/usr/share/locale/en_CA/msg.cat
/usr/local/share/locale/en_CA/msg.cat

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

READ  The Linux Documentation Project - To Do List - Open Tasks