Locale::Utils::PlaceholderMaketext - Utils to expand maketext palaceholders
$Id: PlaceholderMaketext.pm 665 2017-07-16 10:12:00Z steffenw $
$HeadURL: svn+ssh://steffenw@svn.code.sf.net/p/perl-gettext-oo/code/Locale-Utils-PlaceholderMaketext/trunk/lib/Locale/Utils/PlaceholderMaketext.pm $
1.005
use Locale::Utils::PlaceholderMaketext; my $obj = Locale::Utils::PlaceholderMaketext->new( # optional is_strict switch is_strict => 1, # optional escape of % to %% is_escape_percent_sign => 1, # optional fromatter code formatter_code => sub { ... }, # space between number and singular/plural at function quant space => "\N{NO-BREAK SPACE}", ); $expanded = $obj->expand_maketext($text, @args); $expanded = $obj->expand_maketext($text, \@args);
Utils to transform text from maketext to gettext style and reverse. Utils to expand placeholders in maketext or gettext style.
Locale::Maketext encapsulates the expander. To use the expander in other modules it is not possible. Use this module instead. Use method formatter_code and feel free how to format numerics. Use method sapce to prevent the linebreak bitween number and singular/plural.
see SYNOPSIS
Maps maketext strings with
% [_1] [quant,_2,singular] [quant,_3,singular,plural] [quant,_4,singular,plural,zero] [*,_5,singular] [*,_6,singular,plural] [*,_7,singular,plural,zero]
inside to
%% %1 %quant(%2,singluar) %quant(%3,singluar,plural) %quant(%4,singluar,plural,zero) %*(%5,singluar) %*(%6,singluar,plural) %*(%7,singluar,plural,zero)
inside. % to %% depends on is_escape_percent_sign
$gettext_string = $obj->maketext_to_gettext($maketext_string);
This method can called as class method too.
$gettext_string = Locale::Utils::PlaceholderMaketext->maketext_to_gettext($maketext_string);
It is the same like method maktetext_to_gettext only the other direction.
$maketext_string = $obj->gettext_to_maketext($gettext_string);
$maketext_string = Locale::Utils::PlaceholderMaketext->gettext_to_maketext($gettext_string);
Set the space bitween number and singular/plural. Prevent the linebreak after the number using no-break space. The default of space is q{ }.
q{ }
$obj->space( "\N{NO-BREAK SPACE}" ); # unicode example $obj->reset_space; # to reset to the default q{ }
If is_strict is true: For normal replacement undef will be converted to q{}. For quant undef will be converted to 0.
$obj->is_strict(1); # boolean true or false;
If is_ecscpe_percent_sign is true: A single % willbe escaped to %%.
$obj->is_escape_percent_sign(1); # boolean true or false;
If it is needed to localize e.g. the numerics than describe this in a code reference.
my $code_ref = sub { my ($value, $type, $function_name) = @_; # $value is never undefined # $type is 'numeric' or 'string' # $function_name is 'quant' or undef ... return $value; }; $obj->formatter_code($code_ref);
Than method expand_maketext and expand_gettext will run this code before the substitution of placeholders.
To switch off this code - clear them.
$obj->clear_formatter_code;
Expands strings containing maketext placeholders.
maketext style:
[_1] [quant,_1,singular] [quant,_1,singular,plural] [quant,_1,singular,plural,zero] [*,_1,singular] [*,_1,singular,plural] [*,_1,singular,plural,zero] $expanded = $obj->expand_maketext($maketext_text, @args);
or
$expanded = $obj->expand_maketext($maketext_text, \@args);
Expands strings containing gettext placeholders.
gettext style:
%1 %quant(%1,singular) %quant(%1,singular,plural) %quant(%1,singular,plural,zero) %*(%1,singular) %*(%1,singular,plural) %*(%1,singular,plural,zero) $expanded = $obj->expand_maketext($gettext_text, @args);
$expanded = $obj->expand_maketext($gettext_text, \@args);
Inside of this distribution is a directory named example. Run the *.pl files.
none
Carp
Scalar::Util
Moo
MooX::StrictConstructor
MooX::Types::MooseLike
namespace::autoclean
not known
Locale::Maketext
http://en.wikipedia.org/wiki/Gettext
Steffen Winkler
Copyright (c) 2011 - 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::Utils::PlaceholderMaketext, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Locale::Utils::PlaceholderMaketext
CPAN shell
perl -MCPAN -e shell install Locale::Utils::PlaceholderMaketext
For more information on module installation, please visit the detailed CPAN module installation guide.