On Mon, Oct 02, 2000 at 15:32:20 +0200, Bruno Haible wrote:
> Byrial Jensen writes:
> 
> > +    setlocale (LC_CTYPE, "");
> > +    bind_textdomain_codeset (PACKAGE, nl_langinfo(CODESET));
> > +    bind_textdomain_codeset ("libc", nl_langinfo(CODESET));
> > +    setlocale (LC_CTYPE, "C");
> 
> This will nearly work. But not completely, because glibc's gettext function
> needs the LC_CTYPE locale for the codeset _and_ for the transliteration.
> You are only setting the codeset.

I have now tested the conversions of all libc error strings in all
locales in glibc 2.1.92, and I find no examples where my method
gives another result than if LC_CTYPE was permanently set.

Could you please say where you think that my method can give bad
transliterations?

> Moreover, nl_langinfo is not completely portable. bind_textdomain_codeset
> will also be contained in the next standalone gettext package, thus
> HAVE_BIND_TEXTDOMAIN_CODESET will be true even on old platforms with gettext,
> and your code won't compile.

Well, I will then add a configure test for nl_langinfo(CODESET).

My test programs and test results:

$ cat test_method_1.c
#include <errno.h>
#include <locale.h>
#include <libintl.h>
#include <langinfo.h>
#include <stdio.h>
#include <string.h>

int main ()
{
  int i;
  extern int sys_nerr;

  setlocale (LC_CTYPE, "");
  bind_textdomain_codeset ("libc", nl_langinfo(CODESET));
  setlocale (LC_CTYPE, "C");
  for (i = 1 ; i < sys_nerr ; i ++)
    puts (strerror (i));
  return 0;
}
$ cat test_method_2.c
#include <errno.h>
#include <locale.h>
#include <stdio.h>
#include <string.h>

int main ()
{
  int i;
  extern int sys_nerr;

  setlocale (LC_CTYPE, "");
  for (i = 1 ; i < sys_nerr ; i ++)
    puts (strerror (i));
  return 0;
}
$ cat test_conversion.c
#include <sys/types.h>
#include <dirent.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

int main ()
{
  DIR *dir;
  struct dirent *dirent;
  char cmd[80];

  unsetenv ("LANG");
  unsetenv ("LANGUAGE");
  unsetenv ("LC_ALL");
  unsetenv ("LC_CTYPE");
  unsetenv ("LC_MESSAGES");

  dir = opendir ("/usr/share/locale");
  while ((dirent = readdir (dir)))
  {
    if (strcmp (dirent->d_name, "locale.alias") == 0 ||
        strcmp (dirent->d_name, ".") == 0 ||
        strcmp (dirent->d_name, "..") == 0)
      continue;
    printf ("testing locale %s... ", dirent->d_name);
    setenv ("LC_ALL", dirent->d_name, 1);
    sprintf (cmd, "./test_method_1 > test-%s-1.out", dirent->d_name);
    system (cmd);
    sprintf (cmd, "./test_method_2 > test-%s-2.out", dirent->d_name);
    system (cmd);
    sprintf (cmd, "cmp -s test-%s-1.out test-%s-2.out",
             dirent->d_name, dirent->d_name);
    switch (system (cmd))
    {
    case 0:
      printf ("OK\n");
      break;
    case 1:
      printf ("FAIL - the conversions are different\n");
      break;
    default:
      printf ("Error calling cmp\n");
      break;
    }
  }
  return 0;
}
$ gcc -Wall -static -o test_method_1 test_method_1.c
$ gcc -Wall -o test_method_2 test_method_2.c
$ gcc -Wall -o test_conversion test_conversion.c
$ ./test_conversion
testing locale en_AU... OK
testing locale bg_BG.cp1251... OK
testing locale sp... OK
testing locale cs... OK
testing locale cy... OK
testing locale gd... OK
testing locale de... OK
testing locale de_AT... OK
testing locale gv... OK
testing locale kw... OK
testing locale nn... OK
testing locale gr_GR... OK
testing locale el... OK
testing locale ja_JP.eucJP... OK
testing locale en_GB... OK
testing locale es... OK
testing locale es_ES... OK
testing locale fr... OK
testing locale fr_CA... OK
testing locale gl... OK
testing locale it... OK
testing locale ko... OK
testing locale nl... OK
testing locale no... OK
testing locale pl... OK
testing locale pt_BR... OK
testing locale pt_PT... OK
testing locale ru_RU... OK
testing locale sk... OK
testing locale sr_YU... OK
testing locale sv... OK
testing locale da... OK
testing locale fi... OK
testing locale hu... OK
testing locale id... OK
testing locale is... OK
testing locale ro... OK
testing locale ru... OK
testing locale sl... OK
testing locale sr... OK
testing locale tr... OK
testing locale uk... OK
testing locale ja... OK
testing locale pt... OK
testing locale zh... OK
testing locale et... OK
testing locale ga... OK
testing locale zh_TW.Big5... OK
testing locale wa... OK
testing locale [EMAIL PROTECTED] OK
testing locale br... OK
testing locale ca... OK
testing locale eu... OK
testing locale hr... OK
testing locale es_DO... OK
testing locale es_GT... OK
testing locale es_HN... OK
testing locale es_MX... OK
testing locale es_PA... OK
testing locale es_PE... OK
testing locale es_SV... OK
testing locale lt... OK
testing locale eo... OK
testing locale zh_CN.GB2312... OK
testing locale en_UK... OK
testing locale he... OK
testing locale hs... OK
testing locale mk... OK
testing locale en... OK
testing locale zh_TW... OK
$ 

-- 
Byrial
http://home.worldonline.dk/~byrial/
-
Linux-UTF8:   i18n of Linux on all levels
Archive:      http://mail.nl.linux.org/lists/

Reply via email to