Re: Display Japanese Characters in GtkComboBox





On Mon, Apr 27, 2009 at 7:34 AM, Peter E Dennis <peter edwin dennis gmail com> wrote:
> Modify your program and add "use warnings;" and check if perl complains
> about "wide characters in print".

Did this but no warnings about 'wide characters in print'.

> Add the following to your loop:
> use Endode;
> print "is kanji in UTF-8? ", (is_utf8($ref->{'kanji'}, 1) ? 'YES' : 'NO'),
> "\n";

This was interesting. ÂIt says that all of the kanji:
is kanji in UTF-8? NO

Is there a way I can determine what encoding they are in?
I'm afraid that there's no way to tell that's why a program has to "decode" the strings for perl. The reason is that the programmer should know where the input came from and the encoding. In this particular case mysql might be able to tell your in which encoding the strings are. I don't use mysql so I can't tell you if it's possible.


> I'm afraid that this will only affect the low level communication between
> the mysql.so library and the server. What's important for your application
> is that the perl string are marked as being valid UTF-8 (perl strings have
> an internal flag for this purpose).

Thanks for this info. ÂWasn't really sure if it would have any
relevance but thought I should include it.

Apart from finding out what the actual encoding is I have been able to
display the kanji in the GtkComboBox by doing the following:

 Âwhile (my $ref = $sth->fetchrow_hashref)
 Â{
   Âmy $string = decode("utf8", $ref->{'kanji'});
  .....
  }

Although I'd much prefer to know what encoding it actually is in, as
no doubt I'll hit similar problems when I start trying to insert
data...
In theory inserting data shouldn't cause a problem because you are inserting a perl string which is either utf8 or not (perl knows). In practice, your string came mostlikely from an external source (file, URL, database) in that case when the input as read perl wasn't aware of the input type (binrary string? utf8?). The best is to always encode/decode all I/O, if you are dealing with text perl will want to store the data as UTF-8 so it needs to be instructed how to do it.

--
Emmanuel Rodriguez


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]