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 for Locale::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" β€” return undef
  • "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 by Locale::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. πŸ’–


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