Locale::TextDomain::OO::Extract::Xslate - Extract messages from Text::Xslate templates for translation with Locale::TextDomain::OO
version 0.04
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, }); }
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:
__
__x
__n
__nx
__p
__px
__np
__npx
The same methods are recognized when the first _ (underscore) is replaced by loc (resulting in loc_, loc_x, and so on).
loc_
loc_x
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!
addl_l10n_function_re
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!
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.
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);
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.
filename
Passing in a true or false value you can enable or disable the debugging output (written to STDERR).
true
false
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.
Heiko Jansen <hjansen@cpan.org>
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
To install Locale::TextDomain::OO::Extract::Xslate, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Locale::TextDomain::OO::Extract::Xslate
CPAN shell
perl -MCPAN -e shell install Locale::TextDomain::OO::Extract::Xslate
For more information on module installation, please visit the detailed CPAN module installation guide.