Locale::Maketext::Extract - Extract translatable strings from source
my $Ext = Locale::Maketext::Extract->new; $Ext->read_po('messages.po'); $Ext->extract_file($_) for <*.pl>; # Set $entries_are_in_gettext_format if the .pl files above use # loc('%1') instead of loc('[_1]') $Ext->compile($entries_are_in_gettext_format); $Ext->write_po('messages.po');
This module can extract translatable strings from files, and write them back to PO files. It can also parse existing PO files and merge their contents with newly extracted strings.
A command-line utility, xgettext.pl, is installed with this module as well.
Following formats of input files are supported:
Valid localization function names are: translate, maketext, gettext, loc, x, _ and __.
translate
maketext
gettext
loc
x
_
__
Strings inside <&|/l>...</&> and <&|/loc>...</&> are extracted.
<&|/l>...</&>
<&|/loc>...</&>
Strings inside [%|l%]...[%END%] or [%|loc%]...[%END%] are extracted.
[%|l%]...[%END%]
[%|loc%]...[%END%]
Sentences between STARTxxx and ENDxxx are extracted individually.
STARTxxx
ENDxxx
Strings inside {{...}} are extracted.
new
header, set_header lexicon, set_lexicon, msgstr, set_msgstr entries, set_entries, entry, add_entry, del_entry compiled_entries, set_compiled_entries, compiled_entry, add_compiled_entry, del_compiled_entry clear
extract extract_file
Merges the entries into compiled_entries.
entries
compiled_entries
If $entries_are_in_gettext_style is true, the previously extracted entries are assumed to be in the Gettext style (e.g. %1).
$entries_are_in_gettext_style
%1
Otherwise they are assumed to be in Maketext style (e.g. [_1]) and are converted into Gettext style before merging into compiled_entries.
[_1]
The entries are not cleared after each compilation; use -set_entries()> to clear them if you need to extract from sources with varying styles.
-
msgids, has_msgid, msgstr, set_msgstr msg_positions, msg_variables, msg_format, msg_out
_default_header _maketext_to_gettext _escape _format
Thanks to Jesse Vincent for contributing to an early version of this module.
Also to Alain Barbet, who effectively re-wrote the source parser with a flex-like algorithm.
xgettext.pl, Locale::Maketext, Locale::Maketext::Lexicon
Audrey Tang <cpan@audreyt.org>
Copyright 2003, 2004, 2005, 2006 by Audrey Tang <cpan@audreyt.org>.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is fur- nished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FIT- NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
To install Locale::Maketext::Lexicon, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Locale::Maketext::Lexicon
CPAN shell
perl -MCPAN -e shell install Locale::Maketext::Lexicon
For more information on module installation, please visit the detailed CPAN module installation guide.