PoFileParser
in package
Parses file in PO format
Tags
Table of Contents
Methods
- parse() : array<string|int, mixed>
- Parses portable object (PO) format.
- _addMessage() : void
- Saves a translation item to the messages.
Methods
parse()
Parses portable object (PO) format.
public
parse(string $resource) : array<string|int, mixed>
From https://www.gnu.org/software/gettext/manual/gettext.html#PO-Files we should be able to parse files having:
white-space
translator-comments
#. extracted-comments #: reference... #, flag... #| msgid previous-untranslated-string msgid untranslated-string msgstr translated-string
extra or different lines are:
#| msgctxt previous-context #| msgid previous-untranslated-string msgctxt context
#| msgid previous-untranslated-string-singular #| msgid_plural previous-untranslated-string-plural msgid untranslated-string-singular msgid_plural untranslated-string-plural msgstr[0] translated-string-case-0 ... msgstr[N] translated-string-case-n
The definition states:
- white-space and comments are optional.
- msgid "" that an empty singleline defines a header.
This parser sacrifices some features of the reference implementation the differences to that implementation are as follows.
- Translator and extracted comments are treated as being the same type.
- Message IDs are allowed to have other encodings as just US-ASCII.
Items with an empty id are ignored.
Parameters
- $resource : string
-
The file name to parse
Return values
array<string|int, mixed>_addMessage()
Saves a translation item to the messages.
protected
_addMessage(array<string|int, mixed> &$messages, array<string|int, mixed> $item) : void
Parameters
- $messages : array<string|int, mixed>
-
The messages array being collected from the file
- $item : array<string|int, mixed>
-
The current item being inspected