PHP Class Sepia\PoParser

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of copyright holders nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. https://github.com/raulferras/PHP-po-parser Class to parse .po file and extract its strings.
Exibir arquivo Open project: raulferras/PHP-po-parser Class Usage Examples

Protected Properties

Property Type Description
$entries
$headers
$options
$sourceHandle

Public Methods

Method Description
__construct ( sepia\InterfaceHandler $handler = null, $options = [] )
compile ( ) : string Compiles entries into a string
entries ( ) Gets entries.
getEntries ( )
getHeaders ( ) : array Get headers from .po file
getOptions ( )
parse ( sepia\InterfaceHandler $handle = null ) : array. Reads and parses strings of a .po file.
parseFile ( string $filepath, array $options = [] ) : array. Reads and parses a file
parseString ( $string, array $options = [] ) : array. Reads and parses a string
setEntry ( String $msgid, Array $entry, boolean $createNew = true ) Updates an entry.
setEntryContext ( $msgid, $context = false )
setEntryPlural ( $msgid, $plural = false )
setHeaders ( array $newHeaders ) : boolean Set new headers
writeFile ( string $filepath ) : boolean Writes entries to a po file

Protected Methods

Method Description
clean ( string | array $x ) : string | array. Undos cleanExport actions on a string.
cleanExport ( string $string ) : string Prepares a string to be outputed into a file.
getEntryId ( array $entry ) : string Generates the internal key for a msgid.
isHeader ( array $entry ) : boolean Checks if entry is a header by

Method Details

__construct() public method

public __construct ( sepia\InterfaceHandler $handler = null, $options = [] )
$handler sepia\InterfaceHandler

clean() protected method

Undos cleanExport actions on a string.
protected clean ( string | array $x ) : string | array.
$x string | array
return string | array.

cleanExport() protected method

Prepares a string to be outputed into a file.
protected cleanExport ( string $string ) : string
$string string The string to be converted.
return string

compile() public method

Compiles entries into a string
public compile ( ) : string
return string

entries() public method

Gets entries.
public entries ( )

getEntries() public method

public getEntries ( )

getEntryId() protected method

Generates the internal key for a msgid.
protected getEntryId ( array $entry ) : string
$entry array
return string

getHeaders() public method

Get headers from .po file
public getHeaders ( ) : array
return array

getOptions() public method

public getOptions ( )

isHeader() protected static method

Checks if entry is a header by
protected static isHeader ( array $entry ) : boolean
$entry array
return boolean

parse() public method

Reads and parses strings of a .po file.
public parse ( sepia\InterfaceHandler $handle = null ) : array.
$handle sepia\InterfaceHandler
return array.

parseFile() public static method

Reads and parses a file
public static parseFile ( string $filepath, array $options = [] ) : array.
$filepath string
$options array
return array.

parseString() public static method

Reads and parses a string
public static parseString ( $string, array $options = [] ) : array.
$options array
return array.

setEntry() public method

If entry not found returns false. If $createNew is true, a new entry will be created. $entry is an array that can contain following indexes: - msgid: String Array. Required. - msgstr: String Array. Required. - reference: String Array. - msgctxt: String. Disambiguating context. - tcomment: String Array. Translator comments. - ccomment: String Array. Source comments. - msgid_plural: String Array. - flags: Array. List of entry flags. Example: array('fuzzy','php-format') - previous: Array: Contains previous untranslated strings in a sub array with msgid and msgstr.
public setEntry ( String $msgid, Array $entry, boolean $createNew = true )
$msgid String Id of entry. Be aware that some entries have a multiline msgid. In that case \n must be replaced by the value of 'multiline-glue' option (by default "<##EOL##>").
$entry Array Array with all entry data. Fields not setted will be removed.
$createNew boolean If msgid not found, it will create a new entry. By default true. You want to set this to false if need to change the msgid of an entry.

setEntryContext() public method

public setEntryContext ( $msgid, $context = false )

setEntryPlural() public method

public setEntryPlural ( $msgid, $plural = false )

setHeaders() public method

{code} array( '"Project-Id-Version: \n"', '"Report-Msgid-Bugs-To: \n"', '"POT-Creation-Date: \n"', '"PO-Revision-Date: \n"', '"Last-Translator: none\n"', '"Language-Team: \n"', '"MIME-Version: 1.0\n"', '"Content-Type: text/plain; charset=UTF-8\n"', ); {code}
public setHeaders ( array $newHeaders ) : boolean
$newHeaders array
return boolean

writeFile() public method

Writes entries to a po file
public writeFile ( string $filepath ) : boolean
$filepath string
return boolean

Property Details

$entries protected_oe property

protected $entries

$headers protected_oe property

protected $headers

$options protected_oe property

protected $options

$sourceHandle protected_oe property

protected $sourceHandle