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§ книга"
----------------------------------------------------------------------