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.
Example:
author |
Hans Lellelid hans@xmpl.org |
---|---|
version |
$Id: ceb6f10071ec525cd89b9f6dba2564971aa67a72 $ |
see | |
package |
phing.filters |
_initialize()
chain(\Reader $reader) : \TranslateGettext
\TranslateGettext
A new filter based on this configuration, but filtering the specified reader
checkAttributes()
throws |
|
---|---|
close()
throws |
if there is an error closing stream |
---|---|
eof() : boolean
boolean
getDomain() : string
string
getInitialized() : boolean
boolean
whether or not the filter is initialized
getLocale() : string
string
getParameters() : array
array
the parameters to be used by this filter
getProject() : object
object
The project this filter is part of
getResource() : string
This is critical for, e.g., ExpatParser's ability to know the filename that is throwing an ExpatParserException, etc.
string
initEnvironment() : void
This method will change some env vars and locale settings; the restoreEnvironment should put them all back :)
throws |
|
---|---|
see | \TranslateGettext::restoreEnvironment() |
log(string $msg, integer $level = \Project::MSG_INFO) : void
string
Message to log.
integer
Priority level.
mark()
A subsequent call to reset() will move stream position back to last marker (if supported).
markSupported() : boolean
boolean
read(integer $len = null)
If length is specified, then only that number of chars is read, otherwise stream is read until EOF.
integer
readLine() : string
The returned String retains the '\n'.
throws |
if the underlying reader throws one during reading |
---|---|
string
the line read, or null
if the end of the
stream has already been reached
ready() : boolean
boolean
reset()
restoreEnvironment() : void
This does not restore any gettext-specific settings (e.g. textdomain()).
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)
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(array $parameters) : void
throws |
---|
array
Array of parameters to be used by this filter.
Should not be null
.
setProject(object|\Project $project)
skip(integer $n)
integer
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
DOMAIN_KEY
DIR_KEY
LOCALE_KEY
domain :
dir :
locale :
storedLocale :
_parameters : array
var |
---|
array
initialized :
project :