translateExtractorBackend

translateExtractorBackend provides a means of handling different types of files and markup of text to be translated. It requires a concrete implementation into a specific type e.g. the requirements for parsing a PHP class or script file are different to a Smarty (or other) template.

The extractor should be able to operate on a single file or directory and should create an internal array of all strings to be translated. The array is structured as: "messageID => current text" so whatever the marked up text is becomes the key that it will be identified by.

There are some restrictions placed on text. For example within PHP files the text to be translated should be entirely enclosed in quotes - double or single, but the string should not be separated. If variables need to be added or displayed then ideally these should be replaced with using sprintf. In Smarty templates any var can be embedded as the template is pre-filtered to translate the text with the template then being parsed again for variables.

Extractor Backend Options

The backend can have its own options, but the following are shared:

scan.type -- either file, directory or website scan.location -- path of the file or directory scan.dir.recurse -- (optional) set to recurse directories, default no scan.extension -- (optional) an array of extensions that will be scanned lang.source -- source language lang.target -- the target language, required by some compilers e.g. xliff trans.marker.type -- translation marker type, either function or tag trans.marker.open -- the identifying opening tag or function name trans.marker.close -- the closing tag, not required for function


Methods

public __construct([$inOptions = array()])

Creates a new backend object

public reset()

Resets the object

public validateOptions()

Checks that all options have been set before processing methods are called

protected abstract _validateOptions()

Backend specific validation instructions

public parseResource()

Locates all files that should be processed by the backend storing the results in $_Resources

protected _parseFile()

Parses a single file resource

protected _parseDirectory()

Parses a directory resource

protected _parseWebsite()

Parses a website resource

protected _findTranslationTargets($inSiteConfig, $inController)

Interrogates the controller to locate all the template files

public extract()

Extracts strings from the resources

protected abstract _extract($inFile)

The custom extraction implementation

public getOptions([$inOption = null])

Returns options or a specific option, null if not found

public setOptions([$inOptions = array()])

Set options to $inOptions

$inOptions should be an array containing the key value pairs of options.

public getTranslationTable()

Returns $_TranslationTable

public setTranslationTable($inTranslationTable)

Set $_TranslationTable to $inTranslationTable

public addTranslation($inString)

Adds the string to the translation array, but only if it does not exist already

public removeTranslation($inString)

Removes $inString from the translation table

public hasTranslation($inString)

Returns true if $inString is in the translation table

public getResources()

Returns $_Resources

public setResources($inResources)

Set $_Resources to $inResources

public addResource($inFile)

Adds the file to the list of resources, only if it does not already exist

<  1  >