Dist::...tDomain(3pm)
π Dist::Zilla::Plugin::LocaleTextDomain π
okay bestie, so this page is the manual for Dist::Zilla::Plugin::LocaleTextDomain (from the User Contributed Perl Documentation, no less π), and it's literally all about compiling Local::TextDomain language files. Let's get into it π
β¨ NAME β¨
Dist::Zilla::Plugin::LocaleTextDomain β Compile Local::TextDomain language files π
πΈ SYNOPSIS πΈ
In dist.ini:
[ShareDir]
[LocaleTextDomain]
textdomain = My-App
lang_dir = po
share_dir = share
that's it, that's the whole vibe check β¨
π¦ DESCRIPTION π¦
okay so here's the tea β: this plugin compiles GNU gettext language files and adds them into your distribution so Locale::TextDomain can use them. Super useful if your distribution keeps gettext language files in a directory, with each file named for a language. The plugin uses msgfmt to compile each file and then adds it to the distribution's share directory. Then you can use the ShareDir plugin to make sure it gets installed in the right place. iconic behavior, honestly π
π§ Installation π§
By default, Locale::TextDomain searches for language files in the shared directory for your distribution, as defined by File::ShareDir. But β and this is the plot twist π β prior to v1.21, that was not the case. Instead, it searched for files in Perl's @INC directories. So if you're stuck with one of these older versions of Locale::TextDomain, you'll have to install the compiled language files into the lib directory in your distribution. To do so, simply set the share_dir attribute to lib:
[LocaleTextDomain]
textdomain = My-App
lang_dir = po
share_dir = lib
If your distribution uses ExtUtils::MakeMaker to do the installation, the files will now be installed in the proper location. π If it relies on Module::Build, you will have to do a bit of additional work. First, subclass Module::Build by creating inc/Module/Build/MyApp.pm with this code:
package Module::Build::MyApp;
use parent 'Module::Build';
sub new {
my ( $class, %p ) = @_;
my $self = $class->SUPER::new(%p);
$self->add_build_element('mo');
return $self;
}
Then tell Dist::Zilla to use the subclass via the mb_class attribute in dist.ini:
[ModuleBuild]
mb_class = Module::Build::MyApp
Now the .mo files will be installed where Locale::TextDomain can find them. slay π«Ά
π Configuration π
Configuration attributes settable in dist.ini to change the plugin behavior. Let's go one by one, bestie, no skips π
textdomainβ the textdomain to use for your language files, as defined by theLocale::TextDomaindocumentation. This should be the same value declared in each use ofLocale::TextDomainin your module. For example, if such lines look like this:
use LocaleText::Domain qw(com.example.myApp);
Then set it to such in your dist.ini:
[LocaleTextDomain]
textdomain = com.example.myApp
Defaults to the name of your distribution, which is the value that Locale::TextDomain recommends you use. π
lang_dirβ the directory containing your language files. Defaults topo.share_dirβ the name of the distribution directory into which compiled language files should be added. Defaults toshare.msgfmtβ the location of themsgfmtprogram, which is distributed with GNU gettext <http://www.gnu.org/software/gettext/>. Defaults to justmsgfmt, which should work if it's in your path.languageβ a language to be compiled. May be specified more than once. If not specified, the default will be the list of files inlang_dirending inlange_file_suffix.lang_file_suffixβ suffix used in the language file names. These are the files your translators maintain in your repository. Defaults topo.bin_file_suffixβ suffix to use for the compiled language file. Defaults tomo.finderβ file finders to use to look for files to search for strings to extract. May be specified more than once. If not specified, the default will be:InstallModulesand:ExecFiles; that is, files belowlib/and executable files marked by e.g. theExecDirplugin. You can also combine default finders with custom ones based on aFileFinderplugin. For example:
[FileFinder::ByName / MyFiles]
file = *.pl
[LocaleTextDomain]
finder = MyFiles
finder = :ShareFiles
This configuration will extract strings from files that match *.pl and all files in a share directory. π
xgettext_argsβ extra arguments to be passed to the extractor program. This is an advanced feature that exists for cases where special customization is needed, such as when different keywords are used to mark strings. π₯override_argsβ by default, arguments are passed to the extractor that set the language toperlas well as set keywords that tell xgettext how strings are marked (which includes the keywords specified byLocale::TextDomain). If for some reason you don't want that (presumably because you're going to use thexgettext_argsattribute to configure your own language and keywords), then you can set this attribute to true.join_existingβ if you have strings in files other than Perl files, you can cause the extractor to be invoked multiple times against different sets of files with different arguments. The strings from all of these other file sets will be joined into yourpofiles.
For example, imagine you have a GTK+ app. You have strings in your Perl modules, as usual, but perhaps you also have strings in your Glade files that you want to be translatable. You could write something like this into your dist.ini:
[FileFinder::ByName / GladeFiles]
file = *.ui
[LocaleTextDomain]
join_existing = --language=glade %{GladeFiles}f
The value of the join_existing attribute is the argument list that will be passed to an additional invocation of xgettext. The %{GladeFiles}f syntax allows you to use a finder to search for files to be passed to the extractor, but you could also "hard code" one or more files as well.
This attribute is repeatable. If your project also had a JavaScript file with strings, you could just add another line to your LocaleTextDomain section:
join_existing = -L javascript share/media/app.js
π AUTHOR π
David E. Wheeler <david@justatheory.com> π
π CONTRIBUTOR π
Charles McGarvey <ccm@cpan.org> π«Ά
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2012-2017 by David E. Wheeler.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
and that's the whole page, bestie, you ate it up β¨π
tiny little sign-off for the road: this was written up against perl v5.26.2 and dated 2018-07-08 β periodt, go compile some language files π¦πΈ
π¦ where this page comes from
- debian bookworm: libdist-zilla-localetextdomain-perl 0.91-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libdist-zilla-localetextdomain-perl 0.91-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu jammy: libdist-zilla-localetextdomain-perl 0.91-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libdist-zilla-localetextdomain-perl 0.91-3 Β· 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