Gtk2, Locale::TextDomain and utf-8 locales

Hash: SHA1


in December 2005 Jörn Reder had described problems using
Locale::TextDomain (part of libintl-perl) with Gtk2, see
for the complete mail.  Basically, he complained about
Locale::TextDomain unconditionally turning off the utf-8 flag of
translated messages.

The issue had been resolved in September 2005 with libintl-perl 1.16,
with the new functions bind_textdomain_filter() and turn_utf_8_on(),
both defined in Locale::Messages.  The first function allows you to
register an output filter function, while the latter provides you a
portable way (independent of the Perl version) of turning the flag on.
Please have a look in the source of Test-Unit-GTestRunner for an example
on how to use the new features.  The relevant part of the code is:

~  use Locale::TextDomain qw (Test-Unit-GTestRunner);
~  use Locale::Messages qw (bind_textdomain_filter
~                           bind_textdomain_codeset
~                           turn_utf_8_on);

~  BEGIN {
~        bind_textdomain_filter 'Test-Unit-GTestRunner', \&turn_utf_8_on;
~        bind_textdomain_codeset 'Test-Unit-GTestRunner', 'utf-8';
~  }

Why all the hassle? Why does libintl-perl not "respect" that utf-8 flag?
The answer is a little off-topic, and therefore I only summarize the

The gettext API does not allow you to portably find out the character
set of a string returned by gettext() (or ngettext, etc.).  It doesn't
even tell you whether a string has actually been translated or not.

On the other hand, the API allows you to enforce a certain output
character set by the use of bind_textdomain_codeset(), a relatively new

Therefore, libintl-perl does the right thing(tm): Since the character
set of the output of gettext() and friends is unknown, the library turns
the utf-8 flag unconditionally off on these strings.  However, if you
have enforced a certain character set, you can override the library by
unconditionally turning the flag on (or use an even smarter filter).

A lot of hassle, but honestly, I don't understand why Gtk2 uses this
flag at all in the first place.  We can perfectly make do without in the
C version, why make a difference in Perl?

- --
Imperia AG, Development
Leyboldstr. 10 - D-50354 Hürth -

Version: GnuPG v1.4.2.2 (GNU/Linux)


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