1Locale::Utils::PlaceholUdseerrBaCboenltFriisbhu(t3e)d PeLrolcaDloec:u:mUetnitlast:i:oPnlaceholderBabelFish(3)
2
3
4

NAME

6       Locale::Utils::PlaceholderBabelFish - Utils to expand BabelFish
7       palaceholders
8
9       $Id: PlaceholderBabelFish.pm 663 2017-07-16 09:59:32Z steffenw $
10
11       $HeadURL:
12       svn+ssh://steffenw@svn.code.sf.net/p/perl-gettext-oo/code/Locale-Utils-PlaceholderBabelFish/trunk/lib/Locale/Utils/PlaceholderBabelFish.pm
13       $
14

VERSION

16       0.006
17

SYNOPSIS

19           use Locale::Utils::PlaceholderBabelFish;
20
21           my $obj = Locale::Utils::PlaceholderBabelFish->new(
22               # optional is_strict switch
23               is_strict => 1,
24               # optional modifier code
25               modifier_code => sub {
26                   my ( $value, $attribute ) = @_;
27                   return
28                       $attribute =~ m{ \b numf \b }xms
29                       ? format_number($value)
30                       : $attribute =~ m{ \b html \b }xms
31                       ? encode_entiaccusative($value)
32                       : $value;
33               },
34               # optional plural code
35               plural_code => sub { # the default for English
36                   my $n = shift;
37                   0 + (
38                       $n != 1 # en
39                   );
40               },
41           );
42
43           $expanded = $obj->expand_babel_fish($text, $count);
44           $expanded = $obj->expand_babel_fish($text, $arg_ref);
45           $expanded = $obj->expand_babel_fish($text, \%arg_of);
46

DESCRIPTION

48       Utils to expand placeholders in BabelFish style.
49
50       Placeholders are also extendable with attributes to run the modifier
51       code.  That is an extention to BabelFish style.
52

SUBROUTINES/METHODS

54   method new
55       see SYNOPSIS
56
57   method is_strict
58       If is_strict is false: undef will be converted to q{}.  If is_strict is
59       true: no replacement.
60
61           $obj->is_strict(1); # boolean true or false;
62
63   method default_modifier_code
64       Implements the html attribute.  For plain text messages in HTML the
65       whole message will be escaped.  In case of HTML messages the
66       placeholder data have to escaped.
67
68           # class method
69           my $modifier_code = Locale::Utils::PlaceholderBabelFish->default_modifier_code;
70           # object method
71           my $modifier_code = $obj->default_modifier_code;
72
73           # call example
74           $value = $modifier_code->($value, $attributes);
75
76   method modifier_code, clear_modifier_code
77       The modifier code handles named attributes to modify the given
78       placeholder value.
79
80       If the placeholder name is "#{foo:bar}" then foo is the placeholder
81       name and bar the attribute name.  Space in front of the attribute name
82       is allowed, e.g. "#{foo :bar}".
83
84           my $code_ref = sub {
85               my ( $value, $attributes ) = @_;
86               return
87                   $attributes =~ m{ \b numf \b }
88                   ? $value =~ tr{.}{,}
89                   : $attribute =~ m{ \b accusative \b }xms
90                   ? accusative($value)
91                   : $value;
92           };
93           $obj->modifier_code($code_ref);
94
95       To switch off this code - clear them.
96
97           $obj->clear_modifier_code;
98
99   method expand_babel_fish
100       Expands strings containing BabelFish placeholders.
101
102       variables and attributes
103
104           #{name}
105           #{name :attr_name}
106
107       plural with default "count" or other name for count
108
109           ((Singular|Plural))
110           ((Singular|Plural)):other
111
112       plural with special count 0
113
114           ((=0 Zero|Singular|Plural))
115           ((=0 Zero|Singular|Plural)):other
116
117       plural with placeholder
118
119           ((#{count} Singular|#{count} Plural))
120           ((#{other} Singular|#{other} Plural)):other
121
122       plural with placeholder and attributes
123
124           ((#{count :attr_name} Singular|#{count} Plural))
125           ((#{other :attr_name} Singular|#{other} Plural)):other
126
127           $expanded = $obj->expand_babel_fish($babel_fish_text, $count);
128           $expanded = $obj->expand_babel_fish($babel_fish_text, count => $count);
129           $expanded = $obj->expand_babel_fish($babel_fish_text, { count => $count, key => $value });
130

JAVASCRIPT

132       Inside of this distribution is a directory named javascript.  For more
133       information see: Locale::TextDomain::OO::JavaScript
134
135       This script depends on <http://jquery.com/>.
136

EXAMPLE

138       Inside of this distribution is a directory named example.  Run the *.pl
139       files.
140

DIAGNOSTICS

142       none
143

CONFIGURATION AND ENVIRONMENT

145       none
146

DEPENDENCIES

148       Carp
149
150       List::Util
151
152       Moo
153
154       MooX::StrictConstructor
155
156       MooX::Types::MooseLike
157
158       Scalar::Util
159
160       namespace::autoclean
161

INCOMPATIBILITIES

163       not known
164

BUGS AND LIMITATIONS

166       not known
167

SEE ALSO

169       <https://github.com/nodeca/babelfish>
170

AUTHOR

172       Steffen Winkler
173
175       Copyright (c) 2015 - 2017, Steffen Winkler "<steffenw at cpan.org>".
176       All rights reserved.
177
178       This module is free software; you can redistribute it and/or modify it
179       under the same terms as Perl itself.
180
181
182
183perl v5.30.0                      2019-07L-o2c6ale::Utils::PlaceholderBabelFish(3)
Impressum