{count:numf}
or alternative {count :numf}
?
Locale::TextDomain::OO::Plugin::Expand::Gettext::Named - Additional gettext methods locn, Nlocn
$Id: Named.pm 545 2014-10-30 13:23:00Z steffenw $
1.016
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}
or alternative {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.
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
.
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(...
.
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
Locale::Utils::PlaceholderNamed
not known
none
Steffen Winkler
Copyright (c) 2009 - 2014,
Steffen Winkler
<steffenw at cpan.org>
.
All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.