Revision 1902
Added by darkviper over 11 years ago
branches/2.8.x/CHANGELOG | ||
---|---|---|
11 | 11 |
! = Update/Change |
12 | 12 |
=============================================================================== |
13 | 13 |
|
14 |
12 May-2013 Build 1902 Werner v.d.Decken(DarkViper) |
|
15 |
+ added posssibility to use different adaptors for each module |
|
16 |
+ added new adaptor to access language definitions in a MySQL database |
|
14 | 17 |
19 Apr-2013 Build 1901 Werner v.d.Decken(DarkViper) |
15 | 18 |
# little corrections in class Password |
16 | 19 |
18 Apr-2013 Build 1900 Werner v.d.Decken(DarkViper) |
branches/2.8.x/wb/admin/interface/version.php | ||
---|---|---|
51 | 51 |
|
52 | 52 |
// check if defined to avoid errors during installation (redirect to admin panel fails if PHP error/warnings are enabled) |
53 | 53 |
if(!defined('VERSION')) define('VERSION', '2.8.3'); |
54 |
if(!defined('REVISION')) define('REVISION', '1901');
|
|
54 |
if(!defined('REVISION')) define('REVISION', '1902');
|
|
55 | 55 |
if(!defined('SP')) define('SP', ''); |
branches/2.8.x/wb/framework/TranslationTable.php | ||
---|---|---|
90 | 90 |
$this->aTranslations = $this->loadCacheFile($sCacheFile); |
91 | 91 |
}else { |
92 | 92 |
$bLanguageFound = false; |
93 |
if(!class_exists($sAdaptor)) { |
|
94 |
throw new TranslationException('unable to load adaptor: '.$sAdaptor); |
|
95 |
} |
|
93 | 96 |
$oAdaptor= new $sAdaptor($this->sAddon); |
94 | 97 |
if(!$oAdaptor instanceof TranslateAdaptorInterface) { |
95 | 98 |
$sMsg = 'Class ['.$sAdaptor.'] does not implement the ' |
branches/2.8.x/wb/framework/TranslateAdaptorWb3Mysql.php | ||
---|---|---|
1 |
<?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 |
* TranslateAdaptorWb3Mysql.php |
|
22 |
* |
|
23 |
* @category Core |
|
24 |
* @package Core_Translation |
|
25 |
* @copyright Werner v.d.Decken <wkl@isteam.de> |
|
26 |
* @author 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.05.2013 |
|
33 |
* @description Loads translation table from MySQL Language table<br /> |
|
34 |
* Can handle Languagecodes like 'de_DE_BAY' (2ALPHA_2ALPHA_2-4ALNUM) |
|
35 |
*/ |
|
36 |
|
|
37 |
class TranslateAdaptorWb3Mysql implements TranslateAdaptorInterface { |
|
38 |
|
|
39 |
protected $sAddon = ''; |
|
40 |
protected $sFilePath = ''; |
|
41 |
private $_oDb = null; |
|
42 |
private $_sTableName = 'translations'; |
|
43 |
/** |
|
44 |
* Constructor |
|
45 |
* @param string descriptor of the Addon (i.e. '' || 'modules\myAddon' |
|
46 |
*/ |
|
47 |
public function __construct($sAddon = '') |
|
48 |
{ |
|
49 |
$this->_oDb = WbDatabase::getInstance(); |
|
50 |
$this->sAddon = $sAddon; |
|
51 |
} |
|
52 |
/** |
|
53 |
* Load languagefile |
|
54 |
* @param string $sLangCode |
|
55 |
* @return array|bool an array of translations or FALSE on error |
|
56 |
*/ |
|
57 |
public function loadLanguage($sLangCode) |
|
58 |
{ |
|
59 |
$aTranslations = array(); |
|
60 |
$sql = 'SELECT `keyword`, `value` ' |
|
61 |
. 'FROM `'.$this->_oDb->getTablePrefix.$this->_sTableName.'` ' |
|
62 |
. 'WHERE `addon`=\''.$this->sAddon.'\' ' |
|
63 |
. 'AND `lang` LIKE \''.addcslashes($sLangCode ,'_?').'\''; |
|
64 |
if(($oTransSet = $this->_oDb->query($sql))) { |
|
65 |
while($aTrans = $oTransSet->fetchRow(MYSQL_ASSOC)) { |
|
66 |
$aTranslations[] = $aTrans; |
|
67 |
} |
|
68 |
} |
|
69 |
return $aTranslations; |
|
70 |
} |
|
71 |
/** |
|
72 |
* Find first existing language |
|
73 |
* @return string Code of first found basic language |
|
74 |
*/ |
|
75 |
public function findFirstLanguage() |
|
76 |
{ |
|
77 |
$sql = 'SELECT `lang` ' |
|
78 |
. 'FROM `'.$this->_oDb->getTablePrefix.$this->_sTableName.'` ' |
|
79 |
. 'WHERE `addon`=\''.$this->sAddon.'\' ' |
|
80 |
. 'AND `lang` LIKE \'__\''; |
|
81 |
$sfirstMatch = $this->_oDb->get_one($sql); |
|
82 |
return ($sfirstMatch ? $sfirstMatch : 'en'); |
|
83 |
} |
|
84 |
|
|
85 |
} |
|
86 |
// end of class TranslateAdaptorWb3Mysql |
|
87 |
|
|
0 | 88 |
branches/2.8.x/wb/framework/Translate.php | ||
---|---|---|
92 | 92 |
throw new TranslationException('unable to load adaptor: '.$sAdaptor); |
93 | 93 |
} |
94 | 94 |
$this->sAdaptor = 'TranslateAdaptor'.$sAdaptor; |
95 |
$this->bUseCache = (($iOptions & self::CACHE_DISABLED) == 0);
|
|
96 |
$this->bRemoveMissing = (($iOptions & self::KEEP_MISSING) == 0);
|
|
95 |
$this->bUseCache = (!($iOptions & self::CACHE_DISABLED));
|
|
96 |
$this->bRemoveMissing = (!($iOptions & self::KEEP_MISSING));
|
|
97 | 97 |
// if no system language is set then use language 'en' |
98 | 98 |
$this->sSystemLanguage = (trim($sSystemLanguage) == '' ? 'en' : $sSystemLanguage); |
99 | 99 |
// if no default language is set then use system language |
... | ... | |
132 | 132 |
/** |
133 | 133 |
* Add new addon |
134 | 134 |
* @param string Addon descriptor (i.e. 'modules\myAddon') |
135 |
* @param string (optional)Adaptor name (default: $this->sAdaptor) |
|
135 | 136 |
* @return bool |
136 | 137 |
*/ |
137 |
public function addAddon($sAddon) |
|
138 |
public function addAddon($sAddon, $sAdaptor = null)
|
|
138 | 139 |
{ |
140 |
if($sAdaptor) { |
|
141 |
if(!class_exists('TranslateAdaptor'.$sAdaptor)) { |
|
142 |
throw new TranslationException('unable to load adaptor: '.$sAdaptor); |
|
143 |
} |
|
144 |
$sAdaptor = 'TranslateAdaptor'.$sAdaptor; |
|
145 |
}else { |
|
146 |
$sAdaptor = $this->sAdaptor; |
|
147 |
} |
|
139 | 148 |
$sAddon = str_replace('/', '\\', $sAddon); |
140 | 149 |
if(!(strtolower($sAddon) == 'core' || $sAddon == '' || isset($this->aLoadedAddons[$sAddon]))) { |
141 | 150 |
// load requested addon translations if needed and possible |
... | ... | |
144 | 153 |
$this->sDefaultLanguage, |
145 | 154 |
$this->sUserLanguage, |
146 | 155 |
$this->bUseCache); |
147 |
$this->aLoadedAddons[$sAddon] = $oTmp->load($this->sAdaptor);
|
|
156 |
$this->aLoadedAddons[$sAddon] = $oTmp->load($sAdaptor); |
|
148 | 157 |
} |
149 | 158 |
} |
150 | 159 |
/** |
151 | 160 |
* Activate Addon |
152 | 161 |
* @param string Addon descriptor (i.e. 'modules\myAddon') |
162 |
* @param string (optional)Adaptor name (default: $this->sAdaptor) |
|
153 | 163 |
*/ |
154 |
public function enableAddon($sAddon) |
|
164 |
public function enableAddon($sAddon, $sAdaptor = null)
|
|
155 | 165 |
{ |
156 | 166 |
$sAddon = str_replace('/', '\\', $sAddon); |
157 | 167 |
if(!(strtolower($sAddon) == 'core' || $sAddon == '')) { |
158 | 168 |
if(!isset($this->aLoadedAddons[$sAddon])) { |
159 |
$this->addAddon($sAddon); |
|
169 |
$this->addAddon($sAddon, $sAdaptor);
|
|
160 | 170 |
} |
161 | 171 |
$this->aActiveTranslations[1] = $this->aLoadedAddons[$sAddon]; |
162 | 172 |
} |
Also available in: Unified diff
added posssibility to use different adaptors for each module
added new adaptor to access language definitions in a MySQL database