Locale:...abelFish(3)

πŸ“¦
version 0.006 Β· 2 versions
, in fedora 43

πŸ’– 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_strict is false β†’ undef gets converted to q{} (empty string, we love a clean slate)
  • if is_strict is 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:

  • Carp
  • List::Util
  • Moo
  • MooX::StrictConstructor
  • MooX::Types::MooseLike
  • Scalar::Util
  • namespace::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 🫢


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