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

Class: Translation2

Source Location: /Translation2-2.0.0beta7/Translation2.php

Class Overview


Translation2 base class


Author(s):

Copyright:

  • 2004-2005 Lorenzo Alberton

Variables

Methods


Child classes:

Translation2_Admin
Administration utilities for translation string management

Inherited Variables

Inherited Methods


Class Details

[line 65]
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 94]

Current pageID
  • Access: protected

Type:   string


[ Top ]

$lang = array()

[line 87]

Default lang
  • Access: protected

Type:   array


[ Top ]

$options = array()

[line 80]

Class options

Type:   array


[ Top ]

$params = array()

[line 101]

Array parameters
  • Access: protected

Type:   array


[ Top ]

$storage =  ''

[line 74]

Storage object
  • Access: protected

Type:   object


[ Top ]



Method Detail

Translation2 (Constructor)   [line 109]

Translation2 Translation2( )

Constructor

[ Top ]

factory   [line 134]

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

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   $storageDriver   —  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)
   $driver   — 

[ Top ]

get   [line 454]

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.


Parameters:

string   $stringID   — 
string   $pageID   — 
string   $langID   — 
string   $defaultText   —  Text to display when the string is empty NB: This parameter is only used in the DefaultText decorator

[ Top ]

getDecorator   [line 236]

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

Parameters:

string   $decorator   —  Name of the decorator

[ Top ]

getLang   [line 298]

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

Parameters:

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

[ Top ]

getLangs   [line 333]

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

get langs

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


Parameters:

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

[ Top ]

getPage   [line 495]

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


Parameters:

string   $pageID   — 
string   $langID   — 

[ Top ]

getRaw   [line 426]

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

Get translated string (as-is)

Parameters:

string   $stringID   — 
string   $pageID   — 
string   $langID   — 
string   $defaultText   —  Text to display when the string is empty

[ Top ]

getRawPage   [line 476]

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


Parameters:

string   $pageID   — 
string   $langID   — 

[ Top ]

getStringID   [line 513]

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

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

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   — 

[ Top ]

replaceEmptyStringsWithKeys   [line 401]

void replaceEmptyStringsWithKeys( $strings, mixed $params)

Replace empty strings with their stringID

Parameters:

mixed   $params   — 
   $strings   — 

[ Top ]

setContainerOptions   [line 183]

void setContainerOptions( array $options)

Set some storage driver options
  • Access: protected

Parameters:

array   $options   — 

[ Top ]

setLang   [line 260]

void setLang( string $langID)

Set default lang

Set the language that shall be used when retrieving strings.


Parameters:

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

[ Top ]

setPageID   [line 280]

void setPageID( [ $pageID = null], string $langID)

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.


Parameters:

string   $langID   — 
   $pageID   — 

[ Top ]

setParams   [line 349]

void setParams( [array $params = null])

Set parameters for next string

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


Parameters:

array   $params   — 

[ Top ]

_replaceParams   [line 368]

void _replaceParams( $strings, mixed $params)

Replace parameters in strings
  • Access: protected

Parameters:

mixed   $params   — 
   $strings   — 

[ Top ]

__clone   [line 529]

void __clone( )

Clone internal object references

This method is called automatically by PHP5

  • Access: protected

[ Top ]


Documentation generated on Mon, 11 Mar 2019 14:18:26 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.