Skip to content

gnouet/PHP-po-parser

 
 

Repository files navigation

Po Parser

![Gitter](https://badges.gitter.im/Join Chat.svg) Build Status Code Coverage Scrutinizer Quality Score Latest Stable Version

PoParser is a personal project to fulfill a need I got: parse Gettext Portable files (*.po files) and edit its content using PHP.

PoParser will allow you to read PO Data from any source (files and strings built-in), update it and store back to a file (or get the compiled string).

It supports following parsing features:

  • header section.
  • msgid, both single and multiline.
  • msgstr, both single and multiline.
  • msgctxt (Message context).
  • msgid_plural (plurals forms).
  • #, keys (flags).
  • keys (translator comments).

  • #. keys (Comments extracted from source code).
  • #: keys (references).
  • #| keys (previously untranslated), both single and multiline.
  • #~ keys (old entries), both single and multiline.

Usage

// Parse a po file
$poParser = new Sepia\PoParser();
$entries  = $poParser->parseFile( 'es.po' );
// $entries contains every entry in es.po file.

// Update entries
$msgid = 'Press this button to save';
$msgstr= 'Pulsa este botón para guardar';
$poParser->updateEntry($msgid, $msgstr);
// You can also change translator comments, code comments, flags...

Changelog

v4.1

  • Constructor now accepts options to define separator used in multiline msgid entries.
  • New method getOptions().

v4.0

  • new methods parseString() and parseFile() replace the old parse()`
  • new method writeFile() replaces the old write().
  • new method compile() which takes all parsed entries and coverts back to a PO formatted string.

See whole changelog

Documentation

See v4 documentation

Testing

Tests are done using PHPUnit. To execute tests, from command line type:

php vendor/bin/phpunit

Install via composer

Edit your composer.json file to include the following:

{
    "require": {
        "sepia/po-parser": "dev-master"
    }
}

About

PO files parser for PHP

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%