Extract strings from arbitrary formats into PO files
When using Lhttps://www.gnu.org/software/gettext/ you often find yourself extracting translatable strings from more or less exotic file formats that cannot be handled by xgettext from the Lhttps://www.gnu.org/software/gettext/ suite directly. This package simplifies the task of writing a string extractor in Perl, Python, Java, Ruby or other languages by providing a common base needed for such scripts.
Included is a sample string extractor "xgettext-txt" in bin for plain text files. It simply splits the input into paragraphs, and turns each paragraph into an entry of a PO file.
The idea of the package is that you just a write a parser plug-in for Locale::XGettext and use all the boilerplate code for generating the PO file and for processing script options from this library. One such example is a parser plug-in for strings in templates for the Template Toolkit version 2 included in the package Lhttps://github.com/gflohr/Template-Plugin-Gettext. that contains a script xgettext-tt2 which can only extract strings from that particular template language.
Locale::XGettext
xgettext-tt2
If this is the only source of translatable strings you are mostly done. Often times you will, however, have to merge strings from all different input formats into one single PO file. Let's assume that your project is written in Perl and C and that it also contains Template Toolkit templates and plain text files that have to be translated.
xgettext-txt
text.pot
templates.pot
xgettext
.po
.pot
By the way, all xgettext flavors based on Locale::XGettext are also able to extract strings from .po or .pot files. So you can also make do completely without GNU gettext and use any Locale::XGettext extractor instead of GNU gettext for the last step.
Writing an extractor is as easy as implementing one single method that takes a filename argument and extract strings from that file. See the manual page Lhttp://search.cpan.org/~guido/Locale-XGettext/lib/Locale/XGettext.pm for more information. See "README.md" in samples as a starting point for writing an extractor in Perl or many other languages. The distribution currently contains fully functional examples written in "C/README.md" in samples, "Java/README.md" in samples, "Python/README.md" in samples, "Perl/README.md" in samples, and "Ruby/README.md" in samples.
There a couple of subtle differences in the handling of command-line arguments between extractors based on Locale::XGettext and the original xgettext program. Report a bug if you think that a particular difference is a bug and not an improvement.
One thing that Locale::XGettext does not support is the prefix "pass-" for flag definitions. While it is possible for an extractor to implement the behavior of GNU gettext, this is not directly supported by Locale::XGettext. Instead, that prefix is simply ignored, when specified on the command-line for an option argument to "--flag" or as part of the set of default flags for a particular extractor.
Additionally, while xgettext from GNU gettext has a hard-coded, fixed set of supported formats, you can specify arbitrary formats with "--flag" for extractors based on Locale::XGettext.
You can install the latest version of Locale::XGettext from Lhttp://search.cpan.org/ with:
$ cpan Locale::XGettext
If the command cpan is not installed, try instead:
cpan
$ perl -MCPAN -e 'install Locale::XGettext'
Download the sources from Lhttps://github.com/gflohr/Locale-XGettext and
$ tar cxf Locale-XGettext-VERSION.tar.gz $ cd Locale-XGettext-VERSION $ perl Makefile.PL $ make $ make test $ make install
$ git clone https://github.com/gflohr/Locale-XGettext.git $ cd Locale-XGettext $ dzil build $ cd Locale-XGettext-VERSION
From here, follow the instructions for installation from sources.
The command dzil is part of Lhttp://search.cpan.org/~rjbs/Dist-Zilla/.
dzil
The module should ship with its own PO parser and writer.
Please report bugs at Lhttps://github.com/gflohr/Locale-XGettext/issues
Copyright (C) 2016-2017, Guido Flohr, mailto:guido.flohr@cantanea.com, all rights reserved.
To install Locale::XGettext, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Locale::XGettext
CPAN shell
perl -MCPAN -e shell install Locale::XGettext
For more information on module installation, please visit the detailed CPAN module installation guide.