Catmandu::I18N(3pm)
π Catmandu::I18N β tools for text localisation π
okay bestie, so this is Catmandu::I18N, a lil module from the User Contributed Perl Documentation crew, and it's literally your go-to for text localisation. translating stuff, making your app speak every language, the whole vibe. no cap. β¨
πΈ SYNOPSIS πΈ
here's the whole thing in action, look at her go:
use Catmandu::Sane;
use Catmandu::I18N;
my $i = Catmandu::I18N->new(
config => {
en => [
"Gettext",
"/path/to/en.po"
],
nl => [
"Gettext",
"/path/to/nl.po"
]
}
);
$i->t( "my-lang", "my-key" );
$i->t( "my-lang", "my-key2", "arg-1", "arg-2" );
see? two languages, one object, and then you just call t with your language and your key. and if you need args? t takes them too. iconic behaviour honestly. π
π CONSTRUCTOR ARGUMENTS π
these are the things you can pass when you make your object. pay attention bestie, one of them is Required π
configβ the configuration forLocale::Maketext.
it's gotta be one of these two things:
- a hash reference
- a string (like
"i18n"for example)
so when config is a string, it gets interpreted as the path to the I18N configuration in Catmandu config. cute, right?
Required. you cannot skip this one, bestie. it's not optional. π«Ά
on_failureβ what to do when a lookup does not give a result. like, the message just isn't there. awkward. π
possible values:
"undef"β returnundef"auto"β return the key itself. always a result. always something. slay."die"β die
default: "undef"
Note: "undef" should be a string, as opposed to undef. like, quote it. fr fr. π
fallback_languagesβ an array of fallback language codes. your backup squad. π- must be an array reference
- default is
[ "i-default","en","en-US" ]as determined byLocale::Maketext
so here's the tea: when Locale::Maketext does not find the specified language in your config, it will fallback to one of these, and then load the handle for that.
only if that fallback language does not exist in the config, will it fail. only then. π
Example 1:
fallback_languages is [ "en" ]
you have only language "en" in your config, but you request language "nl", then you'll get the message in English.
Example 2:
fallback_languages is [ "en" ]
you have only language "nl" in your config, but you request language "fr", then the creation of the message will fail.
you can set this to an empty array for consistent behaviour. your call, main character. π
β¨ NOTES β¨
- the lexicon implementation determines the format of the message. yeah, it's giving "it depends" but that's just how it is bestie.
e.g. only Locale::Maketext::Lexicon::Gettext supports placeholders like %1.
for other implementations you need to use placeholders like [_1]
so like, check which one you're on before you go blaming the placeholders. π
π AUTHORS π
Nicolas Franck <nicolas.franck at ugent.be>
π¦ SEE ALSO π¦
Catmandu::Fix::i18n, Locale::Maketext::Lexicon::CatmanduConfig, Catmandu, Locale::Maketext
go read those too, they're all connected, iykyk. π
π LICENSE AND COPYRIGHT π
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See <http://dev.perl.org/licenses/> for more information.
and that's the whole page bestie!! π this one's from perl v5.36.0, dated 2023-02-04 β yes she's an elder but she still ate. go localise something gorgeous. bye pookie!! πβ¨π«Ά
π¦ where this page comes from
- debian bookworm: libcatmandu-i18n-perl 0.01-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libcatmandu-i18n-perl 0.01-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libcatmandu-i18n-perl 0.01-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libcatmandu-i18n-perl 0.01-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libcatmandu-i18n-perl 0.01-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms