phing-filters
[ class tree: phing-filters ] [ index: phing-filters ] [ all elements ]

Class: TranslateGettext

Source Location: /filters/TranslateGettext.php

Class Overview

Reader
   |
   --FilterReader
      |
      --BaseFilterReader
         |
         --BaseParamFilterReader
            |
            --TranslateGettext

Replaces gettext("message id") and _("message id") with the translated string.


Author(s):

Version:

  • $Revision: 526 $ $Date: 2009-08-11 14:11:17 +0200 (Tue, 11 Aug 2009) $

Copyright:

  • © 2003 seasonfive. All rights reserved

Implements interfaces:

Constants

Methods


Inherited Variables

Inherited Methods

Class: BaseParamFilterReader

BaseParamFilterReader::getParameters()
BaseParamFilterReader::setParameters()

Class: BaseFilterReader

BaseFilterReader::__construct()
Constructor used by Phing's introspection mechanism.
BaseFilterReader::eof()
Returns whether the end of file has been reached with input stream.
BaseFilterReader::getInitialized()
Returns the initialized status.
BaseFilterReader::getProject()
Returns the project this filter is part of.
BaseFilterReader::log()
Convenience method to support logging in filters.
BaseFilterReader::read()
Reads characters.
BaseFilterReader::readLine()
Reads a line of text ending with '\n' (or until the end of the stream).
BaseFilterReader::setInitialized()
Sets the initialized status.
BaseFilterReader::setProject()
Sets the project to work with.

Class: FilterReader

FilterReader::__construct()
FilterReader::close()
FilterReader::getResource()
FilterReader::read()
Read data from source.
FilterReader::reset()
FilterReader::setReader()
FilterReader::skip()

Class: Reader

Reader::close()
Close stream.
Reader::getResource()
Returns the filename, url, etc. that is being read from.
Reader::mark()
If supported, places a "marker" (like a bookmark) at current stream position.
Reader::markSupported()
Whether marking is supported.
Reader::read()
Read data from source.
Reader::ready()
Is stream ready for reading.
Reader::reset()
Reset the current position in stream to beginning or last mark (if supported).
Reader::skip()
Move stream position relative to current pos.

Class Details

[line 47]
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:

 




Tags:

author:  Hans Lellelid <hans@xmpl.org>
version:  $Revision: 526 $ $Date: 2009-08-11 14:11:17 +0200 (Tue, 11 Aug 2009) $
copyright:  © 2003 seasonfive. All rights reserved
see:  BaseFilterReader
access:  public


[ Top ]


Class Methods


method chain [line 252]

TranslateGettext chain( $reader)

Creates a new TranslateGettext filter using the passed in Reader for instantiation.



Tags:

return:  A new filter based on this configuration, but filtering the specified reader



Implementation of:
ChainableReader::chain()
Returns a reader with the same configuration as this one, but filtering input from the specified reader.

Parameters:

Reader   $reader   A Reader object providing the underlying stream. Must not be
  1. null
.

[ Top ]

method checkAttributes [line 125]

void checkAttributes( )

Make sure that required attributes are set.



Tags:

throws:  BuldException - if any required attribs aren't set.
access:  protected


[ Top ]

method getDir [line 98]

PhingFile getDir( )

Gets the root locale directory.



[ Top ]

method getDomain [line 82]

string getDomain( )

Get the current domain.



[ Top ]

method getLocale [line 117]

string getLocale( )

Gets the locale to use for translation.



[ Top ]

method initEnvironment [line 140]

void initEnvironment( )

Initialize the gettext/locale environment.

This method will change some env vars and locale settings; the restoreEnvironment should put them all back :)




Tags:

see:  TranslateGettext::restoreEnvironment()
throws:  BuildException - if locale cannot be set.
access:  protected


[ Top ]

method read [line 197]

mixed read( [ $len = null])

Returns the filtered stream.

The original stream is first read in fully, and then translation is performed.




Tags:

return:  the filtered stream, or -1 if the end of the resulting stream has been reached.
throws:  IOException - if the underlying stream throws an IOException during reading
throws:  BuildException - if the correct params are not supplied


Overrides BaseFilterReader::read() (Reads characters.)

Parameters:

   $len  

[ Top ]

method restoreEnvironment [line 165]

void restoreEnvironment( )

Restores environment settings and locale.

This does _not_ restore any gettext-specific settings (e.g. textdomain()).




Tags:

access:  protected


[ Top ]

method setDir [line 90]

void setDir( $dir)

Sets the root locale directory.



Parameters:

PhingFile   $dir  

[ Top ]

method setDomain [line 74]

void setDomain( string $domain)

Set the text domain to use.

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




Parameters:

string   $domain  

[ Top ]

method setLocale [line 109]

void setLocale( string $locale)

Sets the locale to use for translation.

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.).




Parameters:

string   $locale  

[ Top ]


Class Constants

DIR_KEY =  "dir"

[line 52]


[ Top ]

DOMAIN_KEY =  "domain"

[line 51]


[ Top ]

LOCALE_KEY =  "locale"

[line 53]


[ Top ]



Documentation generated on Mon, 19 Oct 2009 10:52:16 +0200 by phpDocumentor 1.4.3