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
Afficher le fichier Open project: vjousse/symfony-1.4 Class Usage Examples

Méthodes publiques

Méthode 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.

Méthodes protégées

Méthode 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

Méthode 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 méthode

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.
Résultat TranslateGettext A new filter based on this configuration, but filtering the specified reader

checkAttributes() protected méthode

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

getDir() public méthode

Gets the root locale directory.
public getDir ( ) : PhingFile
Résultat PhingFile

getDomain() public méthode

Get the current domain.
public getDomain ( ) : string
Résultat string

getLocale() public méthode

Gets the locale to use for translation.
public getLocale ( ) : string
Résultat string

initEnvironment() protected méthode

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

read() public méthode

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

restoreEnvironment() protected méthode

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

setDir() public méthode

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

setDomain() public méthode

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 méthode

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