Locale-Utils-Autotranslator
view release on metacpan or search on metacpan
t/01_autotranslation_utf-8.t view on Meta::CPAN
#!perl
#!perl -T
use strict;
use warnings;
use utf8;
use Moo;
use Path::Tiny qw(path);
use Test::More tests => 4;
use Test::NoWarnings;
use Test::Differences;
extends qw(
Locale::Utils::Autotranslator
);
my $char = 1;
sub translate_text {
my ($self, $msgid) = @_;
return 'text ' . $char++;
}
my $output_filename = './translated de_utf-8.po';
my @debug;
is
__PACKAGE__
->new(
language => 'de',
before_translation_code => sub {
my ($self, $msgid) = @_;
push @debug, sprintf '%s: %s', $self->developer_language, $msgid;
1;
},
after_translation_code => sub {
my ($self, undef, $msgstr) = @_;
push @debug, sprintf '%s: %s', $self->language, $msgstr;
1;
},
)
->translate(
't/LocaleData/untranslated de_utf-8.po',
$output_filename,
)
->translation_count,
11,
'translation count';
my $content = path($output_filename)->slurp_utf8;
unlink $output_filename;
eq_or_diff
[ split m{ \r? \n }xms, $content ],
[ split m{ \n }xms, <<"EOT" ],
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=2; plural=n != 1;\\n"
msgid "Number of %1: %2"
msgstr "text 1"
msgid "Number of {post items}: {count :num}"
msgstr "text 2"
( run in 0.920 second using v1.01-cache-2.11-cpan-5b529ec07f3 )