$Id: Process.pm 719 2018-09-21 12:58:00Z steffenw $
$HeadURL: svn+ssh://steffenw@svn.code.sf.net/p/perl-gettext-oo/code/extract/trunk/lib/Locale/TextDomain/OO/Extract/Process.pm $
2.015
Prepare PO/MO files for extraction and store them back after extraction.
use Locale::TextDomain::OO::Extract::Perl; # subclass Perl use Path::Tiny qw(path);
Set in constructor all static values. Set all other in loop.
my $process = Locale::TextDomain::OO::Extract::Process->new( # set all static things here, all dynamics in loops project => 'my project', # for special cases # set or default undef is used category => 'LC_MESSAGES', # for special cases # set or default q{} is used domain => 'my domain', # text domain # set or default q{} is used language => 'en', # mostly dynamic and not set here # set or the default 'i-default' is used lexicon_ref => $my_own_hash_ref, # mostly not set plugin_ref => { # depends on read/write files po => 'PO', # default mo => 'MO', foo => '+My::FooPlugin', # with full class name }, );
for ( @po_files ) { $process->project('my project'); $process->category('LC_MESSAGES'); $process->domain('my domain'); $process->language('en'); $process->slurp( po => $_ ); }
This are the #: comments in PO files.
#:
$process->remove_all_reference;
This are the #. comments in PO files.
#.
$process->remove_all_automatic;
my $extract = Locale::TextDomain::OO::Extract::Perl->new; for ( @perl_files ) { $extract->clear; $extract->project('my extract project'); $exttact->category('my extract category'); $extract->domain('my extract domain'); # language is i-default $extract->filename($_); $extract->content_ref( \( path($_)->slurp_utf8 ) ); $extract->extract; }
Merge of new or changed data from extract lexicon to process lexicon. Mostly the extract project/category/domain is the same like process project/category/domain. But in can be different.
$process->merge_extract({ lexicon_ref => $extract->lexicon_ref, project => 'my extract project', category => 'my extract category', domain => 'my extract domain', # extract language is i-default # skip region if region file is only the difference, e.g. to language de skip_new_messages => $process->language eq 'de-at', # or extended skip_new_messages => { on => $process->language eq 'de-at' no_skip_for => # arrayref or scalar with string or regex [ '.domain.de', '+49', qr{ ... }xmsi ) ], but_skip_for => # same like before but filter out false positive 'Fax: ', }, });
for ( @po_files ) { $process->clear; $process->project('my project'); $process->category('LC_MESSAGES'); $process->domain('my domain'); $process->language('en'); $process->spew( po => $_ ); }
Do it.
$process->remove_all_non_referenced;
for ( @po_files ) { $process->clear; $process->project('my project'); $process->category('LC_MESSAGES'); $process->domain('my domain'); $process->language('en'); $process->spew( po => $_ ); ( my $mo_file = $_ ) =~ s{ [.] po \z }{.mo}xms; $process->spew( mo => $mo_file ); }
see SYNOPSIS
Needs a plugin name amd a package name. If no + is written the Package name is prefixed by "Locale::TextDomain::OO::Extract::Process::Plugin::".
$process->add_plugin( mo => 'MO' ); $process->add_plugin( bar => '+My::BarPlugin' );
Slurp a file and put the data into the lexicon_ref.
$process->slurp( po => 'filename.po' );
Spew a file with data of lexicon_ref.
$process->spew( mo => 'filename.mo');
Strips all references. References are here gettext references, the filename and line of file the extractor has found.
Strips all automatic comments.
All entries with no reference are no longer in source because the extractor has not found. So there is no need to translate this phrases.
The extractor extracts for language i-default. That is running one time for all files. But every language needs the new extraction data. So all new and changed data will be merged to any language. For sublanguages/regions it is possible to skip.
$process->merge_extract({ lexicon_ref => $extract->lexicon_ref, # all following optional category => 'category during extraction', domain => 'domain during extraction', project => 'project during extraction', # simple skip_new_messages => $boolean, # or extended skip_new_messages => { on => $boolean, no_skip_ => $arrayref_or_scalar_with_string_or_regex, but_skip_for => $arrayref_or_scalar_with_string_or_regex, }, });
Inside of this distribution is a directory named example. Run this *.pl files.
none
Carp
Clone
Class::Load
Locale::TextDomain::OO::Util::JoinSplitLexiconKeys
Moo
MooX::StrictConstructor
MooX::Types::MooseLike::Base
Set::Scalar
namespace::autoclean
not known
Locale::TextDoamin::OO::Extract
Steffen Winkler
Copyright (c) 2014 - 2018, Steffen Winkler <steffenw at cpan.org>. All rights reserved.
<steffenw at cpan.org>
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Locale::TextDomain::OO::Extract, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Locale::TextDomain::OO::Extract
CPAN shell
perl -MCPAN -e shell install Locale::TextDomain::OO::Extract
For more information on module installation, please visit the detailed CPAN module installation guide.