Replaces gettext("message id") and _("message id") with the translated string.
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.
<
p>
Example:
author | Hans Lellelid |
---|---|
version | $Id$ |
access | public |
see | \global\BaseFilterReader |
package | phing.filters |
copyright | 2003 seasonfive. All rights reserved |
__construct(\Reader $in)
The original filter reader is only used for chaining purposes, never for filtering purposes (and indeed it would be useless for filtering purposes, as it has no real data to filter). ChainedReaderHelper uses this placeholder instance to create a chain of real filters.
inherited_from | \BaseFilterReader::__construct() |
---|---|
inherited_from | \BaseParamFilterReader::__construct() |
\Reader
chain(\Reader $reader) : \TranslateGettext
\TranslateGettext
A new filter based on this configuration, but filtering
the specified readerclose()
inherited_from | \FilterReader::close() |
---|---|
inherited_from | \BaseFilterReader::close() |
inherited_from | \BaseParamFilterReader::close() |
\IOException |
if there is an error closing stream |
---|
eof() : boolean
inherited_from | \BaseFilterReader::eof() |
---|---|
inherited_from | \BaseParamFilterReader::eof() |
boolean
getDomain() : string
string
getInitialized() : boolean
inherited_from | \BaseFilterReader::getInitialized() |
---|---|
inherited_from | \BaseParamFilterReader::getInitialized() |
boolean
whether or not the filter is initializedgetLocale() : string
string
getParameters()
inherited_from | \BaseParamFilterReader::getParameters() |
---|
getProject() : object
inherited_from | \BaseFilterReader::getProject() |
---|---|
inherited_from | \BaseParamFilterReader::getProject() |
object
The project this filter is part ofgetResource() : string
that is being read from. This is critical for, e.g., ExpatParser's ability to know the filename that is throwing an ExpatParserException, etc.
inherited_from | \FilterReader::getResource() |
---|---|
inherited_from | \BaseFilterReader::getResource() |
inherited_from | \BaseParamFilterReader::getResource() |
string
log(string $msg, int $level)
inherited_from | \BaseFilterReader::log() |
---|---|
inherited_from | \BaseParamFilterReader::log() |
string
Message to log.
int
Priority level.
mark()
A subsequent call to reset() will move stream position back to last marker (if supported).
inherited_from | \Reader::mark() |
---|---|
inherited_from | \FilterReader::mark() |
inherited_from | \BaseFilterReader::mark() |
inherited_from | \BaseParamFilterReader::mark() |
markSupported() : boolean
inherited_from | \Reader::markSupported() |
---|---|
inherited_from | \FilterReader::markSupported() |
inherited_from | \BaseFilterReader::markSupported() |
inherited_from | \BaseParamFilterReader::markSupported() |
boolean
read(\off $len) : mixed
The original stream is first read in fully, and then translation is performed.
\off
Offset at which to start storing characters.
\IOException |
- if the underlying stream throws an IOException during reading |
---|---|
\BuildException |
- if the correct params are not supplied |
mixed
the filtered stream, or -1 if the end of the resulting stream has been reached.readLine() : \the
The returned String retains the '\n'.
inherited_from | \BaseFilterReader::readLine() |
---|---|
inherited_from | \BaseParamFilterReader::readLine() |
\IOException |
if the underlying reader throws one during reading |
---|
\the
line read, or null
if the end of the
stream has already been reachedready() : boolean
inherited_from | \Reader::ready() |
---|---|
inherited_from | \FilterReader::ready() |
inherited_from | \BaseFilterReader::ready() |
inherited_from | \BaseParamFilterReader::ready() |
boolean
reset()
inherited_from | \FilterReader::reset() |
---|---|
inherited_from | \BaseFilterReader::reset() |
inherited_from | \BaseParamFilterReader::reset() |
setDomain(string $domain)
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
string
setInitialized(boolean $initialized)
inherited_from | \BaseFilterReader::setInitialized() |
---|---|
inherited_from | \BaseParamFilterReader::setInitialized() |
boolean
Whether or not the filter is initialized.
setLocale(string $locale)
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.).
string
setParameters($parameters)
inherited_from | \BaseParamFilterReader::setParameters() |
---|
setProject(\Project $project)
inherited_from | \BaseFilterReader::setProject() |
---|---|
inherited_from | \BaseParamFilterReader::setProject() |
object
The project this filter is part of. Should not be null
.
setReader(\Reader $in)
inherited_from | \FilterReader::setReader() |
---|---|
inherited_from | \BaseFilterReader::setReader() |
inherited_from | \BaseParamFilterReader::setReader() |
skip(int $n)
inherited_from | \FilterReader::skip() |
---|---|
inherited_from | \BaseFilterReader::skip() |
inherited_from | \BaseParamFilterReader::skip() |
int
checkAttributes()
\BuldException |
- if any required attribs aren't set. |
---|
initEnvironment() : void
This method will change some env vars and locale settings; the restoreEnvironment should put them all back :)
see | \global\restoreEnvironment() |
---|
\BuildException |
- if locale cannot be set. |
---|
restoreEnvironment() : void
This does not restore any gettext-specific settings (e.g. textdomain()).
_initialize()
xlateStringCallback(array $matches) : string
This function simply wraps gettext() call, but provides ability to log string replacements. (alternative would be using preg_replace with /e which would probably be faster, but no ability to debug/log.)
array
Array of matches; we're interested in $matches[2].
string
Translated text$_parameters
inherited_from | \BaseParamFilterReader::$$_parameters |
---|
$in : \Reader
inherited_from | \FilterReader::$$in |
---|---|
inherited_from | \BaseFilterReader::$$in |
inherited_from | \BaseParamFilterReader::$$in |
$initialized
inherited_from | \BaseFilterReader::$$initialized |
---|---|
inherited_from | \BaseParamFilterReader::$$initialized |
$project
inherited_from | \BaseFilterReader::$$project |
---|---|
inherited_from | \BaseParamFilterReader::$$project |
$dir
$domain
$locale
$storedLocale
DIR_KEY
DOMAIN_KEY
LOCALE_KEY