PHP Класс 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:


См. также: BaseFilterReader
Автор: Hans Lellelid ([email protected])
Наследование: extends BaseParamFilterReader, implements ChainableReader
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
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.

Защищенные методы

Метод Описание
checkAttributes ( ) Make sure that required attributes are set.
initEnvironment ( ) : void Initialize the gettext/locale environment.
restoreEnvironment ( ) : void Restores environment settings and locale.

Приватные методы

Метод Описание
_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.

Описание методов

chain() публичный Метод

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.
Результат TranslateGettext A new filter based on this configuration, but filtering the specified reader

checkAttributes() защищенный Метод

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

getDir() публичный Метод

Gets the root locale directory.
public getDir ( ) : PhingFile
Результат PhingFile

getDomain() публичный Метод

Get the current domain.
public getDomain ( ) : string
Результат string

getLocale() публичный Метод

Gets the locale to use for translation.
public getLocale ( ) : string
Результат string

initEnvironment() защищенный Метод

This method will change some env vars and locale settings; the restoreEnvironment should put them all back :)
См. также: restoreEnvironment()
protected initEnvironment ( ) : void
Результат void

read() публичный Метод

The original stream is first read in fully, and then translation is performed.
public read ( $len = null ) : mixed
Результат mixed the filtered stream, or -1 if the end of the resulting stream has been reached.

restoreEnvironment() защищенный Метод

This does _not_ restore any gettext-specific settings (e.g. textdomain()).
protected restoreEnvironment ( ) : void
Результат void

setDir() публичный Метод

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

setDomain() публичный Метод

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() публичный Метод

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