Translation2
[ class tree: Translation2 ] [ index: Translation2 ] [ all elements ]

Class: Translation2

Source Location: /Translation2-2.0.4/Translation2.php

Class Overview


Translation2 base class


Author(s):

Copyright:

  • 2004-2008 Lorenzo Alberton

Variables

Methods


Child classes:

Translation2_Admin
Administration utilities for translation string management
Translation2_Decorator
Translation2_Decorator. Base Decorator class for Translation2

Inherited Variables

Inherited Methods


Class Details

[line 81]
Translation2 base class

This class provides an easy way to retrieve all the strings for a multilingual site or application from a data source (i.e. a db, an xml file or a gettext file).



[ Top ]


Class Variables

$currentPageID =  null

[line 110]

Current pageID
  • Access: protected

Type:   string


[ Top ]

$lang = array()

[line 103]

Default lang
  • Access: protected

Type:   array


[ Top ]

$options = array()

[line 96]

Class options

Type:   array


[ Top ]

$params = array()

[line 117]

Array of parameters for the adapter class
  • Access: protected

Type:   array


[ Top ]

$storage =  ''

[line 90]

Storage object
  • Access: protected

Type:   object


[ Top ]



Method Detail

Translation2 (Constructor)   [line 125]

Translation2 Translation2( )

Constructor

[ Top ]

factory   [line 151]

object Translation2 &factory( string $driver, [mixed $options = ''], [array $params = array()])

Return a Translation2 instance already initialized
  • Return: instance or PEAR_Error on failure

Overridden in child classes as:

Translation2_Admin::factory()
Return a Translation2_Admin instance already initialized

Parameters:

string   $driver     Type of the storage driver
mixed   $options     Additional options for the storage driver (example: if you are using DB as the storage driver, you have to pass the dsn string here)
array   $params     Array of parameters for the adapter class (i.e. you can set here the mappings between your table/field names and the ones used by this class)

[ Top ]

get   [line 512]

string get( string $stringID, [string $pageID = TRANSLATION2_DEFAULT_PAGEID], [string $langID = null], [string $defaultText = ''])

Get translated string

First check if the string is cached, if not => fetch the page from the container and cache it for later use. If the string is empty, check the fallback language; if the latter is empty too, then return the $defaultText.


Overridden in child classes as:

Translation2_Decorator::get()
Get translated string
Translation2_Admin_Decorator_Autoadd::get()
Get a translated string
Translation2_Decorator_Iconv::get()
Get the translated string, in the new encoding
Translation2_Decorator_DefaultText::get()
Get translated string
Translation2_Decorator_CacheLiteFunction::get()
Get translated string
Translation2_Decorator_CacheMemory::get()
Get translated string
Translation2_Decorator_Lang::get()
Get translated string
Translation2_Decorator_SpecialChars::get()
Get translated string
Translation2_Decorator_ErrorText::get()
Get translated string
Translation2_Decorator_UTF8::get()
Get translated string

Parameters:

string   $stringID     ID of the string
string   $pageID     ID of the page/group containing the string
string   $langID     ID of the language
string   $defaultText     Text to display when the string is empty NB: This parameter is only used in the DefaultText decorator

[ Top ]

getDecorator   [line 257]

object Decorator &getDecorator( string $decorator)

Return an instance of a decorator

This method is used to get a decorator instance. A decorator can be seen as a filter, i.e. something that can change or handle the values of the objects/vars that pass through.

  • Return: object reference

Overridden in child classes as:

Translation2_Decorator::getDecorator()
Return an instance of a decorator

Parameters:

string   $decorator     Name of the decorator

[ Top ]

getLang   [line 344]

mixed getLang( [string $langID = null], [string $format = 'name'])

get lang info

Get some extra information about the language (its full name, the localized error text, ...)

  • Return: [string | array], depending on $format

Overridden in child classes as:

Translation2_Decorator::getLang()
Get language info
Translation2_Decorator_CacheLiteFunction::getLang()
get lang info

Parameters:

string   $langID     language ID
string   $format     ['name', 'meta', 'error_text', 'array']

[ Top ]

getLangs   [line 380]

array|PEAR_Error getLangs( [string $format = 'name'])

get langs

Get some extra information about the languages (their full names, the localized error text, their codes, ...)


Overridden in child classes as:

Translation2_Decorator::getLangs()
Get languages
Translation2_Decorator_CacheLiteFunction::getLangs()
get langs

Parameters:

string   $format     ['ids', 'names', 'array']

[ Top ]

getPage   [line 555]

array getPage( [string $pageID = TRANSLATION2_DEFAULT_PAGEID], [string $langID = null])

Get an entire group of strings

Same as getRawPage, but resort to fallback language and replace parameters when needed


Overridden in child classes as:

Translation2_Decorator::getPage()
Same as getRawPage, but resort to fallback language and replace parameters when needed
Translation2_Decorator_Iconv::getPage()
Same as getRawPage, but apply transformations when needed
Translation2_Decorator_DefaultText::getPage()
Replace empty strings with their $stringID
Translation2_Decorator_CacheLiteFunction::getPage()
Same as getRawPage, but resort to fallback language and replace parameters when needed
Translation2_Decorator_CacheMemory::getPage()
Same as getRawPage, but resort to fallback language and replace parameters when needed
Translation2_Decorator_Lang::getPage()
Same as getRawPage, but resort to fallback language and replace parameters when needed
Translation2_Decorator_SpecialChars::getPage()
Same as getRawPage, but apply transformations when needed
Translation2_Decorator_ErrorText::getPage()
Same as getRawPage, but resort to fallback language and replace parameters when needed
Translation2_Decorator_UTF8::getPage()
Same as getRawPage, but resort to fallback language and replace parameters when needed

Parameters:

string   $pageID     ID of the page/group containing the string
string   $langID     ID of the language

[ Top ]

getRaw   [line 483]

string|PEAR_Error getRaw( string $stringID, [string $pageID = TRANSLATION2_DEFAULT_PAGEID], [string $langID = null], [string $defaultText = ''])

Get translated string (as-is)

Overridden in child classes as:

Translation2_Decorator::getRaw()
Get translated string
Translation2_Decorator_CacheLiteFunction::getRaw()
Get translated string (as-is)
Translation2_Decorator_CacheMemory::getRaw()
Get translated string (as-is)

Parameters:

string   $stringID     ID of the string to be translated
string   $pageID     ID of the page/group containing the string
string   $langID     ID of the language
string   $defaultText     Text to display when the string is empty

[ Top ]

getRawPage   [line 535]

array getRawPage( [string $pageID = TRANSLATION2_DEFAULT_PAGEID], [string $langID = null])

Get the array of strings in a page

Fetch the page (aka "group of strings) from the container, without applying any formatting and without replacing the parameters


Overridden in child classes as:

Translation2_Decorator::getRawPage()
Get the array of strings in a page
Translation2_Decorator_CacheLiteFunction::getRawPage()
Get the array of strings in a page
Translation2_Decorator_CacheMemory::getRawPage()
Get the array of strings in a page

Parameters:

string   $pageID     ID of the page/group containing the string
string   $langID     ID of the language

[ Top ]

getStringID   [line 574]

string getStringID( string $string, [string $pageID = TRANSLATION2_DEFAULT_PAGEID])

Get the stringID for the given string. This method is the reverse of get().

Overridden in child classes as:

Translation2_Decorator::getStringID()
Get the stringID for the given string. This method is the reverse of get().
Translation2_Decorator_DefaultText::getStringID()
Get the stringID for the given string. This method is the reverse of get().
Translation2_Decorator_CacheLiteFunction::getStringID()
Get translated string

Parameters:

string   $string     This is NOT the stringID, this is a real string. The method will search for its matching stringID, and then it will return the associate string in the selected language.
string   $pageID     ID of the page/group containing the string

[ Top ]

replaceEmptyStringsWithKeys   [line 457]

array replaceEmptyStringsWithKeys( array $strings)

Replace empty strings with their stringID

Overridden in child classes as:

Translation2_Decorator::replaceEmptyStringsWithKeys()
Replace empty strings with their stringID

Parameters:

array   $strings     array of strings to be replaced if empty

[ Top ]

setCharset   [line 281]

void|PEAR_Error setCharset( string $charset)

Set charset used to read/store the translations

Overridden in child classes as:

Translation2_Decorator::setCharset()
Set charset used to read/store the translations

Parameters:

string   $charset     character set (encoding)

[ Top ]

setContainerOptions   [line 201]

void setContainerOptions( array $options)

Set some storage driver options
  • Access: protected

Overridden in child classes as:

Translation2_Decorator::setContainerOptions()
Set some storage driver options

Parameters:

array   $options     array of options

[ Top ]

setLang   [line 301]

true|PEAR_Error setLang( string $langID)

Set default lang

Set the language that shall be used when retrieving strings.


Overridden in child classes as:

Translation2_Decorator::setLang()
Set default language
Translation2_Decorator_CacheLiteFunction::setLang()
Set default lang

Parameters:

string   $langID     language code (for instance, 'en' or 'it')

[ Top ]

setPageID   [line 324]

self setPageID( [string $pageID = null])

Set default page

Set the page (aka "group of strings") that shall be used when retrieving strings. If you set it, you don't have to state it in each get() call.


Overridden in child classes as:

Translation2_Decorator::setPageID()
Set default page

Parameters:

string   $pageID     ID of the default page

[ Top ]

setParams   [line 398]

self setParams( [array $params = null])

Set parameters for next string

Set the replacement for the parameters in the string(s). Parameter delimiters are customizable.


Overridden in child classes as:

Translation2_Decorator::setParams()
Set parameters for next string

Parameters:

array   $params     array of replacement parameters

[ Top ]

_replaceParams   [line 421]

mixed _replaceParams( mixed $strings)

Replace parameters in strings
  • Access: protected

Overridden in child classes as:

Translation2_Decorator::_replaceParams()
Replace parameters in strings

Parameters:

mixed   $strings     strings where the replacements must occur

[ Top ]

__clone   [line 591]

void __clone( )

Clone internal object references

This method is called automatically by PHP5

  • Access: protected

Overridden in child classes as:

Translation2_Decorator::__clone()
Clone internal object references

[ Top ]


Documentation generated on Mon, 06 Dec 2010 00:00:30 +0000 by phpDocumentor 1.4.3. PEAR Logo Copyright © PHP Group 2004.