Locale::Utils::PlaceholderBabelFish - Utils to expand BabelFish palaceholders
$Id: PlaceholderBabelFish.pm 663 2017-07-16 09:59:32Z steffenw $
$HeadURL: svn+ssh://steffenw@svn.code.sf.net/p/perl-gettext-oo/code/Locale-Utils-PlaceholderBabelFish/trunk/lib/Locale/Utils/PlaceholderBabelFish.pm $
0.006
use Locale::Utils::PlaceholderBabelFish; my $obj = Locale::Utils::PlaceholderBabelFish->new( # optional is_strict switch is_strict => 1, # optional modifier code modifier_code => sub { my ( $value, $attribute ) = @_; return $attribute =~ m{ \b numf \b }xms ? format_number($value) : $attribute =~ m{ \b html \b }xms ? encode_entiaccusative($value) : $value; }, # optional plural code plural_code => sub { # the default for English my $n = shift; 0 + ( $n != 1 # en ); }, ); $expanded = $obj->expand_babel_fish($text, $count); $expanded = $obj->expand_babel_fish($text, $arg_ref); $expanded = $obj->expand_babel_fish($text, \%arg_of);
Utils to expand placeholders in BabelFish style.
Placeholders are also extendable with attributes to run the modifier code. That is an extention to BabelFish style.
see SYNOPSIS
If is_strict is false: undef will be converted to q{}. If is_strict is true: no replacement.
$obj->is_strict(1); # boolean true or false;
Implements the html attribute. For plain text messages in HTML the whole message will be escaped. In case of HTML messages the placeholder data have to escaped.
# class method my $modifier_code = Locale::Utils::PlaceholderBabelFish->default_modifier_code; # object method my $modifier_code = $obj->default_modifier_code; # call example $value = $modifier_code->($value, $attributes);
The modifier code handles named attributes to modify the given placeholder value.
If the placeholder name is #{foo:bar} then foo is the placeholder name and bar the attribute name. Space in front of the attribute name is allowed, e.g. #{foo :bar}.
#{foo:bar}
#{foo :bar}
my $code_ref = sub { my ( $value, $attributes ) = @_; return $attributes =~ m{ \b numf \b } ? $value =~ tr{.}{,} : $attribute =~ m{ \b accusative \b }xms ? accusative($value) : $value; }; $obj->modifier_code($code_ref);
To switch off this code - clear them.
$obj->clear_modifier_code;
Expands strings containing BabelFish placeholders.
variables and attributes
#{name} #{name :attr_name}
plural with default count or other name for count
count
((Singular|Plural)) ((Singular|Plural)):other
plural with special count 0
((=0 Zero|Singular|Plural)) ((=0 Zero|Singular|Plural)):other
plural with placeholder
((#{count} Singular|#{count} Plural)) ((#{other} Singular|#{other} Plural)):other
plural with placeholder and attributes
((#{count :attr_name} Singular|#{count} Plural)) ((#{other :attr_name} Singular|#{other} Plural)):other $expanded = $obj->expand_babel_fish($babel_fish_text, $count); $expanded = $obj->expand_babel_fish($babel_fish_text, count => $count); $expanded = $obj->expand_babel_fish($babel_fish_text, { count => $count, key => $value });
Inside of this distribution is a directory named javascript. For more information see: Locale::TextDomain::OO::JavaScript
This script depends on http://jquery.com/.
Inside of this distribution is a directory named example. Run the *.pl files.
none
Carp
List::Util
Moo
MooX::StrictConstructor
MooX::Types::MooseLike
Scalar::Util
namespace::autoclean
not known
https://github.com/nodeca/babelfish
Steffen Winkler
Copyright (c) 2015 - 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::PlaceholderBabelFish, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Locale::Utils::PlaceholderBabelFish
CPAN shell
perl -MCPAN -e shell install Locale::Utils::PlaceholderBabelFish
For more information on module installation, please visit the detailed CPAN module installation guide.