Locale::TextDomain::OO::Plugin::Expand::Gettext - Additional gettext methods, prefixed with __
$Id: Gettext.pm 651 2017-05-31 18:10:43Z steffenw $
$HeadURL: svn+ssh://steffenw@svn.code.sf.net/p/perl-gettext-oo/code/module/trunk/lib/Locale/TextDomain/OO/Plugin/Expand/Gettext.pm $
1.027
This module provides an additional getext methods for static domain and category handling.
my $loc = Locale::Text::TextDomain::OO->new( plugins => [ qw ( Expand::Gettext ... )], ... );
Optional type formatting or grammar stuff see Locale::Utils::PlaceholderNamed for possible methods.
$loc->expand_gettext->modifier_code($code_ref);
Returns the Locale::Utils::PlaceholderNamed object to be able to set some options.
my $expander_object = $self->expand_gettext;
e.g.
$self->expand_gettext->modifier_code( sub { my ( $value, $attribute ) = @_; if ( $attribute eq 'numf' ) { # modify that numeric $value # e.g. change 1234.56 to 1.234,56 or 1,234.56 ... } elsif ( $attribute eq 'accusative' ) { # modify the string with that grammar rule # e.g. needed for East-European languages # write grammar rules only on msgstr/msgstr_plural[n] # and not on msgid ... } ... return $value; }, );
How to build the method name?
Use __ and append this with "n", "p" and/or "x" in alphabetic order.
.------------------------------------------------------------------------. | Snippet | Description | |---------+--------------------------------------------------------------| | __ | Special marked for extraction. | | n | Using plural forms. | | p | Context is the first parameter. | | x | Last parameters as hash/hash_ref are for named placeholders. | '------------------------------------------------------------------------'
Translate only
print $loc->__( 'Hello World!', );
Expand named placeholders
print $loc->__x( 'Hello {name}!', # hash or hash_ref name => 'Steffen', );
Plural
print $loc->__n( 'one file read', # Singular 'a lot of files read', # Plural $file_count, # number to select the right plural form );
Plural and expand named placeholders
print $loc->__nx( '{count:num} file read', '{count:num} files read', $file_count, # hash or hash_ref count => $file_count, );
{count:num}
{count :num}
That is a attribute. If there is such an attribute like :num and the modifier_code is set, the placeholder value will be modified before replacement.
:num
Think about the attribute names. Too technical names are able to destroy the translation process by translation office stuff.
For better automatic translation use the reserved attribute :num and tag all numeric placeholders.
You are allowed to set multiple attributes like {count :num :numf} The resulting attribute string is then num :numf.
{count :num :numf}
num :numf
Context
print $loc->__p( 'time', # Context 'to', ); print $loc->__p( 'destination', # Context 'to', );
Context and expand named placeholders
print $loc->__px( 'destination', 'from {town_from} to {town_to}', # hash or hash_ref town_from => 'Chemnitz', town_to => 'Erlangen', );
Context and plural
print $loc->__np( 'maskulin', 'Dear friend', 'Dear friends', $friends, );
Context, plural and expand named placeholders
print $loc->__npx( 'maskulin', 'Mr. {name} has {count:num} book.', 'Mr. {name} has {count:num} books.', $book_count, # hash or hash_ref name => $name, count => $book_count, );
Use N__ and append this with "n", "p" and/or "x" in alphabetic order.
The extractor looks for __('... and has no problem with $loc->N__('....
__('...
$loc->N__('...
This is the idea of the N-Methods.
$loc->N__('...'); $loc->N__x('...', ...); ...
Inside of this distribution is a directory named example. Run this *.pl files.
confess
none
Locale::Utils::PlaceholderNamed
Moo::Role
not known
Locale::TextDoamin::OO
Steffen Winkler
Copyright (c) 2009 - 2017, Steffen Winkler <steffenw at cpan.org>. All rights reserved.
<steffenw at cpan.org>
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Locale::TextDomain::OO, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Locale::TextDomain::OO
CPAN shell
perl -MCPAN -e shell install Locale::TextDomain::OO
For more information on module installation, please visit the detailed CPAN module installation guide.