54 |
54 |
protected $aLoadedAddons = array();
|
55 |
55 |
/** TranslationTable object of the core and additional one activated addon */
|
56 |
56 |
protected $aActiveTranslations = array();
|
|
57 |
// ** */
|
|
58 |
protected $aPrivatePriorities = array();
|
57 |
59 |
/** possible option flags */
|
58 |
60 |
const CACHE_DISABLED = 1; // ( 2^0 )
|
59 |
61 |
const KEEP_MISSING = 2; // ( 2^1 )
|
60 |
|
|
|
62 |
/** types of translation tables */
|
|
63 |
const TABLE_CORE = 0;
|
|
64 |
const TABLE_ADDON = 1;
|
|
65 |
const TABLE_THEME = 2;
|
|
66 |
const TABLE_TEMPLATE = 2;
|
|
67 |
const FIRST_USER_DEFINED_TABLE = 10;
|
|
68 |
const STEP_USER_DEFINED_TABLES = 5;
|
61 |
69 |
/** prevent class from public instancing and get an object to hold extensions */
|
62 |
70 |
protected function __construct() {}
|
63 |
71 |
/** prevent from cloning existing instance */
|
... | ... | |
117 |
125 |
$this->sUserLanguage,
|
118 |
126 |
$this->bUseCache);
|
119 |
127 |
$this->aLoadedAddons['core'] = $oTmp->load($this->sAdaptor);
|
120 |
|
$this->aActiveTranslations[0] = $this->aLoadedAddons['core'];
|
|
128 |
$this->aActiveTranslations[self::TABLE_CORE] = $this->aLoadedAddons['core'];
|
121 |
129 |
if(sizeof($this->aLoadedAddons['core']) == 0) {
|
122 |
130 |
// throw an exception for missing translations
|
123 |
131 |
throw new TranslationException('missing core translations');
|
... | ... | |
168 |
176 |
if(!isset($this->aLoadedAddons[$sAddon])) {
|
169 |
177 |
$this->addAddon($sAddon, $sAdaptor);
|
170 |
178 |
}
|
171 |
|
$this->aActiveTranslations[1] = $this->aLoadedAddons[$sAddon];
|
|
179 |
$this->aActiveTranslations[self::TABLE_ADDON] = $this->aLoadedAddons[$sAddon];
|
172 |
180 |
}
|
173 |
181 |
|
174 |
182 |
}
|
... | ... | |
177 |
185 |
*/
|
178 |
186 |
public function disableAddon()
|
179 |
187 |
{
|
180 |
|
if(isset($this->aActiveTranslations[1])) {
|
181 |
|
unset($this->aActiveTranslations[1]);
|
|
188 |
if(isset($this->aActiveTranslations[self::TABLE_ADDON])) {
|
|
189 |
unset($this->aActiveTranslations[self::TABLE_ADDON]);
|
182 |
190 |
}
|
183 |
191 |
}
|
184 |
|
|
185 |
192 |
/**
|
|
193 |
* Activate additional translation table
|
|
194 |
* @param string $sAddon Addon descriptor (i.e. 'modules\myAddon')
|
|
195 |
* @param int $iPriority (default: self::FIRST_USER_DEFINED_TABLE)
|
|
196 |
* @param string $sAdaptor (optional)Adaptor name (default: $this->sAdaptor)
|
|
197 |
*/
|
|
198 |
public function enablePrivateTable($sAddon, $iPriority = self::FIRST_USER_DEFINED_TABLE, $sAdaptor = null)
|
|
199 |
{
|
|
200 |
switch (($iPriority = intval($iPriority))) :
|
|
201 |
case self::TABLE_THEME:
|
|
202 |
case self::TABLE_TEMPLATE:
|
|
203 |
break;
|
|
204 |
default:
|
|
205 |
$iPriority = ($iPriority < self::FIRST_USER_DEFINED_TABLE ? self::FIRST_USER_DEFINED_TABLE : $iPriority);
|
|
206 |
// search for first free priority position
|
|
207 |
while (array_key_exists($iPriority, $this->aActiveTranslations)) {
|
|
208 |
$iPriority += self::STEP_USER_DEFINED_TABLES;
|
|
209 |
}
|
|
210 |
break;
|
|
211 |
endswitch;
|
|
212 |
// sanitize Addon descriptor
|
|
213 |
$sAddon = str_replace('/', '\\', $sAddon);
|
|
214 |
if(!(strtolower($sAddon) == 'core' || $sAddon == '')) {
|
|
215 |
// if addon is not already in list then add it now
|
|
216 |
if(!isset($this->aLoadedAddons[$sAddon])) {
|
|
217 |
$this->addAddon($sAddon, $sAdaptor);
|
|
218 |
}
|
|
219 |
// copy table into activate list
|
|
220 |
$this->aActiveTranslations[$iPriority] = $this->aLoadedAddons[$sAddon];
|
|
221 |
// save dependency of addon<->priority
|
|
222 |
$this->aPrivatePriorities[$sAddon] = $iPriority;
|
|
223 |
// sort active list ascending by priority
|
|
224 |
ksort($this->aActiveTranslations);
|
|
225 |
}
|
|
226 |
|
|
227 |
}
|
|
228 |
/**
|
|
229 |
* Remove private table from ActiveTranslations table
|
|
230 |
* @param string $sAddon Addon descriptor (i.e. 'modules\myAddon')
|
|
231 |
*/
|
|
232 |
public function disablePrivateTable($sAddon)
|
|
233 |
{
|
|
234 |
// sanitize addon descriptor
|
|
235 |
$sAddon = str_replace('/', '\\', $sAddon);
|
|
236 |
if (isset($this->aPrivatePriorities[$sAddon])) {
|
|
237 |
// get priority for this addon if it's loaded
|
|
238 |
$iPriority = $this->aPrivatePriorities[$sAddon];
|
|
239 |
// check if addon is activated
|
|
240 |
if (isset($this->aActiveTranslations[$iPriority]) && $iPriority >= self::FIRST_USER_DEFINED_TABLE) {
|
|
241 |
// deactivate addon and remove it from priority list
|
|
242 |
unset($this->aActiveTranslations[$iPriority]);
|
|
243 |
unset($this->aPrivatePriorities[$sAddon]);
|
|
244 |
// sort active translation list for ascending priority
|
|
245 |
ksort($this->aActiveTranslations);
|
|
246 |
}
|
|
247 |
}
|
|
248 |
}
|
|
249 |
/**
|
186 |
250 |
* Is key available
|
187 |
251 |
* @param string Language key
|
188 |
252 |
* @return bool
|
+ Translate::enablePrivateTable() allows to add more private language definitions
+ Translate::disablePrivateTable()
! TranslateAdaptorWbOldStyle move hardcoded foldername into a variable