Cataly...::I18N(3pm)

πŸ“¦
version 0.10 Β· 4 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Catalyst::Plugin::I18N β€” the manual, but make it cute πŸ’–

okay so bestie, this is the manual page for Catalyst::Plugin::I18N β€” it's the perl one (section 3pm), and it's literally the way you make your Catalyst app speak every language. 🌍✨


✨ NAME ✨

Catalyst::Plugin::I18N β€” I18N for Catalyst. that's it, that's the name, slay. πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

the vibe is: plug it in, set your languages, localize your lil strings.

use Catalyst 'I18N';

print join ' ', @{ $c->languages };
$c->languages( ['de'] );
print $c->localize('Hello Catalyst');

and if you're feeling lazy (no judgement, we've all been there πŸ™ˆ), use a macro:

[% MACRO l(text, args) BLOCK;
    c.localize(text, args);
END; %]

[% l('Hello Catalyst') %]
[% l('Hello [_1]', 'Catalyst') %]
[% l('lalala[_1]lalala[_2]', ['test', 'foo']) %]
[% l('messages.hello.catalyst') %]

🌸 DESCRIPTION 🌸

it supports mo/po files and Maketext classes, all living under your application's I18N namespace. it's giving organized. it's giving multilingual queen. πŸ‘‘

# MyApp/I18N/de.po
msgid "Hello Catalyst"
msgstr "Hallo Katalysator"

# MyApp/I18N/i_default.po
msgid "messages.hello.catalyst"
msgstr "Hello Catalyst - fallback translation"

# MyApp/I18N/de.pm
package MyApp::I18N::de;
use base 'MyApp::I18N';
our %Lexicon = ( 'Hello Catalyst' => 'Hallo Katalysator' );
1;

βš™οΈ CONFIGURATION βš™οΈ

you can override any parameter that gets sent to Locale::Maketext::Simple by handing a maketext_options hashref to the Plugin::I18N config section. like, literally any of them. main character energy fr fr.

for example, this config right here overrides the Decode parameter, which normally defaults to 1:

__PACKAGE__->config(
    'Plugin::I18N' =>
        maketext_options => {
            Decode => 0
        }
);

every language falls back to MyApp::I18N, which is mapped onto the i-default language tag. and if you're using arbitrary message keys, use i_default.po to translate them into English β€” otherwise the message key itself is what gets returned. iykyk. πŸ’œ


πŸ”₯ EXTENDED METHODS πŸ”₯

  • setup

πŸ’… METHODS πŸ’…

  • languages

contains languages. yeah, it just holds them. iconic behaviour honestly.

$c->languages(['de_DE']);
print join '', @{ $c->languages };
  • language

returns the selected locale from your locales list.

  • language_tag

returns the language tag for the current locale. the most notable difference between this method and language() is typically that languages and regions are joined with a dash and not an underscore. πŸ¦‹

$c->language(); # en_us
$c->language_tag(); # en-us
  • installed_languages

returns a hash shaped like { langtag => "descriptive name for language" }, based on the language files chillin' in your application's I18N directory. the descriptive name comes from I18N::LangTags::List info. and if that descriptive name isn't available? it'll be undef. πŸ’€

  • loc
  • localize

localizes text. the moment we've all been waiting for.

print $c->localize( 'Welcome to Catalyst, [_1]', 'sri' );

πŸ‘€ SEE ALSO πŸ‘€

Catalyst


🫢 AUTHORS 🫢

  • Sebastian Riedel <sri@cpan.org>
  • Brian Cassidy <bricas@cpan.org>
  • Christian Hansen <chansen@cpan.org>

Copyright (c) 2005 - 2009 the Catalyst::Plugin::I18N "AUTHORS" as listed above.

This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself.


and that's a wrap bestie!! this page came straight out of perl version v5.36.0, dated 2022-11-27. go forth and translate everything, you absolute legend πŸ’–βœ¨πŸŒˆ
πŸ“¦ where this page comes from