translateExtractor provides a framework for extracting terms to be translated by parsing templates and classes for a project. It requires a backend system to do the actual extraction of terms. Several are available in the package, however others can be created by implementing the abstract base.
The various extractor backends should compile data into an array which can then be used by the compilers. These build actual language files from the data and ensure it is the correct format for the various translateAdaptor types. Again additional output formats can be supported by adding another compiler implementation.
For some formats e.g. Gettext, additional transformation is required. Additionally this format can be created using the gettext development package and tools.
A basic example to extract all marked up text from a website called example.com:
$oExtractor = new translateExtractor(
translateExtractor::BACKEND_TEMPLATE_SMARTY,
translateExtractor::COMPILER_QT,
array(
translateExtractor::OPTIONS_BACKEND => array(
translateExtractorBackend::OPTIONS_SCAN => translateExtractorBackend::OPTIONS_RESOURCE_WEBSITE,
translateExtractorBackend::OPTIONS_RESOURCE_RECURSE => true,
translateExtractorBackend::OPTIONS_RESOURCE_EXTN => 'tpl',
translateExtractorBackend::OPTIONS_RESOURCE_LOCATION => 'example.com',
translateExtractorBackend::OPTIONS_TRANSLATION_MARKER_TYPE => OPTIONS_TRANSLATION_MARKER_TAG,
translateExtractorBackend::OPTIONS_TRANSLATION_OPENING_MARKER = '{t}',
translateExtractorBackend::OPTIONS_TRANSLATION_CLOSING_MARKER = '{/t}',
),
translateExtractor::OPTIONS_COMPILER => array(
translateExtractorCompiler::OPTIONS_SOURCE_LANGUAGE => 'en',
translateExtractorCompiler::OPTIONS_TARGET_LANGUAGE => 'fr',
translateExtractorCompiler::OPTIONS_USE_CDATA_SECTIONS => false,
)
)
);
$langData = $oExtractor->execute();
public __construct($inBackend, $inCompiler, [$inOptions = array()])
Creates a new extractor object, using $inBackend for extraction and $inCompiler for compiling
$inOptions is an associative array containing options for both the backend and compiler and has the following format:
$options = array(
translateExtractor::OPTIONS_BACKEND => array(),
translateExtractor::OPTIONS_COMPILER => array(),
);
public static getExtractorBackends()
Returns the array of valid backend engines
public static getExtractorCompilers()
Returns the array of valid compiler engines
public static isValidBackend($inBackend)
Returns true if $inBackend is a valid backend
public static isValidCompiler($inCompiler)
Returns true if $inCompiler is a valid compiler
public execute()
Runs the extraction and compilation processes, returns the compiled data
public extract()
Attempts to locate and extract the terms for translation
public compile()
Attempts to compile the extracted strings into the requested format
public getTranslationTable()
Returns the translation table from the extractor backend
public getLanguageData()
Returns the compiled language data
public reset()
Resets the object to defaults
public getBackend()
Returns $_Backend
public setBackend($inBackend, [$inOptions = array()])
Set $_Backend to $inBackend
public getCompiler()
Returns $_Compiler
public setCompiler($inCompiler, [$inOptions = array()])
Set $_Compiler to $inCompiler
public getOptions($inComponent, [$inOption = null])
Returns options for the component or a specific option, null if not found
public getBackendOptions([$inOption = null])
Returns the backend option or all of them if $inOption is null
public getCompilerOptions([$inOption = null])
Returns the compiler option or all of them if $inOption is null
public setOptions([$inOptions = array()])
Set options to $inOptions
$inOptions should be an array containing the component key and then key value pairs of options. Alternatively use {@link translateExtractor::setBackendOptions} or {@link translateExtractor::setCompilerOptions} to set those individually.
public setBackendOptions([$inOptions = array()])
Sets the backend options
public setCompilerOptions([$inOptions = array()])
Sets the compiler options
Posted by: Scorpio Documentor (Writer), in Translate on 19 Nov 2009 @ 20:39
Tags: translate, translateextractor,
This
work is licenced under a
Creative Commons Licence.