Date: Fri, 13 Mar 2009 16:38:41 +0100 From: =?ISO-8859-1?Q?G=E1bor_K=F6vesd=E1n?= <gabor@FreeBSD.org> To: "Sean C. Farley" <scf@FreeBSD.org> Cc: svn-src-head@FreeBSD.org, svn-src-all@FreeBSD.org, src-committers@FreeBSD.org Subject: Re: svn commit: r189765 - in head: . lib/libc lib/libc/nls Message-ID: <49BA7E01.50000@FreeBSD.org> In-Reply-To: <alpine.BSF.2.00.0903130910540.4522@thor.farley.org> References: <200903131040.n2DAecSO061131@svn.freebsd.org> <alpine.BSF.2.00.0903130910540.4522@thor.farley.org>
next in thread | previous in thread | raw e-mail | index | archive | help
> Nice! I need to find some time to learn how to use NLS. > > Now, you only need to revive the BSD-licensed libiconv[1]. :) I am > kidding; I do not want to start adding more stuff to your plate. > Thank you for strengthening FreeBSD's i18n support. > > Out of curiosity, how does enabling NLS in libc interact with the > devel/gettext port? Well, it's not a bad idea, actually I'm thinking of generating some more catalogs automatically but the problem is that we don't have iconv in the base system. For example, we could easily make a hu_HU.UTF-8 catalog from hu_HU.ISO8859-2 by just converting the encoding of the catalog file. And the same applies to a bunch of locales... I don't really know gettext so I don't know how they can interact. Afaik, gettext is based on some text replacement, while in POSIX.1 NLS, you arrange strings into sets and you identify them with a number inside the sets. Some people think gettext is easier to use but I suspect that it uses a more complex process of building the application itself to process its catalogs. POSIX.1 NLS only needs some additional lines. Here are some code snippets from BSD grep, which uses a single set with 10 messages: grep.h: ================ #ifdef WITHOUT_NLS #define getstr(n) errstr[n] #else #include <nl_types.h> extern nl_catd catalog; #define getstr(n) catgets(catalog, 1, n, errstr[n]) #endif extern char *errstr[]; grep.c: ================ #ifndef WITHOUT_NLS #include <nl_types.h> nl_catd catalog; #endif /* * Default messags to use when NLS is disabled or no catalogue * is found. */ char *errstr[] = { "", /* 1*/ "(standard input)", /* 2*/ "cannot read bzip2 compressed file", /* 3*/ "unknown --color option", /* 4*/ "usage: %s [-abcDEFGHhIiJLlmnOoPqRSsUVvwxZ] [-A num] [-B num] [-C[num]]\n", /* 5*/ "\t[-e pattern] [-f file] [--binary-files=value] [--color=when]\n", /* 6*/ "\t[--context[=num]] [--directories=action] [--label] [--line-buffered]\n", /* 7*/ "\t[--null] [pattern] [file ...]\n", /* 8*/ "unknown --binary-files option", /* 9*/ "Binary file %s matches\n" /*10*/ "%s (BSD grep) %s\n", }; And then you can simply use getstr(n), where n is the number of the string you want to use. It will work with catalogs and with NLS disables, as well. -- Gabor Kovesdan FreeBSD Volunteer EMAIL: gabor@FreeBSD.org .:|:. gabor@kovesdan.org WEB: http://people.FreeBSD.org/~gabor .:|:. http://kovesdan.org
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?49BA7E01.50000>