| 1 |
1860
|
darkviper
|
<?php
|
| 2 |
|
|
|
| 3 |
|
|
/**
|
| 4 |
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
| 5 |
|
|
*
|
| 6 |
|
|
* This program is free software: you can redistribute it and/or modify
|
| 7 |
|
|
* it under the terms of the GNU General Public License as published by
|
| 8 |
|
|
* the Free Software Foundation, either version 3 of the License, or
|
| 9 |
|
|
* (at your option) any later version.
|
| 10 |
|
|
*
|
| 11 |
|
|
* This program is distributed in the hope that it will be useful,
|
| 12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
|
|
* GNU General Public License for more details.
|
| 15 |
|
|
*
|
| 16 |
|
|
* You should have received a copy of the GNU General Public License
|
| 17 |
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
|
|
*/
|
| 19 |
|
|
|
| 20 |
|
|
/**
|
| 21 |
|
|
* TranslationTable.php
|
| 22 |
|
|
*
|
| 23 |
|
|
* @category Core
|
| 24 |
|
|
* @package Core_Translation
|
| 25 |
|
|
* @author Werner v.d.Decken <wkl@isteam.de>
|
| 26 |
|
|
* @copyright Werner v.d.Decken <wkl@isteam.de>
|
| 27 |
|
|
* @license http://www.gnu.org/licenses/gpl.html GPL License
|
| 28 |
|
|
* @version 0.0.1
|
| 29 |
|
|
* @revision $Revision$
|
| 30 |
|
|
* @link $HeadURL$
|
| 31 |
|
|
* @lastmodified $Date$
|
| 32 |
|
|
* @since File available since 12.01.2013
|
| 33 |
|
|
*/
|
| 34 |
|
|
class TranslationTable {
|
| 35 |
|
|
|
| 36 |
|
|
private $_aTranslations = array();
|
| 37 |
|
|
private $_sSystemLang = 'en';
|
| 38 |
|
|
private $_sDefaultLang = 'en';
|
| 39 |
|
|
private $_sUserLang = 'en';
|
| 40 |
|
|
private $_sAddon = '';
|
| 41 |
|
|
|
| 42 |
|
|
/**
|
| 43 |
|
|
* Constructor
|
| 44 |
|
|
* @param string relative pathname of the Addon (i.e. '' || 'modules/myAddon/')
|
| 45 |
|
|
* @param string Default language code ( 2ALPHA[[_2ALPHA]_2*4ALNUM] )
|
| 46 |
|
|
* @param string User language code ( 2ALPHA[[_2ALPHA]_2*4ALNUM] )
|
| 47 |
|
|
*/
|
| 48 |
|
|
public function __construct($sAddon, $sDefaultLanguage, $sUserLanguage = '')
|
| 49 |
|
|
{
|
| 50 |
|
|
$this->_sDefaultLang = $sDefaultLanguage;
|
| 51 |
|
|
$this->_sUserLang = ($sUserLanguage == '' ? $sDefaultLanguage : $sUserLanguage);
|
| 52 |
|
|
$this->_sAddon = $sAddon;
|
| 53 |
|
|
}
|
| 54 |
|
|
/**
|
| 55 |
|
|
* Load language definitions
|
| 56 |
|
|
* @return TranslationTable a valid translation table object
|
| 57 |
|
|
* @throws TranslationException
|
| 58 |
|
|
*/
|
| 59 |
|
|
public function load($sAdaptor)
|
| 60 |
|
|
{
|
| 61 |
|
|
$c = 'TranslateAdaptor'.$sAdaptor;
|
| 62 |
|
|
$oTmp = new $c($this->_sAddon);
|
| 63 |
|
|
// load default language first
|
| 64 |
|
|
if( ($aResult = $oTmp->loadLanguage($this->_sDefaultLang)) !== false ) {
|
| 65 |
|
|
$this->_aTranslations = $aResult;
|
| 66 |
|
|
}
|
| 67 |
|
|
if($this->_sUserLang != $this->_sDefaultLang) {
|
| 68 |
|
|
// load user language if its not equal default language
|
| 69 |
|
|
if( ($aResult = $oTmp->loadLanguage($this->_sUserLang)) !== false ) {
|
| 70 |
|
|
$this->_aTranslations = array_merge($this->_aTranslations, $aResult);
|
| 71 |
|
|
}
|
| 72 |
|
|
}
|
| 73 |
|
|
if(($this->_sSystemLang != $this->_sUserLang) &&
|
| 74 |
|
|
($this->_sSystemLang != $this->_sDefaultLang)) {
|
| 75 |
|
|
// load system language if its not already loaded
|
| 76 |
|
|
if( ($aResult = $oTmp->loadLanguage($this->_sSystemLang)) !== false ) {
|
| 77 |
|
|
$this->_aTranslations = array_merge($this->_aTranslations, $aResult);
|
| 78 |
|
|
}
|
| 79 |
|
|
}
|
| 80 |
|
|
if(sizeof($this->_aTranslations) == 0) {
|
| 81 |
|
|
// if absolutely no requested language found, simply get the first available
|
| 82 |
|
|
$sFirstLanguage = $oTmp->findFirstLanguage();
|
| 83 |
|
|
// load first found language if its not already loaded
|
| 84 |
|
|
if( ($aResult = $oTmp->loadLanguage($sFirstLanguage)) !== false ) {
|
| 85 |
|
|
$this->_aTranslations = array_merge($this->_aTranslations, $aResult);
|
| 86 |
|
|
}
|
| 87 |
|
|
}
|
| 88 |
|
|
return $this;
|
| 89 |
|
|
}
|
| 90 |
|
|
/**
|
| 91 |
|
|
* Is key available
|
| 92 |
|
|
* @param string Language key
|
| 93 |
|
|
* @return bool
|
| 94 |
|
|
*/
|
| 95 |
|
|
public function __isset($sKey)
|
| 96 |
|
|
{
|
| 97 |
|
|
return isset($this->_aTranslations[$sKey]);
|
| 98 |
|
|
}
|
| 99 |
|
|
/**
|
| 100 |
|
|
* Get translation text
|
| 101 |
|
|
* @param string Language key
|
| 102 |
|
|
* @return string Translation text
|
| 103 |
|
|
*/
|
| 104 |
|
|
public function __get($sKey)
|
| 105 |
|
|
{
|
| 106 |
|
|
if(isset($this->_aTranslations[$sKey])) {
|
| 107 |
|
|
return $this->_aTranslations[$sKey];
|
| 108 |
|
|
}else {
|
| 109 |
|
|
return '';
|
| 110 |
|
|
}
|
| 111 |
|
|
}
|
| 112 |
|
|
/**
|
| 113 |
|
|
* returns the whoole translation array
|
| 114 |
|
|
* @return array
|
| 115 |
|
|
* @deprecated for backward compatibility only. Will be removed shortly
|
| 116 |
|
|
*/
|
| 117 |
|
|
public function getArray()
|
| 118 |
|
|
{
|
| 119 |
|
|
return $this->_aTranslations;
|
| 120 |
|
|
}
|
| 121 |
|
|
} // end of class TranslationTable
|