Class Translation



Translation class Class allows to store and retrieve all the strings on multilingual site in the database. Class connects to any database using PHP PEAR extension - so it needs PEAR to be installed to work correctly. The object should be created for every page. While creation all the strings connected with specific page and the strings connected with all the pages on the site are loaded into variable, so access to them is quite fast and does not overload database server connection.

File: c:/www/translation_012/translation.class.012.php
Version: 1.2
Author(s): Wojciech Zieliński <>


public void Translation( string $PageName, string $LanguageID, string $pear_DSN );


string $PageName
the page identifier. It identifies strings connected with specific page on the site
string $LanguageID
language id. All the languages are stored on the database on specific ID's.
string $pear_DSN
PEAR DSN string for database connection

Method Summary

Private Methods
gstr() Translated string retrieval
getLangName() Active language name retrieval
getOtherLangs() Other languages retrieval
getMetaTags() META tags retrieval

Variable Summary

Private Variables
Strings Strings of the given page array - for fast access purposes
PageName Page identifier
LanguageID Language identifier
db Connection to database

Detailed Method List

Private Methods

private string gstr( string $StringName, array $Params );
Translated string retrieval
Retrieves the strings basing on string indetifier


string $StringName
string identifier - unique for the page as well as for the strings, that are available on all the pages.
array $Params
string may be parametrized - and the paraters, that will be "inserted" into string may be typen into this array. It means, that &&1&& string will be replaced by 1st array element; string &&2&& will be replaced by 2nd array element; string &&3&& will be replaced by 3rd array element etc.


string $String retrieved string

private string getLangName( void );
Active language name retrieval
Retrieves the name of active language


string $LangName current active language name or PEAR_ERROR object in case of problems

private array getOtherLangs( void );
Other languages retrieval
Retrieves names of all other languages, not the active.


array $OtherLangs 2-dimensional array (0..)('id', 'name') for all the languages defined in DB but the current selected one. In case of DB error - returns PEAR_ERROR object.

private string getMetaTags( void );
META tags retrieval
Retrievs the META tags that should be added on the top of translated page, so the translated characters will be correctly displayed on client's browser.


string $MetaTags string with configured in DB META tags for selected language. In case of DB error - returns PEAR_ERROR object.

Detailed Variable List

Private Variables

private array Strings;
Strings of the given page array - for fast access purposes

private string PageName;
Page identifier

private string LanguageID;
Language identifier

private DB db;
Connection to database

Phpdoc 0.21alpha, Ulf Wendel