1Locale::TextDomain::OO:U:sPelrugCioLnno:tc:raEilxbepu:at:neTdde:x:PtGeDerotlmtaeDixontc:(u:3mO)eOn:t:aPtliuognin::Expand::Gettext(3)
2
3
4

NAME

6       Locale::TextDomain::OO::Plugin::Expand::Gettext - Additional gettext
7       methods, prefixed with __
8
9       $Id: Gettext.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.pm
13       $
14

VERSION

16       1.027
17

DESCRIPTION

19       This module provides an additional getext methods for static domain and
20       category handling.
21

SYNOPSIS

23           my $loc = Locale::Text::TextDomain::OO->new(
24               plugins => [ qw (
25                   Expand::Gettext
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->modifier_code($code_ref);
35

SUBROUTINES/METHODS

37   method expand_gettext
38       Returns the Locale::Utils::PlaceholderNamed object to be able to set
39       some options.
40
41           my $expander_object = $self->expand_gettext;
42
43       e.g.
44
45           $self->expand_gettext->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 __ and append this with "n", "p" and/or "x" in alphabetic order.
69
70        .------------------------------------------------------------------------.
71        | Snippet | Description                                                  |
72        |---------+--------------------------------------------------------------|
73        | __      | 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 __
80
81       Translate only
82
83           print $loc->__(
84               'Hello World!',
85           );
86
87       method __x
88
89       Expand named placeholders
90
91           print $loc->__x(
92               'Hello {name}!',
93               # hash or hash_ref
94               name => 'Steffen',
95           );
96
97       method __n
98
99       Plural
100
101           print $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 __nx
108
109       Plural and expand named placeholders
110
111           print $loc->__nx(
112               '{count:num} file read',
113               '{count:num} files read',
114               $file_count,
115               # hash or hash_ref
116               count => $file_count,
117           );
118
119       What is the meaning of "{count:num}" or alternative "{count :num}"?
120
121       That is a attribute.  If there is such an attribute like ":num" and the
122       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 __p
135
136       Context
137
138           print $loc->__p(
139               'time', # Context
140               'to',
141           );
142
143           print $loc->__p(
144               'destination', # Context
145               'to',
146           );
147
148       method __px
149
150       Context and expand named placeholders
151
152           print $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 __np
161
162       Context and plural
163
164           print $loc->__np(
165               'maskulin',
166               'Dear friend',
167               'Dear friends',
168               $friends,
169           );
170
171       method __npx
172
173       Context, plural and expand named placeholders
174
175           print $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 N__ and append this with "n", "p" and/or "x" in alphabetic order.
189
190        .------------------------------------------------------------------------.
191        | Snippet | Description                                                  |
192        |---------+--------------------------------------------------------------|
193        | __      | 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 N__, N__x, N__n, N__nx, N__p, N__px, N__np, N__npx
200
201       The extractor looks for "__('..."  and has no problem with
202       "$loc->N__('...".
203
204       This is the idea of the N-Methods.
205
206           $loc->N__('...');
207           $loc->N__x('...', ...);
208           ...
209

EXAMPLE

211       Inside of this distribution is a directory named example.  Run this
212       *.pl files.
213

DIAGNOSTICS

215       confess
216

CONFIGURATION AND ENVIRONMENT

218       none
219

DEPENDENCIES

221       Locale::Utils::PlaceholderNamed
222
223       Moo::Role
224

INCOMPATIBILITIES

226       not known
227

BUGS AND LIMITATIONS

229       none
230

SEE ALSO

232       Locale::TextDoamin::OO
233

AUTHOR

235       Steffen Winkler
236
238       Copyright (c) 2009 - 2017, Steffen Winkler "<steffenw at cpan.org>".
239       All rights reserved.
240
241       This module is free software; you can redistribute it and/or modify it
242       under the same terms as Perl itself.
243
244
245
246perl v5.32.0                Locale2:0:2T0e-x0t7D-o2m8ain::OO::Plugin::Expand::Gettext(3)
Impressum