svn commit: r189765 - in head: . lib/libc lib/libc/nls
Gábor Kövesdán
gabor at FreeBSD.org
Fri Mar 13 08:38:49 PDT 2009
> 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 at FreeBSD.org .:|:. gabor at kovesdan.org
WEB: http://people.FreeBSD.org/~gabor .:|:. http://kovesdan.org
More information about the svn-src-all
mailing list