File: 12ctxt.t

package info (click to toggle)
liblog-report-lexicon-perl 1.12-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 440 kB
  • sloc: perl: 2,673; makefile: 9
file content (103 lines) | stat: -rw-r--r-- 2,730 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env perl
# This tries to use context dependent translations

use warnings;
use strict;

use Test::More;

use Log::Report '12test';   # domain selects table

use File::Spec::Functions qw/catdir/;
use File::Basename        qw/dirname/;
use POSIX                 qw/:locale_h/;

# The test file was produced by the t/11 script, and then filled in by hand

if($^O eq 'openbsd')
{   plan skip_all => "openbsd does not support LC_ALL";
    exit 0;
}

my $got_locale = setlocale LC_ALL, 'en_US.UTF-8';
$got_locale && $got_locale eq 'en_US.UTF-8'
    or plan skip_all => "cannot set an en_US.UTF-8 locale";

plan tests => 16;

use_ok 'Log::Report::Translator::POT';

my $rules =
  { gender  => [ 'male', 'female' ]
  , style   => [ 'informal', 'formal' ]
  };

my $translator = Log::Report::Translator::POT->new(lexicon => (dirname __FILE__));

my $domain = textdomain '12test',
	context_rules => $rules,
	translator    => $translator;

isa_ok $domain, 'Log::Report::Domain', 'recreated';

$domain->setContext('gender=male, style=informal');

#
# Simpelest, no context
#

my $d1 = __x"no context {where}", where => 'here';
is $d1, 'out of context here';

#
# Single context "gender", various parameter formats
#

my $a1 = __x"{name<gender} forgot his key", name => 'Mark';
is $a1, 'Mark forgot his key';

my $a2 = __x"{name<gender} forgot his key", name => 'Cleo', _context => 'gender=female';
is $a2, 'Cleo forgot her key';

my $a3 = __x"{name<gender} forgot his key", name => 'Hillary', _context => {gender =>'female'};
is $a3, 'Hillary forgot her key';

my $a4 = __x"{name<gender} forgot his key", name => 'Piet', _context => {gender => 'male'};
is $a4, 'Piet forgot his key';

#
# Two contexts and count
#

my $b1 = __xn"Dear Sir,{<gender<style}", "Dear Sirs,", 3;
is $b1, 'Hi friends,';

my $b2 = __xn"Dear Sir,{<gender<style}", "Dear Sirs,", 3, _context => 'gender=female';
is $b2, "Hi darlin's,";

my $b3 = __xn"Dear Sir,{<gender<style}", "Dear Sirs,", 3, _context => 'style=formal';
is $b3, 'Dear Sirs,';

my $b4 = __xn"Dear Sir,{<gender<style}", "Dear Sirs,", 3, _context => 'gender=female,style=formal';
is $b4, 'Dear Ladies,';



my $b5 = __xn"Dear Sir,{<gender<style}", "Dear Sirs,", 1;
is $b5, 'Dear friend,';

my $b6 = __xn"Dear Sir,{<gender<style}", "Dear Sirs,", 1, _context => 'gender=female';
is $b6, "Hi love,";

my $b7 = __xn"Dear Sir,{<gender<style}", "Dear Sirs,", 1, _context => 'style=formal';
is $b7, 'Dear Sir,';

my $b8 = __xn"Dear Sir,{<gender<style}", "Dear Sirs,", 1, _context => 'gender=female,style=formal';
is $b8, 'Dear Lady,';


# Context values also available to insert

my $c1 = __x"{name} is a {_context.gender}", name => 'Piet', _context => {gender => 'male'};
is $c1, 'Piet is a male';