Skip Menu |

This queue is for tickets about the libintl-perl CPAN distribution.

Report information
The Basics
Id: 49758
Status: rejected
Priority: 0/
Queue: libintl-perl

People
Owner: GUIDO [...] cpan.org
Requestors: STEFFENW [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: 1.20



Subject: no perl unicode support or the half one only
There is a filter, but it is only an output filter for data from Locale::Messages back to my script. To have a full Perl unicode support I neeed an input filter for msgid, msgid_plural and msgctxt too. I would like to write: ---------------------------------------------------------------------- # bind input filter bind_textdomain_input_filter($text_domain, \&encode_utf8); # bind output filter bind_textdomain_filter($text_domain, \&decode_utf8); ---------------------------------------------------------------------- Here is the full script: ---------------------------------------------------------------------- #!perl -T use strict; use warnings; use utf8; our $VERSION = 0; use Carp qw(croak); use English qw(-no_match_vars $OS_ERROR); use Encode qw(encode_utf8 decode_utf8); require Locale::TextDomain; use Locale::Messages qw(bind_textdomain_filter); local $ENV{LANGUAGE} = 'ru'; my $text_domain = 'test'; # bind text domain Locale::TextDomain->import( $text_domain, qw(./LocaleData) ); # bind output filter bind_textdomain_filter($text_domain, \&decode_utf8); # all unicode chars encode to UTF-8 binmode STDOUT, ':encoding(utf-8)' or croak "Binmode STDOUT\n$OS_ERROR"; # run all translations () = print map {"$_\n"} __( 'book', ), __( encode_utf8('§ book'), ), __n( encode_utf8('§§ book'), encode_utf8('§§ books'), 0, ), __p( encode_utf8('c§'), encode_utf8('c§ book'), ); __END__ Output: книга § книга §§ книг c§ книга ---------------------------------------------------------------------- Here is the po file: ---------------------------------------------------------------------- msgid "" msgstr "" "Project-Id-Version: \n" "POT-Creation-Date: \n" "PO-Revision-Date: \n" "Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n" # utf-8 msgstr msgid "book" msgstr "книга" # utf-8 msgid + msgstr msgid "§ book" msgstr "§ книга" # utf-8 msgid + msgid_plural, msgstr[n] msgid "§§ book" msgid_plural "§§ books" msgstr[0] "§§ книга" msgstr[1] "§§ книги" msgstr[2] "§§ книг" # utf-8 context msgctxt "c§" msgid "c§ book" msgstr "c§ книга" ----------------------------------------------------------------------
I must admit that I don't fully understand your problem. The input to gettext() and friends is the source code of your script. Why would anybody need a filter there? If your problem is really that you use non-ASCII message IDs, don't use them: http://ml.imperia.org/libintl-perl/2005/08/16/6289725913ab0bbaa57235297ed06db9/ or read the summary in the pod to Locale::Messages (search for "Non-ASCII"). This is not a problem specific to the Perl version of gettext. Non-ASCII message IDs are deprecated in general, google for more sources. Besides, an additional input filter would increase the calling overhead. The same holds true for the output filter but that solves a common problem: Gtk-Perl (contrary to other language bindings) re-encodes strings from ISO-8859-1 to UTF-8 unless the utf-8 flag is set. The output filter was the only possible way to work around this ideosyncrasy, fools rush in where angels fear to tread. An additional optional input filter would not solve a _common_ problem. Common usage of gettext goes like this: print __("Hello world!"); The input is the string constant in your script itself. Why filter? Whatever problem you want to solve with such a filter, I don't think that it is a common problem worth the overhead of such a feature. If you really need it, it is trivial to write wrappers around the functions in question. I'm sure you will find another solution for your problem, and will therefore close the ticket. If you have more questions, fee free to re-open it, or just mail me. Cheers, Guido