Locale::TextDomain::OO::Plugin::Expand::Gettext::Named - Additional gettext methods locn, Nlocn
$Id: Named.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/Named.pm $
1.027
This module provides hash or hash reference based methods.
my $loc = Locale::Text::TextDomain::OO->new( plugins => [ qw ( Expand::Gettext::Named ... )], ... );
Optional type formatting or grammar stuff see Locale::Utils::PlaceholderNamed for possible methods.
$loc->expand_gettext_named->modifier_code($code_ref);
Returns the Locale::Utils::PlaceholderNamed object to be able to set some options.
my $expander_object = $self->expand_gettext_named;
e.g.
$self->expand_gettext_name->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; }, );
The method accepts hash or hash reference parameters.
print $loc->locn( text => 'Hello World!', ); print $loc->locn( { text => 'Hello World!', }, );
print $loc->locn( text => 'Hello {name}!', replace => { name => 'Steffen' }, );
print $loc->locn( plural => { singular => 'one file read', plural => 'a lot of files read', count => $file_count, # number to select the right plural form }, );
print $loc->locn( plural => { singular => '{count:num} file read', plural => '{count:num} files read', count => $file_count, }, replace => { count => $file_count, }, );
{count:numf}
{count :numf}
That is a attribute. If there is such an attribute like :numf and the modifier_code is set, the placeholder value will be modified before replacement.
:numf
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.
:num
You are allowed to set multiple attributes like {count :num :numf} The resulting attribute string is then num :numf.
{count :num :numf}
num :numf
print $loc->locn( context => 'time', text => 'to', ); print $loc->locn( context => 'destination', text => 'to', );
print $loc->locn( context => 'destination', text => 'from {town_from} to {town_to}', replace => { town_from => 'Chemnitz', town_to => 'Erlangen', }, );
print $loc->locn( context => 'maskulin', plural => { singular => 'Dear friend', plural => 'Dear friends', count => $friends, }, );
print $loc->locn( context => 'maskulin', plural => { singular => 'Mr. {name} has {count:num} book.', plural => 'Mr. {name} has {count:num} books.', count => $book_count, }, replace => { name => $name, count => $book_count, }, );
The method name is N prefixed so it results in Nlocn.
The extractor looks for locn(... and has no problem with $loc->Nlocn(....
locn(...
$loc->Nlocn(...
This is the idea of the N-Methods.
my %hash = $loc->Nlocn( ... ); my $hash_ref = $loc->Nlocn( { ... } );
Inside of this distribution is a directory named example. Run this *.pl files.
confess
none
Carp
Hash::Util
Locale::Utils::PlaceholderNamed
Moo::Role
Try::Tiny
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.