PHP code example of geekwright / po

1. Go to this page and download the library: Download geekwright/po library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

geekwright / po example snippets


    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
    }


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

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

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

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

    $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
    }