\Geekwright\PoPoFile

PoFile - represent all entries in a GNU gettext style PO or POT file as a collection of PoHeader and PoEntry objects.

Summary

Methods
Properties
Constants
__construct()
createKey()
createKeyFromEntry()
setHeaderEntry()
getHeaderEntry()
getEntries()
setUnkeyedEntries()
getUnkeyedEntries()
addEntry()
mergeEntry()
findEntry()
removeEntry()
writePoFile()
dumpString()
readPoFile()
parsePoSource()
$unrecognizedInput
No constants found
No protected methods found
$header
$entries
$unkeyedEntries
N/A
No private methods found
No private properties found
N/A

Properties

$unrecognizedInput

$unrecognizedInput

$var array() $unrecognizedInput

If any lines that cannot be processed are found when reading a po file, the unrecognized input will be recorded here, and an exception will be thrown. No interface is supplied, but this debug data is an array in the form: line number => input line

$header

$header : \Geekwright\Po\PoHeader

Type

PoHeader

$entries

$entries : \Geekwright\Po\PoEntry[]

Type

PoEntry[]

$unkeyedEntries

$unkeyedEntries : \Geekwright\Po\PoEntry[]

Type

PoEntry[]

Methods

__construct()

__construct(\Geekwright\Po\PoHeader|null  $header = null, \Geekwright\Po\PoEntry[]  $entries = array(), \Geekwright\Po\PoEntry[]  $unkeyedEntries = array()) : mixed

Build a PoFile, empty or with provided entries

Parameters

\Geekwright\Po\PoHeader|null $header

header object

\Geekwright\Po\PoEntry[] $entries

associative array po entries

\Geekwright\Po\PoEntry[] $unkeyedEntries

indexed array of po entries. Unkeyed entries are usually comment only entries, such as for obsolete entries.

Returns

mixed —

createKey()

createKey(string|null  $msgid, string|null  $msgctxt = null, string|null  $msgid_plural = null) : string

Build the internal entries array key from id, context and plural id

Parameters

string|null $msgid

the untranslated message of the entry

string|null $msgctxt

the context of the entry, if any

string|null $msgid_plural

the untranslated plural message of the entry, if any

Returns

string —

createKeyFromEntry()

createKeyFromEntry(\Geekwright\Po\PoEntry  $entry) : string

Build an internal entries array key from a PoEntry

Parameters

\Geekwright\Po\PoEntry $entry

the PoEntry to build key from

Returns

string —

setHeaderEntry()

setHeaderEntry(\Geekwright\Po\PoHeader  $header) : void

Replace any existing header with the provided PoHeader

Parameters

\Geekwright\Po\PoHeader $header

header object

getHeaderEntry()

getHeaderEntry() : \Geekwright\Po\PoHeader

Get the current header entry

Returns

\Geekwright\Po\PoHeader —

getEntries()

getEntries() : \Geekwright\Po\PoEntry[]

Get an array of current entries

Returns

\Geekwright\Po\PoEntry[] —

setUnkeyedEntries()

setUnkeyedEntries(\Geekwright\Po\PoEntry[]  $entries) : void

Replace any existing unkeyedEntries with new array of PoEntry objects

Parameters

\Geekwright\Po\PoEntry[] $entries

po entries

getUnkeyedEntries()

getUnkeyedEntries() : \Geekwright\Po\PoEntry[]

Get current array of unkeyed PoEntry objects

Returns

\Geekwright\Po\PoEntry[] —

addEntry()

addEntry(\Geekwright\Po\PoEntry  $entry, bool  $replace = true) : bool

Add an entry to the PoFile using internal key

Parameters

\Geekwright\Po\PoEntry $entry

the PoEntry to add

bool $replace

true to replace any existing entry matching this key, false to not change the PoFile for a duplicated key

Returns

bool —

true if added, false if not

mergeEntry()

mergeEntry(\Geekwright\Po\PoEntry  $newEntry) : bool

Merge an entry with any existing entry with the same key. If the key does not exist, add the entry, otherwise merge comments, references, and flags.

This is intended for use in building a POT, where the handling of translated strings is not a factor.

Parameters

\Geekwright\Po\PoEntry $newEntry

the PoEntry to merge

Returns

bool —

true if merged or added, false if not

findEntry()

findEntry(string  $msgid, string|null  $msgctxt = null, string|null  $msgid_plural = null) : \Geekwright\Po\PoEntry|null

Get an entry based on key values - msgid, msgctxt and msgid_plural

Parameters

string $msgid

the untranslated message of the entry

string|null $msgctxt

the context of the entry, if any

string|null $msgid_plural

the untranslated plural message of the entry, if any

Returns

\Geekwright\Po\PoEntry|null —

matching entry, or null if not found

removeEntry()

removeEntry(\Geekwright\Po\PoEntry  $entry) : bool

Remove an entry from the PoFile

In simple cases, the entry can be found by key. There are several cases where it is not that easy to locate the PoEntry to be removed:

  • the PoEntry was altered, making the generated and stored key different
  • the entry is not keyed and is in unkeyedEntries

In any of these cases, we must loop thru the entry arrays looking for an exact object match, so the cost of the remove goes up

Parameters

\Geekwright\Po\PoEntry $entry

the PoEntry to merge

Returns

bool —

true if remove, false if not

writePoFile()

writePoFile(string  $file) : void

Write any current contents to a po file

Parameters

string $file

po file to write

Throws

\Geekwright\Po\Exceptions\FileNotWritableException

dumpString()

dumpString() : string

Dump the current contents in PO format to a string

Returns

string —

readPoFile()

readPoFile(string  $file, resource|null  $context = null) : void

Replace any current contents with entries from a file

Parameters

string $file

po file/stream to read

resource|null $context

context for stream if required

Throws

\Geekwright\Po\Exceptions\FileNotReadableException

parsePoSource()

parsePoSource(string  $source) : void

Replace any current contents with header and entries from PO souce string

Parameters

string $source

po formatted string to parse

Throws

\Geekwright\Po\Exceptions\UnrecognizedInputException