Class PoFileParser

Parses file in PO format

Namespace: Cake\I18n\Parser

Method Summary

  • _addMessage() protected

    Saves a translation item to the messages.

  • parse() public

    Parses portable object (PO) format.

Method Detail

_addMessage() protected

_addMessage(array $messages, array $item)

Saves a translation item to the messages.

Parameters

array $messages

The messages array being collected from the file

array $item

The current item being inspected

parse() public

parse(string $resource)

Parses portable object (PO) format.

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

string $resource

The file name to parse

Returns

array

© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/4.1/class-Cake.I18n.Parser.PoFileParser.html