.

Translator Class Reference
[Lib]

Translates strings. More...

List of all members.

Public Member Functions

  __construct ($lang=false)
  Constructor.
  translate ($text, $groupname= 'default', $params=NULL)
  Translate string.

Static Public Member Functions

static  Instance ()
  Translations as array.

Public Attributes

  $groups = array()
  Array of translation groups.

Protected Member Functions

  get_translation ($group, $key, $lang)
  Return translation from group for given text and language.
  load_group ($group)
  Load translation group.

Detailed Description

Translates strings.

Singleton

Author:
Gerd Riesselmann

Definition at line 10 of file translator.cls.php.


Constructor & Destructor Documentation

Translator::__construct ( lang = false  ) 

Constructor.

Definition at line 45 of file translator.cls.php.

00045                                                    {
00046                 $this->lang = ($lang) ? $lang : GyroLocale::get_language();
00047         }

Member Function Documentation

Translator::get_translation ( group,
key,
lang  
) [protected]

Return translation from group for given text and language.

Definition at line 141 of file translator.cls.php.

00141                                                                 {
00142                 if (isset($group[$key])) {
00143                         return Arr::get_item($group[$key], $lang, false);
00144                 }
00145                 return false;
00146         }
static Translator::Instance (  )  [static]

Translations as array.

Array is of form Returns singleton instance

Definition at line 35 of file translator.cls.php.

00035                                           {
00036                 if (empty(self::$inst)) {
00037                         self::$inst = new Translator();
00038                 }
00039                 return self::$inst;
00040         }
Translator::load_group ( group  )  [protected]

Load translation group.

Returns:
Array Returns array even if group not found

Definition at line 125 of file translator.cls.php.

00125                                               {
00126                 $ret = array();
00127                 if (Load::classes_in_directory('view/translations/', $group, 'translations', false)) {
00128                         $func = String::plain_ascii($group, '_') . '_load_translations';
00129                         if (function_exists($func)) {
00130                                 $params = array($this->lang);
00131                                 $ret = $func($params);
00132                         }
00133                 }
00134                 
00135                 return $ret;
00136         } 
Translator::translate ( text,
groupname = 'default',
params = NULL  
)

Translate string.

Definition at line 52 of file translator.cls.php.

00052                                                                                  {
00053                 $groupname = Arr::force($groupname, false);
00054                 $arr_groupnames = array();
00055                 foreach($groupname as $g) {
00056                         if ($g !== 'app' && $g !== 'default') {
00057                                 $arr_groupnames[] = $g. '.overloads';
00058                         }
00059                         $arr_groupnames[] = $g;
00060                 }
00061                 
00062                 
00063                 if (count($arr_groupnames) == 0) {
00064                         $arr_groupnames[] = 'default';
00065                 }
00066         
00067                 $ret = false;
00068                 $arr_groupnames[] = 'global';
00069                 foreach($arr_groupnames as $current_groupname) {
00070                         $group = $this->get_group($current_groupname);  
00071                         $ret = $this->get_translation($group, $text, $this->lang);
00072 
00073                         if ($ret !== false) {
00074                                 break;
00075                         }
00076                 }
00077                 
00078                 if ($ret === false) {
00079                         if (Config::has_feature(Config::LOG_TRANSLATIONS)) {
00080                                 $data = array(
00081                                         'groupname' => implode('|', $groupname),
00082                                         'groups' => implode('|', $arr_groupnames),
00083                                         'lang' => $this->lang,
00084                                         'translation' => $text
00085                                 );
00086                                 Load::components('logger');
00087                                 Logger::log('translations', $data);
00088                         }
00089                         $ret = $text;
00090                 }
00091                 
00092                 $ret = $this->apply_params($ret, $params);
00093                 return $ret; 
00094         }

Member Data Documentation

Translator::$groups = array()

Array of translation groups.

Definition at line 24 of file translator.cls.php.


The documentation for this class was generated from the following file: