PHP Class TranslateGettext, symfony-1.4

Gettext is great for creating multi-lingual sites, but in some cases (e.g. for performance reasons) you may wish to replace the gettext calls with the translations of the strings; that's what this task is for. Note that this is similar to ReplaceTokens, but both the find and the replace aspect is more complicated -- hence this is a separate, stand-alone filter.

Example:


See also: BaseFilterReader
Author: Hans Lellelid ([email protected])
Inheritance: extends BaseParamFilterReader, implements ChainableReader
Datei anzeigen Open project: vjousse/symfony-1.4 Class Usage Examples

Public Methods

Method Description
chain ( Reader $reader ) : TranslateGettext Creates a new TranslateGettext filter using the passed in Reader for instantiation.
getDir ( ) : PhingFile Gets the root locale directory.
getDomain ( ) : string Get the current domain.
getLocale ( ) : string Gets the locale to use for translation.
read ( $len = null ) : mixed Returns the filtered stream.
setDir ( PhingFile $dir ) Sets the root locale directory.
setDomain ( string $domain ) Set the text domain to use.
setLocale ( string $locale ) Sets the locale to use for translation.

Protected Methods

Method Description
checkAttributes ( ) Make sure that required attributes are set.
initEnvironment ( ) : void Initialize the gettext/locale environment.
restoreEnvironment ( ) : void Restores environment settings and locale.

Private Methods

Method Description
_initialize ( ) Parses the parameters if this filter is being used in "generic" mode.
xlateStringCallback ( array $matches ) : string Performs gettext translation of msgid and returns translated text.

Method Details

chain() public method

Creates a new TranslateGettext filter using the passed in Reader for instantiation.
public chain ( Reader $reader ) : TranslateGettext
$reader Reader A Reader object providing the underlying stream. Must not be null.
return TranslateGettext A new filter based on this configuration, but filtering the specified reader

checkAttributes() protected method

Make sure that required attributes are set.
protected checkAttributes ( )

getDir() public method

Gets the root locale directory.
public getDir ( ) : PhingFile
return PhingFile

getDomain() public method

Get the current domain.
public getDomain ( ) : string
return string

getLocale() public method

Gets the locale to use for translation.
public getLocale ( ) : string
return string

initEnvironment() protected method

This method will change some env vars and locale settings; the restoreEnvironment should put them all back :)
See also: restoreEnvironment()
protected initEnvironment ( ) : void
return void

read() public method

The original stream is first read in fully, and then translation is performed.
public read ( $len = null ) : mixed
return mixed the filtered stream, or -1 if the end of the resulting stream has been reached.

restoreEnvironment() protected method

This does _not_ restore any gettext-specific settings (e.g. textdomain()).
protected restoreEnvironment ( ) : void
return void

setDir() public method

Sets the root locale directory.
public setDir ( PhingFile $dir )
$dir PhingFile

setDomain() public method

The text domain must correspond to the name of the compiled .mo files. E.g. "messages" ==> $dir/LC_MESSAGES/messages.mo "mydomain" ==> $dir/LC_MESSAGES/mydomain.mo
public setDomain ( string $domain )
$domain string

setLocale() public method

Note that for gettext() to work, you have to make sure this locale is specific enough for your system (e.g. some systems may allow an 'en' locale, but others will require 'en_US', etc.).
public setLocale ( string $locale )
$locale string