Locale:...::Named(3)
β¨ NAME β¨
okay so bestie, meet Locale::TextDomain::OO::Plugin::Expand::Gettext::Named β it's the plugin that adds extra gettext methods locn and Nlocn to your life π (yes the "Named" in the module name means named placeholders, she's very on-brand)
the manual we're reading lives in section 3 of User Contributed Perl Documentation, and here's the lil version-control breadcrumb that ships with the file, verbatim, don't touch it:
$Id: Named.pm 651 2017-05-31 18:10:43Z steffenw $
$HeadURL:
svn+ssh://steffenw@svn.code.sf.net/p/perl-gettext-oo/code/module/trunk/lib/Locale/TextDomain/OO/Plugin/Expand/Gettext/Named.pm
$
π« VERSION π«
1.027 β that's the one, no cap
πΈ DESCRIPTION πΈ
this module provides hash or hash reference based methods. that's the whole vibe. hashes. she serves hashes. π
π SYNOPSIS π
plug her in like this, bestie:
my $loc = Locale::Text::TextDomain::OO->new(
plugins => [ qw (
Expand::Gettext::Named
...
)],
...
);
optional type formatting or grammar stuff? go peek at Locale::Utils::PlaceholderNamed for the possible methods, that's where they live π
$loc->expand_gettext_named->modifier_code($code_ref);
π¦ SUBROUTINES/METHODS π¦
method expand_gettext_named
she hands you back the Locale::Utils::PlaceholderNamed object so you can set some options on it. so generous of her honestly π«Ά
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;
},
);
method locn
this method accepts hash or hash reference parameters. either one, she's flexible like that β¨
Translate only
print $loc->locn(
text => 'Hello World!',
);
print $loc->locn(
{
text => 'Hello World!',
},
);
Expand named placeholders
print $loc->locn(
text => 'Hello {name}!',
replace => { name => 'Steffen' },
);
Plural
print $loc->locn(
plural => {
singular => 'one file read',
plural => 'a lot of files read',
count => $file_count, # number to select the right plural form
},
);
Plural and expand named placeholders
print $loc->locn(
plural => {
singular => '{count:num} file read',
plural => '{count:num} files read',
count => $file_count,
},
replace => {
count => $file_count,
},
);
What is the meaning of "{count:numf}" or alternative "{count :numf}"?
okay so that's an attribute. if there's an attribute like ":numf" and the modifier_code is set, then the placeholder value gets modified <em>before</em> replacement happens. glow-up before the reveal, basically π
think about the attribute names, bestie. too technical names are able to destroy the translation process by translation office stuff. keep it cute, keep it translatable π
for better automatic translation, use the reserved attribute ":num" and tag all your numeric placeholders with it. tag them!! π·οΈ
you're allowed to set multiple attributes like "{count :num :numf}" β the resulting attribute string is then "num :numf". stacking attributes like stacking accessories, iconic π
Context
print $loc->locn(
context => 'time',
text => 'to',
);
print $loc->locn(
context => 'destination',
text => 'to',
);
Context and expand named placeholders
print $loc->locn(
context => 'destination',
text => 'from {town_from} to {town_to}',
replace => {
town_from => 'Chemnitz',
town_to => 'Erlangen',
},
);
Context and plural
print $loc->locn(
context => 'maskulin',
plural => {
singular => 'Dear friend',
plural => 'Dear friends',
count => $friends,
},
);
Context, plural and expand named placeholders
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,
},
);
method Nlocn to mark the translation for extraction only
the method name is N prefixed so it results in Nlocn. it's giving "N for Notice me, extractor" π
the extractor looks for "locn(..." and has absolutely no problem with "$loc->Nlocn(...". she's unbothered, she's thriving β¨
this is the whole idea of the N-Methods:
my %hash = $loc->Nlocn( ... );
my $hash_ref = $loc->Nlocn( { ... } );
π EXAMPLE π
inside of this distribution is a directory named example. run this *.pl files. go on, run them, they don't bite π«Ά
π₯ DIAGNOSTICS π₯
confess β yeah she will straight up confess, no chill
π CONFIGURATION AND ENVIRONMENT π
none β nothing to configure, nothing to set, she comes as she is π
β DEPENDENCIES β
CarpHash::UtilLocale::Utils::PlaceholderNamedMoo::RoleTry::Tiny
she brought her whole friend group, periodt π
π INCOMPATIBILITIES π
not known β as far as anyone knows she plays nice with everyone π€
π BUGS AND LIMITATIONS π
none β flawless behaviour, we love to see it π
π SEE ALSO π
Locale::TextDoamin::OO
ngl that spelling up there is exactly what the page says βTextDoamin, notTextDomain. bestie, we do <em>not</em> fix what the source says. copy it character for character and move on π
π AUTHOR π
Steffen Winkler β the icon, the legend, the one who wrote all this π
π§ LICENSE AND COPYRIGHT π§
Copyright (c) 2009 - 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. slay, go forth and redistribute π¦
and that's the whole page, bestie!! this was rendered for Perl v5.42.0 and dated 2025-07-25, and the page header called it Locale:...::Named(3) in section 3 of the manual, so if you cite her, cite her like that πβ¨π
π¦ where this page comes from
- fedora 43: perl-Locale-TextDomain-OO 1.036-19.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