NAME Locale::TextDomain::OO::Extract::JavaScript - Extracts internationalization data from JavaScript code
$Id: JavaScript.pm 693 2017-09-02 09:20:30Z steffenw $
$HeadURL: svn+ssh://steffenw@svn.code.sf.net/p/perl-gettext-oo/code/extract/trunk/lib/Locale/TextDomain/OO/Extract/JavaScript.pm $
VERSION
2.011
DESCRIPTION
This module extracts internationalization data from JavaScript code.
Implemented rules:
# Gettext::Loc
loc_('...
loc_x('...
loc_n('...
loc_nx('...
loc_p('...
loc_px('...
loc_np('...
loc_npx('...
# Gettext::Loc::DomainAndCategory
loc_d('...
loc_dx('...
loc_dn('...
loc_dnx('...
loc_dp('...
loc_dpx('...
loc_dnp('...
loc_dnpx('...
loc_c('...
loc_cx('...
loc_cn('...
loc_cnx('...
loc_cp('...
loc_cpx('...
loc_cnp('...
loc_cnpx('...
loc_dc('...
loc_dcx('...
loc_dcn('...
loc_dcnx('...
loc_dcp('...
loc_dcpx('...
loc_dcnp('...
loc_dcnpx('...
# BabelFish::Loc
loc_b('...
loc_bp('...
# BabelFish::Loc::DomainAndCategory
loc_bd('...
loc_bdp('...
loc_bc('...
loc_bcp('...
loc_bdc('...
loc_bdcp('...
# Gettext
_('...
_x('...
_n('...
_nx('...
_p('...
_px('...
_np('...
_npx('...
__('...
__x('...
__n('...
__nx('...
__p('...
__px('...
__np('...
__npx('...
gettext('...
ngettext('...
pgettext('...
npgettext('...
# Gettext::DomainAndCategory
_d('...
_dx('...
_dn('...
_dnx('...
_dp('...
_dpx('...
_dnp('...
_dnpx('...
_c('...
_cx('...
_cn('...
_cnx('...
_cp('...
_cpx('...
_cnp('...
_cnpx('...
_dc('...
_dcx('...
_dcn('...
_dcnx('...
_dcp('...
_dcpx('...
_dcnp('...
_dcnpx('...
__d('...
__dx('...
__dn('...
__dnx('...
__dp('...
__dpx('...
__dnp('...
__dnpx('...
__c('...
__cx('...
__cn('...
__cnx('...
__cp('...
__cpx('...
__cnp('...
__cnpx('...
__dc('...
__dcx('...
__dcn('...
__dcnx('...
__dcp('...
__dcpx('...
__dcnp('...
__dcnpx('...
dgettext('...
dngettext('...
dpgettext('...
dnpgettext('...
cgettext('...
cngettext('...
cpgettext('...
cnpgettext('...
dcgettext('...
dcngettext('...
dcpgettext('...
dcnpgettext('...
Whitespace is allowed everywhere. Quote and escape any text like: ' text {placeholder} \\ \' ' or " text {placeholder} \\ \" }
Also possible all functions with N in front like Nloc_, N__, Ngettext, ... to prepare only.
SYNOPSIS
use Locale::TextDomain::OO::Extract::JavaScript;
use Path::Tiny qw(path);
my $extractor = Locale::TextDomain::OO::Extract::JavaScript->new(
# optional filter parameter, the default is ['all'],
# the following means:
# extract for all plugins but not for Plugin
# Locale::TextDomain::OO::Plugin::BabelFish::Loc
filter => [ qw( all !BabelFish::Loc ) ],
);
for ( @files ) {
$extractor->clear;
$extractor->filename($_); # dir/filename for reference
$extractor->content_ref( \( path($_)->slurp_utf8 ) );
$extractor->project('my project'); # set or default undef is used
$extractor->category('LC_MESSAGES'); # set or default q{} is used
$extractor->domain('my domain'); # set or default q{} is used
$extractor->extract;
}
... = $extractor->lexicon_ref;
SUBROUTINES/METHODS
method new
All parameters are optional. See Locale::TextDomain::OO::Extract to replace the defaults.
my $extractor = Locale::TextDomain::OO::Extract::JavaScript->new;
method filter
Ignore some of 'all' or define what to scan. See SYNOPSIS and DESCRIPTION for how and what.
my $array_ref = $extractor->filter;
$extractor->filter(['all']); # the default
method preprocess (called by method extract)
This method removes all comments.
$extractor->preprocess;
method interpolate_escape_sequence (called by method extract)
This method helps e.g. \n to be a real newline in string.
$string = $extractor->interpolate_escape_sequence($string);
method stack_item_mapping (called by method extract)
This method maps the matched stuff as lexicon item.
$extractor->stack_item_mapping;
method extract
This method runs the extraction.
$extractor->extract;
EXAMPLE
Inside of this distribution is a directory named example. Run this *.pl files.
DIAGNOSTICS
none
CONFIGURATION AND ENVIRONMENT
none
DEPENDENCIES
Locale::TextDomain::OO::Extract::Base::RegexBasedExtractor
Locale::TextDomain::OO::Extract::Role::File
INCOMPATIBILITIES
not known
BUGS AND LIMITATIONS
none
SEE ALSO
http://sourceforge.net/projects/jsgettext.berlios/
AUTHOR
Steffen Winkler
LICENSE AND COPYRIGHT
Copyright (c) 2009 - 2017, Steffen Winkler <steffenw at cpan.org>
. All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.