2009/4/26 Peter E Dennis <peter.edwin.den...@gmail.com>

> Thanks for the reply.
>
> > You get this strange squares because your strings don't seem to be having
> > valid UTF-8 characters. Gtk2 is expecting to get UTF-8 strings and what
> has
> > been provided doesn't seem to be too valid. Your perl strings are
> probably
> > not valid UTF-8. This can happen if the mysql driver fails to return
> proper
> > UTF-8 data. If you know the encoding of the database then decode each
> string
> > to UTF-8 as soon as you read them from the mysql database.
> >
>
> I thought my data was already in utf8 format.  I had similar issues
> when connecting with a Perl script from the shell.
> But if I do the following:
>
> #!/usr/bin/perl
> use strict;
> use DBI();
>
Modify your program and add "use warnings;" and check if perl complains
about "wide characters in print".


>
> # Connect to the database.
> my $dbh = DBI->connect("DBI:mysql:database=japanese;host=localhost",
>                                "root", "root",
>                                {'RaiseError' => 1});
>
> # Without this kanji appear as '?' marks.
> my $sth_unicode = $dbh->prepare("SET NAMES utf8");
> $sth_unicode->execute();
>
> # Now retrieve data from the table.
> my $sth = $dbh->prepare("SELECT * FROM vocab LIMIT 5");
> $sth->execute();
> while (my $ref = $sth->fetchrow_hashref()) {
>        print "id = $ref->{'id'}, eng = $ref->{'english'} ";
>        print "kanji = $ref->{'kanji'}\n";
> }
>
Add the following to your loop:
use Endode;
print "is kanji in UTF-8? ", (is_utf8($ref->{'kanji'}, 1) ? 'YES' : 'NO'),
"\n";

Again I initially had issues trying to get the data into the database.
>  I found it was necessary to have the server and the client speaking
> utf8 to each other. So I have in my /etc/my.conf file:
>
> [client]
> default-character-set=utf8
>
> [mysqld]
> default-character-set=utf8
>
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).


> >
> > You can rule out if it's a font issue by copy pasting a valid japanese
> > character into a gtk application (gedit). If you can see the character
> then
> > it's probably not a font issue.
> >>
>
>
> I can type Japanese characters and copy and paste them into a number
> of different apps including gedit.

So it's not a font issue :)



-- 
Emmanuel Rodriguez
_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Reply via email to