NAME
Locale::TextDomain::OO::Extract::Xslate - Extract messages from Text::Xslate templates for translation with Locale::TextDomain::OO
VERSION
version 0.03
SYNOPSIS
use Locale::TextDomain::OO::Extract::Xslate;
use Locale::TextDomain::OO::Extract::Process;
my $process = Locale::TextDomain::OO::Extract::Process->new();
my $extract = Locale::TextDomain::OO::Extract::Xslate->new();
# extract
for my $file (qw( foo.tx bar.tx )) {
$extract->clear;
$extract->filename($file);
$extract->extract;
}
# merge
for my $language (qw( de en )) {
$process->language($language);
$process->merge_extract({
lexicon_ref => $extract->lexicon_ref,
});
}
DESCRIPTION
Locale::TextDomain::OO::Extract::Xslate extracts messages from Text::Xslate templates for later translation handling with Locale::TextDomain::OO.
The template code is scanned for invocations of methods or functions with certain names. Currently the following names are recognized:
The same methods are recognized when the first _ (underscore) is replaced by loc (resulting in loc_
, loc_x
, and so on).
Both variants can also optionally be prefixed by N.
Texts to be translated are also recognized and extracted where filters with these names are used. But please note that since filters cannot take arguments, only __
and loc_
(and perhaps some custom methods; cf. addl_l10n_function_re
below) may reasonably be used as filters!
For the encoded meaning of these names please refer to Locale::TextDomain::OO::Plugin::Expand::Gettext and Locale::TextDomain::OO::Plugin::Expand::Gettext::Loc, respectively.
Please note that as of now the usage of dynamic domains and/or categories (as provided by Locale::TextDomain::OO::Plugin::Expand::Gettext::DomainAndCategory) is not supported!
CONSTRUCTOR OPTIONS
The following params can be provided to the plugin on object construction:
syntax
-
Specify the syntax used in the templates to be scanned. Acceptable values are
debug
-
Passing in a true value for this option enables a dumping (to STDERR) of the abstract syntax tree of the template. This is mostly useful for the development of this module.
addl_l10n_function_re
-
If you need to extract more than the default list of translation functions, you can add yours with this, e.g.
$extract->addl_l10n_function_re(qr{ loc | i10n_me | whatever }x);
METHODS
Locale::TextDomain::OO::Extract::Xslate DOES the role Locale::TextDomain::OO::Extract::Role::File and therefore you can call the methods defined in that role on the objects of this class.
extract
After using the filename
method to specify which template to work on next, invoking this method will start the extraction process. Expects no parameters.
debug
Passing in a true
or false
value you can enable or disable the debugging output (written to STDERR).
SEE ALSO
- Locale::TextDomain::OO
- Locale::TextDomain::OO::Extract
- Locale::TextDomain::OO::Extract::Process
- Locale::TextDomain::OO::Extract::Role::File
The code of this module and the way it uses the AST from Text::Xslate itself to identify the messages is heavily inspired by (read: stolen from) Localizer::Scanner::Xslate.
AUTHOR
Heiko Jansen <hjansen@cpan.org>
COPYRIGHT AND LICENSE
This software is Copyright (c) 2018 by Heiko Jansen <hjansen@cpan.org>.
This is free software, licensed under:
The GNU General Public License, Version 3, June 2007