libintl-perl

Home -> libintl-perl -> 2005 -> August

 Problem with non-ASCII message id's 
Login Login Subscribe Subscribe  Date  08/18/05 08:20:43 GMT
 From  JörnReder
 Subject  Problem with non-ASCII message id's
 Previous Thread
 Next Thread
 Start of Thread
 Reference
 Previous Reply
 This Message
 Reply
 Next Reply
Jörn Reder wrote:

> This way Locale::TextDomain sees
> utf-8 characters only in the message id's and everything should just
> work.

Unfortunately I was wrong with that assumption... :(

I changed my tiny test program to use utf-8 messages consistently, but
Locale::TextDomain obviously has some trouble with the utf-8 flag of the
strings in question...

I changed the xgettext --from-charset back to utf-8 again. Of course
that didn't changed the .po file, since the message id's were utf-8
anyway. Just for the record the interesting portion of my en.po file:

  #: ../test.pl:16
  msgid "Datei öffnen"
  msgstr "Open file"

  #: ../test.pl:17
  msgid "Datei oeffnen"
  msgstr "Open file"

The test program now uses utf-8 message id's:

  use strict;
  use lib 'lib';
  use Locale::TextDomain ("test");

  main: {
    print __"Datei öffnen","\n";
    print __"Datei oeffnen","\n";
  }

These are the test runs: (my terminal is iso-8859-1)

  % LC_MESSAGES="en_US.ISO-8859-1" perl test.pl
  Open file
  Open file

Great. English translation works, but the C mode not:

  % LC_MESSAGES="C" perl test.pl
  Datei öffnen
  Datei oeffnen

Locale::TextDomain misses setting the utf-8 flag on the returned string.
If the utf-8 flag was set, Perl had converted the output to iso-8859-1
when printing to my iso-8859-1 terminal.

Ok, but the test program really should "use utf8", since it contains
utf-8 encoded literals now. I tried that:

  use strict;
  use utf8;
  use lib 'lib';
  use Locale::TextDomain ("test");

  main: {
    print "Datei öffnen","\n";
    print __"Datei öffnen","\n";
    print __"Datei oeffnen","\n";
  }

(the first line should print a correct iso-8859-1 encoded "Datei öffnen"
without any translation, just to prove that Perl's iso-8859-1 STDOUT
recoding works).

These are the results of this program version:

  % LC_MESSAGES="en_US.ISO-8859-1" perl test.pl
  Datei öffnen
  Datei öffnen
  Open file

We see: Perl works as expected, but translation doesn't work anymore.
Why?

  % LC_MESSAGES="C" perl test.pl
  Datei öffnen
  Datei öffnen
  Datei oeffnen

Even passing through in C mode destroys the utf-8 flag, so I get utf-8
characters on my iso-8859-1 terminal.

It looks Locale::TextDomain can't handle utf-8 encoded messages :( In C
mode it always returns strings without the utf-8 flag set, even if the
input had the flag. And translation doesn't work when the input has the
utf-8 flag set, although this should be the right thing if we're
programming consistently with utf-8 and Perl >= 5.8.

Is this behaviour intended, resp it's no bug but a feature I just don't
understand? ;)

Regards,

Joern

--
Think, before you code.
Attachments
 1  +-index.html message/rfc822  

ATTENTION: HTML attachments to this mail have been converted to plain text to prevent you from possibly malicious HTML files. Other attachments are included here without any checking. Choose your own poison! The maintainers of this site cannot be held responsible for any damage caused by these attachments.

 Problem with non-ASCII message id's
 Previous Thread
 Next Thread
 Start of Thread
 Reference
 Previous Reply
 This Message
 Reply
 Next Reply
 
 08/16/05 09:09:12 GMT  JörnReder
 08/16/05 12:58:20 GMT  +--Guido Flohr
 08/16/05 14:01:13 GMT    |--JörnReder
 08/16/05 15:22:33 GMT    |  +--Guido Flohr
 08/17/05 11:00:11 GMT    |    |--JörnReder
 08/18/05 07:30:54 GMT    |    +--JörnReder
 08/18/05 08:20:43 GMT    |      +--JörnReder
 08/18/05 09:05:35 GMT    |        +--Guido Flohr
 08/17/05 08:29:41 GMT    +--Bruno Haible

Powered by Imperia
Home | Top | Imprint