1Locale::Utils::PlaceholUdseerrMaCkoentterxitb(u3t)ed PerLlocDaolceu:m:eUnttialtsi:o:nPlaceholderMaketext(3)
2
3
4
6 Locale::Utils::PlaceholderMaketext - Utils to expand maketext
7 palaceholders
8
9 $Id: PlaceholderMaketext.pm 665 2017-07-16 10:12:00Z steffenw $
10
11 $HeadURL:
12 svn+ssh://steffenw@svn.code.sf.net/p/perl-gettext-oo/code/Locale-Utils-PlaceholderMaketext/trunk/lib/Locale/Utils/PlaceholderMaketext.pm
13 $
14
16 1.005
17
19 use Locale::Utils::PlaceholderMaketext;
20
21 my $obj = Locale::Utils::PlaceholderMaketext->new(
22 # optional is_strict switch
23 is_strict => 1,
24 # optional escape of % to %%
25 is_escape_percent_sign => 1,
26 # optional fromatter code
27 formatter_code => sub { ... },
28 # space between number and singular/plural at function quant
29 space => "\N{NO-BREAK SPACE}",
30 );
31
32 $expanded = $obj->expand_maketext($text, @args);
33 $expanded = $obj->expand_maketext($text, \@args);
34
36 Utils to transform text from maketext to gettext style and reverse.
37 Utils to expand placeholders in maketext or gettext style.
38
39 Locale::Maketext encapsulates the expander. To use the expander in
40 other modules it is not possible. Use this module instead. Use method
41 formatter_code and feel free how to format numerics. Use method sapce
42 to prevent the linebreak bitween number and singular/plural.
43
45 method new
46 see SYNOPSIS
47
48 method maketext_to_gettext
49 Maps maketext strings with
50
51 %
52 [_1]
53 [quant,_2,singular]
54 [quant,_3,singular,plural]
55 [quant,_4,singular,plural,zero]
56 [*,_5,singular]
57 [*,_6,singular,plural]
58 [*,_7,singular,plural,zero]
59
60 inside to
61
62 %%
63 %1
64 %quant(%2,singluar)
65 %quant(%3,singluar,plural)
66 %quant(%4,singluar,plural,zero)
67 %*(%5,singluar)
68 %*(%6,singluar,plural)
69 %*(%7,singluar,plural,zero)
70
71 inside. % to %% depends on is_escape_percent_sign
72
73 $gettext_string = $obj->maketext_to_gettext($maketext_string);
74
75 This method can called as class method too.
76
77 $gettext_string
78 = Locale::Utils::PlaceholderMaketext->maketext_to_gettext($maketext_string);
79
80 method gettext_to_maketext
81 It is the same like method maktetext_to_gettext only the other
82 direction.
83
84 $maketext_string = $obj->gettext_to_maketext($gettext_string);
85
86 This method can called as class method too.
87
88 $maketext_string
89 = Locale::Utils::PlaceholderMaketext->gettext_to_maketext($gettext_string);
90
91 method space, reset_space
92 Set the space bitween number and singular/plural. Prevent the
93 linebreak after the number using no-break space. The default of space
94 is "q{ }".
95
96 $obj->space( "\N{NO-BREAK SPACE}" ); # unicode example
97 $obj->reset_space; # to reset to the default q{ }
98
99 method is_strict
100 If is_strict is true: For normal replacement undef will be converted to
101 q{}. For quant undef will be converted to 0.
102
103 $obj->is_strict(1); # boolean true or false;
104
105 method is_escape_percent_sign
106 If is_ecscpe_percent_sign is true: A single % willbe escaped to %%.
107
108 $obj->is_escape_percent_sign(1); # boolean true or false;
109
110 method formatter_code, clear_formatter_code
111 If it is needed to localize e.g. the numerics than describe this in a
112 code reference.
113
114 my $code_ref = sub {
115 my ($value, $type, $function_name) = @_;
116
117 # $value is never undefined
118 # $type is 'numeric' or 'string'
119 # $function_name is 'quant' or undef
120 ...
121
122 return $value;
123 };
124 $obj->formatter_code($code_ref);
125
126 Than method expand_maketext and expand_gettext will run this code
127 before the substitution of placeholders.
128
129 To switch off this code - clear them.
130
131 $obj->clear_formatter_code;
132
133 method expand_maketext
134 Expands strings containing maketext placeholders.
135
136 maketext style:
137
138 [_1]
139 [quant,_1,singular]
140 [quant,_1,singular,plural]
141 [quant,_1,singular,plural,zero]
142 [*,_1,singular]
143 [*,_1,singular,plural]
144 [*,_1,singular,plural,zero]
145
146 $expanded = $obj->expand_maketext($maketext_text, @args);
147
148 or
149
150 $expanded = $obj->expand_maketext($maketext_text, \@args);
151
152 method expand_gettext
153 Expands strings containing gettext placeholders.
154
155 gettext style:
156
157 %1
158 %quant(%1,singular)
159 %quant(%1,singular,plural)
160 %quant(%1,singular,plural,zero)
161 %*(%1,singular)
162 %*(%1,singular,plural)
163 %*(%1,singular,plural,zero)
164
165 $expanded = $obj->expand_maketext($gettext_text, @args);
166
167 or
168
169 $expanded = $obj->expand_maketext($gettext_text, \@args);
170
172 Inside of this distribution is a directory named example. Run the *.pl
173 files.
174
176 none
177
179 none
180
182 Carp
183
184 Scalar::Util
185
186 Moo
187
188 MooX::StrictConstructor
189
190 MooX::Types::MooseLike
191
192 namespace::autoclean
193
195 not known
196
198 not known
199
201 Locale::Maketext
202
203 <http://en.wikipedia.org/wiki/Gettext>
204
206 Steffen Winkler
207
209 Copyright (c) 2011 - 2017, Steffen Winkler "<steffenw at cpan.org>".
210 All rights reserved.
211
212 This module is free software; you can redistribute it and/or modify it
213 under the same terms as Perl itself.
214
215
216
217perl v5.36.0 2022-07-L2o2cale::Utils::PlaceholderMaketext(3)