1Locale::TextDomain::OO:U:sLPeolrcuagClioenn::t::rTEiexbxputatDneoddm:a:PiGener:tl:tOeDOxo:tc::uP:mlLeuongcti(an3t:)i:oEnxpand::Gettext::Loc(3)
2
3
4
6 Locale::TextDomain::OO::Plugin::Expand::Gettext::Loc - Additional
7 gettext methods, prefixed with loc_
8
9 $Id: Loc.pm 651 2017-05-31 18:10:43Z steffenw $
10
11 $HeadURL:
12 svn+ssh://steffenw@svn.code.sf.net/p/perl-gettext-oo/code/module/trunk/lib/Locale/TextDomain/OO/Plugin/Expand/Gettext/Loc.pm
13 $
14
16 1.027
17
19 This module provides an additional getext methods for static domain and
20 category handling.
21
23 my $loc = Locale::Text::TextDomain::OO->new(
24 plugins => [ qw (
25 Expand::Gettext::Loc
26 ...
27 )],
28 ...
29 );
30
31 Optional type formatting or grammar stuff see
32 Locale::Utils::PlaceholderNamed for possible methods.
33
34 $loc->expand_gettext_loc->modifier_code($code_ref);
35
37 method expand_gettext_loc
38 Returns the Locale::Utils::PlaceholderNamed object to be able to set
39 some options.
40
41 my $expander_object = $self->expand_gettext_loc;
42
43 e.g.
44
45 $self->expand_gettext_loc->modifier_code(
46 sub {
47 my ( $value, $attribute ) = @_;
48 if ( $attribute eq 'numf' ) {
49 # modify that numeric $value
50 # e.g. change 1234.56 to 1.234,56 or 1,234.56
51 ...
52 }
53 elsif ( $attribute eq 'accusative' ) {
54 # modify the string with that grammar rule
55 # e.g. needed for East-European languages
56 # write grammar rules only on msgstr/msgstr_plural[n]
57 # and not on msgid
58 ...
59 }
60 ...
61 return $value;
62 },
63 );
64
65 translation methods
66 How to build the method name?
67
68 Use loc_ and append this with "n", "p" and/or "x" in alphabetic order.
69
70 .------------------------------------------------------------------------.
71 | Snippet | Description |
72 |---------+--------------------------------------------------------------|
73 | loc_ | Special marked for extraction. |
74 | n | Using plural forms. |
75 | p | Context is the first parameter. |
76 | x | Last parameters as hash/hash_ref are for named placeholders. |
77 '------------------------------------------------------------------------'
78
79 method loc_
80
81 Translate only
82
83 print $loc->loc_(
84 'Hello World!',
85 );
86
87 method loc_x
88
89 Expand named placeholders
90
91 print $loc->loc_x(
92 'Hello {name}!',
93 # hash or hash_ref
94 name => 'Steffen',
95 );
96
97 method loc_n
98
99 Plural
100
101 print $loc->loc_n(
102 'one file read', # Singular
103 'a lot of files read', # Plural
104 $file_count, # number to select the right plural form
105 );
106
107 method loc_nx
108
109 Plural and expand named placeholders
110
111 print $loc->loc_nx(
112 '{count:numf} file read',
113 '{count:numf} files read',
114 $file_count,
115 # hash or hash_ref
116 count => $file_count,
117 );
118
119 What is the meaning of "{count:numf}" or alternative "{count :numf}"?
120
121 That is a attribute. If there is such an attribute like ":numf" and
122 the modifier_code is set, the placeholder value will be modified before
123 replacement.
124
125 Think about the attribute names. Too technical names are able to
126 destroy the translation process by translation office stuff.
127
128 For better automatic translation use the reserved attribute ":num" and
129 tag all numeric placeholders.
130
131 You are allowed to set multiple attributes like "{count :num :numf}"
132 The resulting attribute string is then "num :numf".
133
134 method loc_p
135
136 Context
137
138 print $loc->loc_p(
139 'time', # Context
140 'to',
141 );
142
143 print $loc->loc_p(
144 'destination', # Context
145 'to',
146 );
147
148 method loc_px
149
150 Context and expand named placeholders
151
152 print $loc->loc_px(
153 'destination',
154 'from {town_from} to {town_to}',
155 # hash or hash_ref
156 town_from => 'Chemnitz',
157 town_to => 'Erlangen',
158 );
159
160 method loc_np
161
162 Context and plural
163
164 print $loc->loc_np(
165 'maskulin',
166 'Dear friend',
167 'Dear friends',
168 $friends,
169 );
170
171 method loc_npx
172
173 Context, plural and expand named placeholders
174
175 print $loc->loc_npx(
176 'maskulin',
177 'Mr. {name} has {count:num} book.',
178 'Mr. {name} has {count:num} books.',
179 $book_count,
180 # hash or hash_ref
181 name => $name,
182 count => $book_count,
183 );
184
185 Methods to mark the translation for extraction only
186 How to build the method name?
187
188 Use Nloc_ and append this with "n", "p" and/or "x" in alphabetic order.
189
190 .------------------------------------------------------------------------.
191 | Snippet | Description |
192 |---------+--------------------------------------------------------------|
193 | loc_ | Special marked for extraction. |
194 | n | Using plural forms. |
195 | p | Context is the first parameter. |
196 | x | Last parameters as hash/hash_ref are for named placeholders. |
197 '------------------------------------------------------------------------'
198
199 methods Nloc_, Nloc_x, Nloc_n, Nloc_nx, Nloc_p, Nloc_px, Nloc_np,
200 Nloc_npx
201
202 The extractor looks for "loc_('..." and has no problem with
203 "$loc->Nloc_('...".
204
205 This is the idea of the N-Methods.
206
207 $loc->Nloc_('...');
208 $loc->Nloc_x('...', ...);
209 ...
210
212 Inside of this distribution is a directory named example. Run this
213 *.pl files.
214
216 confess
217
219 none
220
222 Locale::Utils::PlaceholderNamed
223
224 Moo::Role
225
227 not known
228
230 none
231
233 Locale::TextDoamin::OO
234
236 Steffen Winkler
237
239 Copyright (c) 2009 - 2017, Steffen Winkler "<steffenw at cpan.org>".
240 All rights reserved.
241
242 This module is free software; you can redistribute it and/or modify it
243 under the same terms as Perl itself.
244
245
246
247perl v5.28.0 Locale::Tex2t0D1o7m-a0i5n-:3:1OO::Plugin::Expand::Gettext::Loc(3)