Locale:...abelFish(3)
π NAME π
okay bestie, buckle up β this page (from the User Contributed Perl Documentation, no less) is all about Locale::Utils::PlaceholderBabelFish, a module whose whole job is expanding BabelFish placeholders β¨
(and yes, the title at the top got squished down to something like "Locale:...abelFish" β the truncation really said "not today" but we know what it is π )
Also, for the record, these two lines are literally in the source:
$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
$
πΈ VERSION πΈ
0.006 β that's the version, iconique, no notes π
β¨ SYNOPSIS β¨
here's the vibe check, verbatim so you can just copy-paste and go:
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);
like, three whole ways to call expand_babel_fish, pick your fighter π«Ά
π¦ DESCRIPTION π¦
It's utils to expand placeholders in BabelFish style, bestie. That's the whole thing.
But wait, there's more β placeholders are also extendable with attributes so you can run the modifier code on them. That part is an extension to plain BabelFish style, iykyk π₯
π SUBROUTINES/METHODS π
π method new
see SYNOPSIS, babe β it's right up there, go look β¬οΈ
π method is_strict
okay so this one is a little switch that changes EVERYTHING:
- if
is_strictis false βundefgets converted toq{}(empty string, we love a clean slate) - if
is_strictis true β no replacement. none. at all. π
$obj->is_strict(1); # boolean true or false;
π method default_modifier_code
This one implements the html attribute. For plain text messages that live inside HTML, the whole message gets escaped. But in the case of HTML messages, it's the placeholder data that have to be 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);
π method modifier_code, clear_modifier_code
The modifier code is the one that handles named attributes to modify the given placeholder value. main character behaviour honestly.
So if the placeholder name is "#{foo:bar}", then foo is the placeholder name and bar is the attribute name. And a space in front of the attribute name is allowed, like "#{foo :bar}" β generous, we stan πΈ
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);
And if you want this code to not be doing all that? To switch off this code β clear them. β¨
$obj->clear_modifier_code;
π method expand_babel_fish
This is the one. Expands strings containing BabelFish placeholders. π«Ά
variables and attributes
#{name}
#{name :attr_name}
plural with default "count" or other name for 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
and the calls, one more time for the people in the back:
$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 });
π JAVASCRIPT π
Inside of this distribution there's a directory named javascript π For more info, see: Locale::TextDomain::OO::JavaScript
This script depends on <http://jquery.com/> β yeah, jquery, it's giving 2017 and we respect the era π
β EXAMPLE β
Inside of this distribution there's a directory named example. Run the *.pl files. that's it, that's the tip π
π§ DIAGNOSTICS π§
none β nothing to diagnose, we're thriving β¨
πΈ CONFIGURATION AND ENVIRONMENT πΈ
none β zero config, zero drama, the dream honestly π
π DEPENDENCIES π
okay so it needs these besties to function:
CarpList::UtilMooMooX::StrictConstructorMooX::Types::MooseLikeScalar::Utilnamespace::autoclean
π INCOMPATIBILITIES π
not known β no beef detected ποΈ
π BUGS AND LIMITATIONS π
not known β flawless behaviour, allegedly π
π¦ SEE ALSO π¦
π AUTHOR π
Steffen Winkler β the icon behind it all π«Ά
π LICENSE AND COPYRIGHT π
Copyright (c) 2015 - 2017, 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. π
okay and that's a wrap bestie β¨ this page came from the User Contributed Perl Documentation, the module is Locale:...abelFish(3), and it's running on perl v5.42.0 dated 2025-07-25. slay, go expand some placeholders πππ¦
π¦ where this page comes from
- fedora 43: perl-Locale-Utils-PlaceholderBabelFish 0.006-24.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms