Properties

$comments_before_headers

$comments_before_headers

$entries

$entries

$headers

$headers

Methods

export_headers()

export_headers() : string

Exports headers to a PO entry

Returns

string —

msgid/msgstr PO entry for this PO file headers, doesn't contain newline at the end

export_entries()

export_entries() : string

Exports all entries to PO format

Returns

string —

sequence of mgsgid/msgstr PO strings, doesn't containt newline at the end

export()

export(bool $include_headers) : string

Exports the whole PO file as a string

Parameters

bool $include_headers

whether to include the headers in the export

Returns

string —

ready for inclusion in PO file string for headers and all the enrtries

export_to_file()

export_to_file(string $filename, bool $include_headers) : bool

Same as {@link export}, but writes the result to a file

Parameters

string $filename

where to write the PO string

bool $include_headers

whether to include tje headers in the export

Returns

bool —

true on success, false on error

set_comment_before_headers()

set_comment_before_headers( $text)

Text to include as a comment before the start of the PO contents

Doesn't need to include # in the beginning of lines, these are added automatically

Parameters

$text

poify()

poify(string $string) : string

Formats a string in PO-style

Parameters

string $string

the string to format

Returns

string —

the poified string

unpoify()

unpoify(string $string) : string

Gives back the original string from a PO-formatted string

Parameters

string $string

PO-formatted string

Returns

string —

enascaped string

prepend_each_line()

prepend_each_line(string $string, string $with)

Inserts $with in the beginning of every new line of $string and returns the modified string

Parameters

string $string

prepend lines in this string

string $with

prepend lines with this string

comment_block()

comment_block(string $text, string $char)

Prepare a text as a comment -- wraps the lines and prepends # and a special character to each line

Parameters

string $text

the comment text

string $char

character to denote a special PO comment,

like :, default is a space

export_entry()

export_entry( $entry) : string|bool

Builds a string from the entry for inclusion in PO file

Parameters

$entry

Returns

string|bool —

PO-style formatted string for the entry or

false if the entry is empty

import_from_file()

import_from_file( $filename)

Parameters

$filename

read_entry()

read_entry( $f,  $lineno)

Parameters

$f
$lineno

read_line()

read_line( $f,  $action)

Parameters

$f
$action

add_comment_to_entry()

add_comment_to_entry( $entry,  $po_comment_line)

Parameters

$entry
$po_comment_line

trim_quotes()

trim_quotes( $s)

Parameters

$s

gettext_select_plural_form()

gettext_select_plural_form( $count)

The gettext implementation of select_plural_form.

It lives in this class, because there are more than one descendand, which will use it and they can't share it effectively.

Parameters

$count

nplurals_and_expression_from_header()

nplurals_and_expression_from_header( $header)

Parameters

$header

make_plural_form_function()

make_plural_form_function( $nplurals,  $expression)

Makes a function, which will return the right translation index, according to the plural forms header

Parameters

$nplurals
$expression

parenthesize_plural_exression()

parenthesize_plural_exression(string $expression) : string

Adds parantheses to the inner parts of ternary operators in plural expressions, because PHP evaluates ternary oerators from left to right

Parameters

string $expression

the expression without parentheses

Returns

string —

the expression with parentheses added

make_headers()

make_headers( $translation)

Parameters

$translation

set_header()

set_header(string $header, string $value)

Sets $header PO header to $value

If the header already exists, it will be overwritten

TODO: this should be out of this class, it is gettext specific

Parameters

string $header

header name, without trailing :

string $value

header value, without trailing \n

add_entry()

add_entry( $entry) : bool

Add entry to the PO structure

Parameters

$entry

Returns

bool —

true on success, false if the entry doesn't have a key

add_entry_or_merge()

add_entry_or_merge( $entry)

Parameters

$entry

set_headers()

set_headers( $headers)

Parameters

$headers

get_header()

get_header( $header)

Parameters

$header

translate_entry()

translate_entry( $entry)

Parameters

$entry

translate()

translate( $singular,  $context)

Parameters

$singular
$context

select_plural_form()

select_plural_form(integer $count)

Given the number of items, returns the 0-based index of the plural form to use

Here, in the base Translations class, the common logic for English is implemented:

0 if there is one element, 1 otherwise

This function should be overrided by the sub-classes. For example MO/PO can derive the logic from their headers.

Parameters

integer $count

number of items

get_plural_forms_count()

get_plural_forms_count()

translate_plural()

translate_plural( $singular,  $plural,  $count,  $context)

Parameters

$singular
$plural
$count
$context

merge_with()

merge_with( $other) : void

Merge $other in the current object.

Parameters

$other

merge_originals_with()

merge_originals_with( $other)

Parameters

$other