Locale::PO(3pm) | User Contributed Perl Documentation | Locale::PO(3pm) |
Locale::PO - Perl module for manipulating .po entries from GNU gettext
use Locale::PO; $po = new Locale::PO([-option=>value,...]) [$string =] $po->msgid([new string]); [$string =] $po->msgstr([new string]); [$string =] $po->comment([new string]); [$string =] $po->automatic([new string]); [$string =] $po->reference([new string]); [$value =] $po->fuzzy([value]); [$value =] $po->add_flag('c-format'); print $po->dump; $quoted_string = $po->quote($string); $string = $po->dequote($quoted_string); $aref = Locale::PO->load_file_asarray(<filename>,[encoding]); $href = Locale::PO->load_file_ashash(<filename>,[encoding]); Locale::PO->save_file_fromarray(<filename>,$aref,[encoding]); Locale::PO->save_file_fromhash(<filename>,$href,[encoding]);
This module simplifies management of GNU gettext .po files and is an alternative to using emacs po-mode. It provides an object-oriented interface in which each entry in a .po file is a Locale::PO object.
my Locale::PO $po = new Locale::PO; my Locale::PO $po = new Locale::PO(%options);
Create a new Locale::PO object to represent a po entry. You can optionally set the attributes of the entry by passing a list/hash of the form:
-option=>value, -option=>value, etc.
Where options are msgid, msgid_plural, msgstr, msgctxt, comment, automatic, reference, fuzzy_msgctxt, fuzzy_msgid, fuzzy_msgid_plural, fuzzy, and c-format. See accessor methods below.
To generate a po file header, add an entry with an empty msgid, like this:
$po = new Locale::PO(-msgid=>'', -msgstr=> "Project-Id-Version: PACKAGE VERSION\\n" . "PO-Revision-Date: YEAR-MO-DA HO:MI +ZONE\\n" . "Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n" . "Language-Team: LANGUAGE <LL@li.org>\\n" . "MIME-Version: 1.0\\n" . "Content-Type: text/plain; charset=CHARSET\\n" . "Content-Transfer-Encoding: ENCODING\\n");
This method expects the new string in unquoted form but returns the current string in quoted form.
This method expects the new string in unquoted form but returns the current string in quoted form.
This method expects the new string in unquoted form but returns the current string in quoted form.
$po->msgstr_n( { 0 => 'found %d plural translations', 1 => 'found %d singular translation', } );
This method expects the new strings in unquoted form but returns the current strings in quoted form.
This method expects the new string in unquoted form but returns the current string in quoted form.
This method expects the new string in unquoted form but returns the current string in quoted form.
This method expects the new string in unquoted form but returns the current string in quoted form.
This method expects the new string in unquoted form but returns the current string in quoted form.
When using load_file_ashash, non-obsolete entries will always replace obsolete entries with the same msgid.
If there are no such comments, then the value is undef. Otherwise, the value is a string that contains the comment lines delimited with "\n". The string includes neither the "# " at the beginning of each comment line nor the newline at the end of the last comment line.
If there are no such comments, then the value is undef. Otherwise, the value is a string that contains the comment lines delimited with "\n". The string includes neither the "#. " at the beginning of each comment line nor the newline at the end of the last comment line.
This can take 3 values: 1 implies c-format, 0 implies no-c-format, and undefined implies neither.
This can take 3 values: 1 implies php-format, 0 implies no-php-format, and undefined implies neither.
if ($po->has_flag('perl-format')) { ... }
Returns true if the flag exists in the entry's #~ comment
$po->add_flag('perl-format');
Adds the flag to the #~ comment
$po->remove_flag('perl-format');
Removes the flag from the #~ comment
Maintainer: Ken Prows, perl@xev.net
Original version by: Alan Schwartz, alansz@pennmush.org
If you load_file_as* then save_file_from*, the output file may have slight cosmetic differences from the input file (an extra blank line here or there).
msgid, msgid_plural, msgstr, msgstr_n and msgctxt expect a non-quoted string as input, but return quoted strings. I'm hesitant to change this in fear of breaking the modules/scripts of people already using Locale::PO.
Locale::PO requires blank lines between entries, but Uniforum style PO files don't have any.
Please submit all bug requests using CPAN's ticketing system.
2018-08-27 | perl v5.26.2 |