\Geekwright\PoPoHeader

A special PoEntry that represents the header of a GNU gettext style PO or POT file.

The header is the first entry of a PO file. It has an empty string as the "msgid" value, and a set of structured strings compose the "msgstr" value. PoHeader exposes these structured strings so that the individual values can be fetched or set by name.

Summary

Methods
Properties
Constants
__construct()
add()
addQuoted()
addQuotedAtPosition()
get()
getAsString()
getAsStringArray()
set()
dumpEntry()
hasFlag()
addFlag()
getHeader()
setHeader()
setCreateDate()
setRevisionDate()
buildDefaultHeader()
No public properties found
No constants found
dumpEntryComments()
formatQuotedString()
buildStructuredHeaders()
storeStructuredHeader()
formatTimestamp()
$entry
$structuredHeaders
N/A
No private methods found
No private properties found
N/A

Properties

$entry

$entry : array

Type

array

$structuredHeaders

$structuredHeaders

Methods

__construct()

__construct() : mixed

Create an empty header entry

Returns

mixed —

add()

add(string  $type, string  $value) : void

add a value to an array 'type' in the entry

Parameters

string $type

PoToken constant

string $value

value to store

addQuoted()

addQuoted(string  $type, string  $value) : void

add a quoted value to the array 'type' in the entry

Parameters

string $type

PoToken constant

string $value

value to store

addQuotedAtPosition()

addQuotedAtPosition(string  $type, int  $position, string  $value) : void

add a quoted value to the nested array 'type' in the entry

This is mainly useful for translated plurals. Since any plural msgstr can have continuation lines, the message is stored as an array of arrays.

Parameters

string $type

PoToken constant

int $position

array position to store

string $value

value to store

get()

get(string  $type) : string|string[]|null

get the value for a specified type

Parameters

string $type

PoToken constant

Returns

string|string[]|null —

getAsString()

getAsString(string  $type) : string|null

get the value of a specified type as a string

Parameters

string $type

PoToken constant

Returns

string|null —

getAsStringArray()

getAsStringArray(string  $type) : string[]|null

Get the value of a specified type as an array of strings. This is mainly for plural TRANSLATED messages.

Parameters

string $type

PoToken constant

Returns

string[]|null —

set()

set(string  $type, string|string[]|null  $value) : void

set the value of a specified type

Parameters

string $type

PoToken constant

string|string[]|null $value

value to set

dumpEntry()

dumpEntry() : string

Dump this entry as a po/pot file fragment

Returns

string —

hasFlag()

hasFlag(string  $name) : bool

check for presence of a flag

Parameters

string $name

flag to check

Returns

bool —

true if flag is set, otherwise false

addFlag()

addFlag(string  $name) : void

add a flag to the entry

Parameters

string $name

flag to check

getHeader()

getHeader(string  $key) : string|null

Get a header value string by key

Parameters

string $key

case insensitive name of header to return

Returns

string|null —

header string for key or false if not set

setHeader()

setHeader(string  $key, string  $value) : void

Set the value of a header string for a key.

Parameters

string $key

name of header to set. If the header exists, the name is case insensitive. If it is new the given case will be used

string $value

value to set

setCreateDate()

setCreateDate(int|null  $time = null) : void

Set the POT-Creation-Date header

Parameters

int|null $time

unix timestamp, null to use current

setRevisionDate()

setRevisionDate(int|null  $time = null) : void

Set the PO-Revision-Date header

Parameters

int|null $time

unix timestamp, null to use current

buildDefaultHeader()

buildDefaultHeader() : void

Create a default header entry

dumpEntryComments()

dumpEntryComments() : string

Dump the comments for this entry as a po/pot file fragment

Returns

string —

formatQuotedString()

formatQuotedString(string|string[]|null  $value, bool  $bare = false) : string

format a string for output by escaping control and double quote characters, then surrounding with double quotes

Parameters

string|string[]|null $value

string to prepare

bool $bare

true for bare output, default false adds leading space and trailing newline

Returns

string —

buildStructuredHeaders()

buildStructuredHeaders() : void

Populate the internal structuredHeaders property with contents of this entry's "msgstr" value.

storeStructuredHeader()

storeStructuredHeader() : bool

Rebuild the this entry's "msgstr" value using contents of the internal structuredHeaders property.

Returns

bool —

true if rebuilt, false if not

formatTimestamp()

formatTimestamp(int|null  $time = null) : string

Format a timestamp following PO file conventions

Parameters

int|null $time

unix timestamp, null to use current

Returns

string —

formatted timestamp