PHPackages                             degola/po-parser - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Localization &amp; i18n](/categories/localization)
4. /
5. degola/po-parser

ActiveLibrary[Localization &amp; i18n](/categories/localization)

degola/po-parser
================

Gettext \*.po parser for PHP

1.0.1(12y ago)022MITPHPPHP &gt;=5.3.0

Since Mar 4Pushed 12y ago1 watchersCompare

[ Source](https://github.com/Degola/PoParser)[ Packagist](https://packagist.org/packages/degola/po-parser)[ Docs](http://github.com/MAXakaWIZARD/PoParser)[ RSS](/packages/degola-po-parser/feed)WikiDiscussions master Synced 4d ago

READMEChangelogDependenciesVersions (3)Used By (0)

PoParser
========

[](#poparser)

Gettext \*.po files parser for PHP.

This package is compliant with [PSR-0](http://www.php-fig.org/psr/0/), [PSR-1](http://www.php-fig.org/psr/1/), and [PSR-2](http://www.php-fig.org/psr/2/). If you notice compliance oversights, please send a patch via pull request.

Forked from  regarding ignored pull requests.

Usage
-----

[](#usage)

### Read file content

[](#read-file-content)

```
$parser = new PoParser\Parser();
$parser->read('my-pofile.po');
$entries = $parser->getEntriesAsArrays();
// Now $entries contains every string information in your pofile

echo '';
foreach ($entries as $entry) {
   echo ''.
   'msgid: '.$entry['msgid'].''.         // Message ID
   'msgstr: '.$entry['msgstr'].''.       // Translation
   'reference: '.$entry['reference'].''. // Reference
   'msgctxt: ' . $entry['msgctxt'].''.   // Message Context
   'tcomment: ' . $entry['tcomment'].''. // Translator comment
   'ccomment: ' . $entry['ccomment'].''. // Code Comment
   'obsolete?: '.(string)$entry['obsolete'].''. // Is obsolete?
	'fuzzy?: ' .(string)$entry['fuzzy'].     // Is fuzzy?
	'';
}
echo '';
```

### Modify content

[](#modify-content)

```
$parser = new PoParser\Parser();
$parser->read('my-pofile.po');
// Entries are stored in array, so you can modify them.

// Use updateEntry method to change messages you want.
$parser->updateEntry('Write your email', 'Escribe tu email');
$parser->write('my-pofile.po');
```

### Convert po file to jsgettext content

[](#convert-po-file-to-jsgettext-content)

For usage with the jsgettext library from .

#### Shell script converting

[](#shell-script-converting)

po2json.php like the perl script of the jsgettext library but without further dependency.

```
bin$ po2json.php messages.po messages >messages.json
```

#### Online converting with caching

[](#online-converting-with-caching)

It's also possible to use the library for live conversion as soon as the po file changes on the server. Gives you way more flexibility while developing. To avoid the overhead of compiling the po files again and again there is also an simple caching functionality included which uses just last-modified headers and filemtime checks.

```
