Locale:...Gettext(3)
π NAME π
Locale::Maketext::Lexicon::Gettext β the PO and MO file parser for Maketext, bestie! It's a User Contributed Perl Documentation page (that's the manual name, iykyk), and it's literally the thing that reads your translation files so your app can speak German, French, whatever.
β¨ VERSION π
version 1.00
π¦ SYNOPSIS πΈ
So there's two ways you can call this: the chill way (through Locale::Maketext::Lexicon), or the direct way (calling parse() yourself). Both slay:
Called via Locale::Maketext::Lexicon:
package Hello::I18N;
use base 'Locale::Maketext';
use Locale::Maketext::Lexicon {
de => [Gettext => 'hello/de.mo'],
};
Directly calling parse():
use Locale::Maketext::Lexicon::Gettext;
my %Lexicon = %{ Locale::Maketext::Lexicon::Gettext->parse(<DATA>) };
__DATA__
#: Hello.pm:10
msgid "Hello, World!"
msgstr "Hallo, Welt!"
#: Hello.pm:11
msgid "You have %quant(%1,piece) of mail."
msgstr "Sie haben %quant(%1,Poststueck,Poststuecken)."
π DESCRIPTION π§
okay so here's the vibe: this module implements a perl-based Gettext parser for Locale::Maketext. What it does is take all your %1, %2, <%*>... sequences and transform them into [_1], [_2], [_*], and so on β like a glow-up for your placeholders. β¨
It happily accepts either a plain PO file, or a MO file β and the MO one gets handled with a pure-perl parser adapted from Imacat's Locale::Maketext::Gettext. no cap, pure perl, no external drama.
Since version 0.03, this module also looks for %function(args...) inside the lexicon strings, and transforms it to [function,args...]. And any %1, %2... sequences sitting inside those args get their percent signs (%) replaced by underscores (_). the way that works is genuinely so clean.
The name of that function up there should begin with a letter or underscore, followed by any number of alphanumeric characters and/or underscores. As an exception π«Ά, the function name may also be a single asterisk (*) or pound sign (#), which are Locale::Maketext's shorthands for quant and numf, respectively. iconic behavior.
As an additional feature (she keeps giving), this module also parses MIME-header style metadata specified in the null msgstr (""), and adds them to the %Lexicon with a "__" prefix. For example, the example above will set "__Content-Type" to "text/plain; charset=iso8859-1", without the newline or the colon. π
Any normal entry that duplicates a metadata entry takes precedence. Hence, a "msgid "__Content-Type"" line occurs anywhere should override the above value. lowkey important, don't forget it.
π OPTIONS π
π use_fuzzy
When parsing PO files, fuzzy entries (entries marked with #, fuzzy) are silently ignored. If you wish to use fuzzy entries, specify a true value to the _use_fuzzy option:
use Locale::Maketext::Lexicon {
de => [Gettext => 'hello/de.mo'],
_use_fuzzy => 1,
};
π¦ allow_empty
When parsing PO files, empty entries (entries with msgstr "") are silently ignored. If you wish to allow empty entries, specify a true value to the _allow_empty option:
use Locale::Maketext::Lexicon {
de => [Gettext => 'hello/de.mo'],
_allow_empty => 1,
};
π SEE ALSO β
Locale::Maketext, Locale::Maketext::Lexicon
π AUTHORS πΈ
Audrey Tang <cpan@audreyt.org>
π₯ COPYRIGHT π
Copyright 2002-2013 by Audrey Tang <cpan@audreyt.org>.
This software is released under the MIT license cited below.
π The MIT License π
okay here's the exact legal text, no edits from me, promise π«Ά:
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
πΊ AUTHORS (yes, again π)
- Clinton Gormley
<drtech@cpan.org> - Audrey Tang
<cpan@audreyt.org>
π§ COPYRIGHT AND LICENSE π
This software is Copyright (c) 2014 by Audrey Tang.
This is free software, licensed under:
The MIT (X11) License
π¦ and that's the whole page bestie, periodt. this little gem isperl v5.40.2, dated2025-01-03β go forth and translate everything β¨π
π¦ where this page comes from
- alpine 3.22: perl-locale-maketext-lexicon-doc 1.00-r6 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms