2017 © Pedro Peláez
 

library po

Objects to assist in reading, manipulating and creating GNU gettext style PO files

image

geekwright/po

Objects to assist in reading, manipulating and creating GNU gettext style PO files

  • Sunday, February 4, 2018
  • by geekwright
  • Repository
  • 2 Watchers
  • 2 Stars
  • 7,630 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 7 Versions
  • 3 % Grown

The README.md

Po

Scrutinizer Code Quality Code Coverage Build Status, (*1)

Po is a set of objects to assist in reading, manipulating and creating GNU gettext style PO files., (*2)

Installing

The recommended installation method is using composer. To add "geekwright/po" to your composer managed project, use this command:, (*3)

composer require geekwright/po

PHP Support

Po version 1 supports PHP 5.3 and above. Begining with version 2, Po requires a minimum of PHP 7.1., (*4)

Namespace

All Po classes are in the Geekwright\Po namespace., (*5)

Examples

Po provides the capability to create, read, and modify PO and POT files, including the ability to scan PHP sources for gettext style calls to build a POT file. You can connect the pieces however you need, but here are a few examples for common situations., (*6)

Reading a PO File

    try {
        $poFile = new PoFile();
        $poFile->readPoFile('test.po');
        // list all the messages in the file
        $entries = $poFile->getEntries();
        foreach($entries as $entry) {
            echo $entry->getAsString(PoTokens::MESSAGE);
        }
    } catch (UnrecognizedInputException $e) {
        // we had unrecognized lines in the file, decide what to do
    } catch (FileNotReadableException $e) {
        // the file couldn't be read, nothing happened
    }

Get the Plural-Forms Header

    $pluralRule = $poFile->getHeaderEntry()->getHeader('plural-forms');

Add a New Entry

    $entry = new PoEntry;
    $entry->set(PoTokens::MESSAGE, 'This is a message.');
    $entry->set(PoTokens::FLAG, 'fuzzy');
    $poFile->addEntry($entry);

Get the Translation for an Entry

The translation for an entry can be a string, or an array of strings if the Entry is a plural form. This code fragment will assign the translation to $msgstr appropriate for either case., (*7)

    $msgid_plural = $entry->get(PoTokens::PLURAL);
    if (empty($msgid_plural)) {
        $msgstr = $entry->getAsString(PoTokens::TRANSLATED);
    } else {
        $msgstr = $entry->getAsStringArray(PoTokens::TRANSLATED);
    }

Writing a PO File

    try {
        $poFile->writePoFile('test.po');
    } catch (FileNotWriteableException $e) {
        // the file couldn't be written
    }

Create a POT File from PHP sources

    $poFile = new PoFile();
    $poInit = new PoInitPHP($poFile);
    foreach (glob("*.php") as $filename) {
        try {
            $poInit->msginitFile($filename);
        } catch (FileNotReadableException $e) {
            // the souce file couldn't be read, decide what to do
        }
    }
    try {
        $poFile->writePoFile('default.pot');
    } catch (FileNotWriteableException $e) {
        // the file couldn't be written
    }

API

For more information, see the full Po API documentation., (*8)

The Versions

04/02 2018

dev-master

9999999-dev https://github.com/geekwright/Po

Objects to assist in reading, manipulating and creating GNU gettext style PO files

  Sources   Download

GPL-2.0+ GPL-2.0-or-later

The Requires

  • php >7.1

 

The Development Requires

by Richard Griffith

i18n gettext l10n po pot

04/02 2018

v2.0.0

2.0.0.0 https://github.com/geekwright/Po

Objects to assist in reading, manipulating and creating GNU gettext style PO files

  Sources   Download

GPL-2.0-or-later

The Requires

  • php >7.1

 

The Development Requires

by Richard Griffith

i18n gettext l10n po pot

25/08 2016

v1.0.4

1.0.4.0 https://github.com/geekwright/Po

Objects to assist in reading, manipulating and creating GNU gettext style PO files

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0

 

by Richard Griffith

i18n gettext l10n po pot

05/08 2015

v1.0.3

1.0.3.0 https://github.com/geekwright/Po

Objects to assist in reading, manipulating and creating GNU gettext style PO files

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0

 

by Richard Griffith

i18n gettext l10n po pot

08/04 2015

v1.0.2

1.0.2.0 https://github.com/geekwright/Po

Objects to assist in reading, manipulating and creating GNU gettext style PO files

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0

 

by Richard Griffith

i18n gettext l10n po pot

20/03 2015

v1.0.1

1.0.1.0 https://github.com/geekwright/Po

Objects to assist in reading, manipulating and creating GNU gettext style PO files

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0

 

by Richard Griffith

i18n gettext l10n po pot

02/03 2015

v1.0.0

1.0.0.0 https://github.com/geekwright/Po

Objects representing the GNU gettext style PO file.

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0

 

by Richard Griffith

i18n gettext l10n po pot