Project

General

Profile

« Previous | Next » 

Revision 2096

Added by darkviper almost 11 years ago

+ Translate::enablePrivateTable() allows to add more private language definitions
+ Translate::disablePrivateTable()
! TranslateAdaptorWbOldStyle move hardcoded foldername into a variable

View differences:

branches/2.8.x/CHANGELOG
11 11
! = Update/Change
12 12
===============================================================================
13 13

  
14
03 Feb-2014 Build 2096 Manuela v.d.Decken(DarkViper)
15
+ Translate::enablePrivateTable() allows to add more private language definitions
16
+ Translate::disablePrivateTable()
17
! TranslateAdaptorWbOldStyle move hardcoded foldername into a variable
14 18
03 Feb-2014 Build 2095 Manuela v.d.Decken(DarkViper)
15 19
! /functions::make_thumb() set JPG-compression to 100%
16 20
! /database::showError() output text corrected
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.4');
54
if(!defined('REVISION')) define('REVISION', '2095');
54
if(!defined('REVISION')) define('REVISION', '2096');
55 55
if(!defined('SP')) define('SP', '');
branches/2.8.x/wb/framework/Translate.php
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
branches/2.8.x/wb/framework/TranslateAdaptorWbOldStyle.php
36 36
class TranslateAdaptorWbOldStyle implements TranslateAdaptorInterface {
37 37

  
38 38
	protected $sAddon     = '';
39
    protected $sTransDir  = 'languages/';
39 40
	protected $sFilePath  = '';
40 41
/**
41 42
 * Constructor
......
100 101
	private function _getAddonPath()
101 102
	{
102 103
	// set environment
103
		$sAddon   = trim(str_replace('\\', '/', $this->sAddon), '/');
104
		$sAddon   = trim(str_replace('\\', '/', $this->sAddon), '/').'/';
104 105
		$sAppDirname = str_replace('\\', '/', dirname(dirname(__FILE__))).'/';
105
		$sLanguagePath = $sAppDirname.$sAddon.'/languages/';
106
		$sLanguagePath = $sAppDirname.$sAddon.$this->sTransDir;
106 107
		if(is_dir($sLanguagePath) && is_readable($sLanguagePath)) {
107 108
		// valid directory found
108 109
			return $sLanguagePath;
......
111 112
		{
112 113
		// get used acp dirname
113 114
			$sTmp = trim(WbAdaptor::getInstance()->AcpDir, '/');
114
		// if path starts with 'admin/' then replace with used acp dirname
115
			$sLanguagePath = $sAppDirname.preg_replace('/^admin/sU', $sTmp, $sAddon).'/languages/';
115
		// if path starts with 'admin/' then replace with used real acp dirname
116
			$sLanguagePath = $sAppDirname.preg_replace('/^admin/sU', $sTmp, $sAddon).$this->sTransDir;
116 117
			if(is_dir($sLanguagePath) && is_readable($sLanguagePath)) {
117 118
			// valid directory found
118 119
				return $sLanguagePath;

Also available in: Unified diff