Project

General

Profile

« Previous | Next » 

Revision 1873

Added by darkviper over 11 years ago

some small fixes in packet Translate
added option to disable cache
added option to keep placeholders if no translation was found

View differences:

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

  
14

  
14
27 Feb-2013 Build 1873 Werner v.d.Decken(DarkViper)
15
# some small fixes in packet Translate
15 16
25 Feb-2013 Build 1872 Dietmar Woellbrink (Luisehahne)
16 17
# bugfix preferences timezone, date_format, time_format settings, backend and frontend
17 18
23 Feb-2013 Build 1871 Dietmar Woellbrink (Luisehahne)
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', '1872');
54
if(!defined('REVISION')) define('REVISION', '1873');
55 55
if(!defined('SP')) define('SP', '');
branches/2.8.x/wb/framework/TranslateAdaptorInterface.php
22 22
 *
23 23
 * @category     Core
24 24
 * @package      Core_Translation
25
 * @copyright    Werner v.d.Decken <wkl@isteam.de>
25 26
 * @author       Werner v.d.Decken <wkl@isteam.de>
26
 * @copyright    Werner v.d.Decken <wkl@isteam.de>
27 27
 * @license      http://www.gnu.org/licenses/gpl.html   GPL License
28 28
 * @version      0.0.1
29 29
 * @revision     $Revision$
branches/2.8.x/wb/framework/Translate.php
22 22
 *
23 23
 * @category     Core
24 24
 * @package      Core_Translation
25
 * @copyright    Werner v.d.Decken <wkl@isteam.de>
25 26
 * @author       Werner v.d.Decken <wkl@isteam.de>
26
 * @copyright    Werner v.d.Decken <wkl@isteam.de>
27 27
 * @license      http://www.gnu.org/licenses/gpl.html   GPL License
28 28
 * @version      0.0.1
29 29
 * @revision     $Revision$
30 30
 * @link         $HeadURL$
31 31
 * @lastmodified $Date$
32 32
 * @since        File available since 12.01.2013
33
 * @description
33
 * @description  basic class of the Translate package
34 34
 */
35 35
class Translate {
36 36
	
37
//  @object hold the Singleton instance 
37
/** holds the active singleton instance */
38 38
	private static $_oInstance     = null;
39
	
39
/** name of the default adaptor */	
40 40
	protected $sAdaptor            = 'WbOldStyle';
41
/** setting for the system language (default: en) */
41 42
	protected $sSystemLanguage     = 'en';
43
/** setting for the default runtime language (default: en) */
42 44
	protected $sDefaultLanguage    = 'en';
45
/** setting for the user defined language (default: en) */
43 46
	protected $sUserLanguage       = 'en';
47
/** switch cache on/off */
44 48
	protected $bUseCache           = true;
45
/** TranslationTable objects of all loaded addons */
49
/** defines if the keys of undefines translation should be preserved */
50
	protected $bRemoveMissing      = false;
51
/** can hold up to 31 boolean option settings */
52
	protected $iOptions            = 0;
53
/** List of loaded translation tables */
46 54
	protected $aLoadedAddons       = array();
47 55
/** TranslationTable object of the core and additional one activated addon */	
48 56
	protected $aActiveTranslations = array();
57
/** possible option flags */	
58
	const CACHE_DISABLED = 1; // ( 2^0 )
59
	const KEEP_MISSING   = 2; // ( 2^1 )
49 60
	
50
	const CACHE_ENABLED = true;
51
	const CACHE_DISABLED = false;
52

  
53 61
/** prevent class from public instancing and get an object to hold extensions */
54 62
	protected function  __construct() {}
55 63
/** prevent from cloning existing instance */
......
67 75
	}
68 76
/**
69 77
 * Initialize the Translations
78
 * @param string SystemLanguage code ('de' || 'de_CH' || 'de_CH_uri')
70 79
 * @param string DefaultLanguage code ('de' || 'de_CH' || 'de_CH_uri')
71 80
 * @param string UserLanguage code ('de' || 'de_CH' || 'de_CH_uri')
81
 * @param string Name of the adaptor to use
82
 * @param integer possible options (DISABLE_CACHE | KEEP_MISSING)
72 83
 * @throws TranslationException
73 84
 */
74
	public function initialize($sSystemLanguage, $sDefaultLanguage, $sUserLanguage = '', 
75
	                           $sAdaptor = 'WbOldStyle', $bUseCache = self::CACHE_ENABLED) 
85
	public function initialize($sSystemLanguage, 
86
	                           $sDefaultLanguage, 
87
	                           $sUserLanguage = '', 
88
	                           $sAdaptor = 'WbOldStyle', 
89
	                           $iOptions = 0)
76 90
	{
77 91
		if(!class_exists('TranslateAdaptor'.$sAdaptor)) {
78 92
			throw new TranslationException('unable to load adaptor: '.$sAdaptor);
79 93
		}
80
		$this->bUseCache = $bUseCache;
81
		$this->sAdaptor = 'TranslateAdaptor'.$sAdaptor;
94
		$this->sAdaptor       = 'TranslateAdaptor'.$sAdaptor;
95
		$this->bUseCache      = (($iOptions & self::CACHE_DISABLED) == 0);
96
		$this->bRemoveMissing = (($iOptions & self::KEEP_MISSING) == 0);
82 97
		// if no system language is set then use language 'en'
83 98
		$this->sSystemLanguage = (trim($sSystemLanguage) == '' ? 'en' : $sSystemLanguage);
84 99
		// if no default language is set then use system language
......
87 102
		                            : $sDefaultLanguage);
88 103
		// if no user language is set then use default language
89 104
		$this->sUserLanguage = (trim($sUserLanguage) == '' 
90
		                         ? $this->sDefaultLanguage 
105
		                         ? $this->sDefaultLanguage
91 106
		                         : $sUserLanguage);
92
		$sPattern = '/^[a-z]{2,3}(?:(?:\_[a-z]{2})?(?:\_[a-z0-9]{2,4})?)$/siU';
107
		$sPattern = '/^[a-z]{2,3}(?:(?:[_-][a-z]{2})?(?:[_-][a-z0-9]{2,4})?)$/siU';
93 108
		// validate language codes
94 109
		if(preg_match($sPattern, $this->sSystemLanguage) &&
95 110
		   preg_match($sPattern, $this->sDefaultLanguage) &&
......
177 192
 */	
178 193
	public function __get($sKey)
179 194
	{
180
		$sRetval = '';
195
		$sRetval = ($this->bRemoveMissing ? '' : '#'.$sKey.'#');
181 196
		foreach($this->aActiveTranslations as $oAddon) {
182 197
			if(isset($oAddon->$sKey)) {
183 198
			// search the last matching translation (Core -> Addon)
branches/2.8.x/wb/framework/initialize.php
154 154
// define constant systemenvironment settings ---
155 155
	date_default_timezone_set('UTC');
156 156
	if(!defined('MAX_TIME')) { define('MAX_TIME', (pow(2, 31)-1)); } // 32-Bit Timestamp of 19 Jan 2038 03:14:07 GMT
157
	if(!defined('DO_NOT_TRACK')) { define('DO_NOT_TRACK', (isset($_SERVER['HTTP_DNT']))); }
157
	$sTmp = (isset($_SERVER['HTTP_DNT']) && $_SERVER['HTTP_DNT'] != '') ? $_SERVER['HTTP_DNT'] : '0';
158
	if(!defined('DO_NOT_TRACK')) { define('DO_NOT_TRACK', ($sTmp[0] == '1')); }
158 159
// register WB basic autoloader ---
159 160
	$sTmp = dirname(__FILE__).'/WbAutoloader.php';
160
	if(!class_exists('WbAutoloader', false)){ include($sTmp); }
161
	if(!class_exists('WbAutoloader')){ 
162
		include($sTmp);
163
	}
161 164
	WbAutoloader::doRegister(array(ADMIN_DIRECTORY=>'a', 'modules'=>'m'));
162 165
// register TWIG autoloader ---
163 166
	$sTmp = dirname(dirname(__FILE__)).'/include/Sensio/Twig/lib/Twig/Autoloader.php';
164
	if(!class_exists('Twig_Autoloader', false)){ include($sTmp); }
167
	if(!class_exists('Twig_Autoloader')) { 
168
		include($sTmp); 
169
	}
165 170
	Twig_Autoloader::register();
166 171
// aktivate exceptionhandler ---
167 172
	if(!function_exists('globalExceptionHandler')) {
......
188 193
									 ? false 
189 194
									 : $aSetting['value'])
190 195
								 );
191
			$aSetting['name'] = strtoupper($aSetting['name']);
192
			if($aSetting['name'] == 'STRING_FILE_MODE') {
193
				$iTmp = ((intval(octdec($aSetting['value'])) & ~0111)|0600);
194
				define('OCTAL_FILE_MODE', $iTmp);
195
				define('STRING_FILE_MODE', sprintf('0%03o', $iTmp));
196
			}elseif($aSetting['name'] == 'STRING_DIR_MODE') {
197
				$iTmp = (intval(octdec($aSetting['value'])) |0711);
198
				define('OCTAL_DIR_MODE', $iTmp);
199
				define('STRING_DIR_MODE', sprintf('0%03o', $iTmp));
200
			}else {
201
			// make global const from setting
202
				@define($aSetting['name'], $aSetting['value']);
203
			}
196
			$sSettingName = strtoupper($aSetting['name']);
197
			switch($sSettingName):
198
				case 'STRING_FILE_MODE':
199
					$iTmp = ((intval(octdec($aSetting['value'])) & ~0111)|0600);
200
					define('OCTAL_FILE_MODE', $iTmp);
201
					define('STRING_FILE_MODE', sprintf('0%03o', $iTmp));
202
					break;
203
				case 'STRING_DIR_MODE':
204
					$iTmp = (intval(octdec($aSetting['value'])) |0711);
205
					define('OCTAL_DIR_MODE', $iTmp);
206
					define('STRING_DIR_MODE', sprintf('0%03o', $iTmp));
207
				case 'PAGES_DIRECTORY':
208
					// sanitize pages_directory
209
					$sTmp = trim($aSetting['value'], '/');
210
					$sTmp = ($sTmp == '' ? '' : '/'.$sTmp);
211
					define('PAGES_DIRECTORY', $sTmp);
212
					break;
213
				default: // make global const from setting
214
					@define($aSetting['name'], $aSetting['value']);
215
					break;
216
			endswitch;
204 217
		}
205 218
	}else { throw new AppException($database->get_error()); }
206 219
// set error-reporting from loaded settings ---
......
286 299
	}
287 300
// load and activate new global translation table
288 301
	Translate::getInstance()->initialize('en',
289
	                                     (defined('DEFAULT_LANGUAGE') ? DEFAULT_LANGUAGE : ''), 
290
	                                     (defined('LANGUAGE') ? LANGUAGE : ''), 
291
	                                     'WbOldStyle',
292
	                                     Translate::CACHE_ENABLED);
302
										 (defined('DEFAULT_LANGUAGE') ? DEFAULT_LANGUAGE : ''), 
303
										 (defined('LANGUAGE') ? LANGUAGE : '') 
304
										);
293 305
// *** END OF FILE ***********************************************************************
294 306
	
branches/2.8.x/wb/framework/TranslationTable.php
22 22
 *
23 23
 * @category     Core
24 24
 * @package      Core_Translation
25
 * @copyright    Werner v.d.Decken <wkl@isteam.de>
25 26
 * @author       Werner v.d.Decken <wkl@isteam.de>
26
 * @copyright    Werner v.d.Decken <wkl@isteam.de>
27 27
 * @license      http://www.gnu.org/licenses/gpl.html   GPL License
28 28
 * @version      0.0.1
29 29
 * @revision     $Revision$
......
42 42
	protected $oReg          = null;
43 43
	protected $sTempPath     = '';
44 44
	protected $iDirMode      = 0777;
45
/**
45
	protected $bUseCache     = true;
46

  
47
	/**
46 48
 * Constructor
47 49
 * @param string relative pathname of the Addon (i.e. '' || 'modules/myAddon/')
48 50
 * @param string System language code ( 2*3ALPHA[[_2ALPHA]_2*4ALNUM] )
49 51
 * @param string Default language code ( 2*3ALPHA[[_2ALPHA]_2*4ALNUM] )
50 52
 * @param string User language code ( 2*3ALPHA[[_2ALPHA]_2*4ALNUM] )
53
 * @param boolean true if caching is enabled
51 54
 */	
52 55
	public function __construct($sAddon, 
53
	                            $sSystemLanguage, $sDefaultLanguage, $sUserLanguage,
54
	                            $bUseCache = Translate::CACHE_ENABLED)
56
	                            $sSystemLanguage, 
57
	                            $sDefaultLanguage, 
58
	                            $sUserLanguage,
59
	                            $bUseCache = true)
55 60
	{
56 61
		$this->bUseCache             = $bUseCache;
57 62
		$this->sSystemLang           = $sSystemLanguage;
......
195 200
		$sConcatedLang = '';
196 201
		foreach($aLangCode as $sLang)
197 202
		{ // iterate all segments of the language code
198
			if( ($aResult = $oAdaptor->loadLanguage($sConcatedLang.$sLang)) !== false ) {
203
			$sConcatedLang .= ($sConcatedLang == '' ? '' :  '_').$sLang;
204
			if( ($aResult = $oAdaptor->loadLanguage($sConcatedLang)) !== false ) {
199 205
				$aTranslations = array_merge($aTranslations, $aResult);
200 206
			}
201 207
		}
branches/2.8.x/wb/framework/TranslateAdaptorWbOldStyle.php
22 22
 *
23 23
 * @category     Core
24 24
 * @package      Core_Translation
25
 * @copyright    Werner v.d.Decken <wkl@isteam.de>
25 26
 * @author       Werner v.d.Decken <wkl@isteam.de>
26
 * @copyright    Werner v.d.Decken <wkl@isteam.de>
27 27
 * @license      http://www.gnu.org/licenses/gpl.html   GPL License
28 28
 * @version      0.0.1
29 29
 * @revision     $Revision$
......
44 44
	public function __construct($sAddon = '')
45 45
	{
46 46
		$this->sAddon = $sAddon;
47
		$this->sFilePath = str_replace('\\', '/', dirname(dirname(__FILE__))).'/'.$sAddon;
48
		$this->sFilePath = rtrim(str_replace('\\', '/', $this->sFilePath), '/').'/languages/';
47
		$this->sFilePath = str_replace('\\', '/', dirname(dirname(__FILE__)).'/'.$sAddon);
48
		$this->sFilePath = rtrim($this->sFilePath, '/').'/languages/';
49 49
	}
50 50
/**
51 51
 * Load languagefile
......
72 72
	}
73 73
/**
74 74
 * Find first existing language
75
 * @return string Code of first found language
75
 * @return string Code of first found basic language
76 76
 */
77 77
	public function findFirstLanguage()
78 78
	{
......
81 81
		if(is_readable($this->sFilePath)) {
82 82
			$iterator = new DirectoryIterator($this->sFilePath);
83 83
			foreach ($iterator as $oFileInfo) {
84
				$sPattern = '/^[a-z0-9]{2}(?:(?:\_[a-z0-9]{2})?(?:\_[a-z0-9]{2,4})?)\.php/siU';
84
				$sPattern = '/^[a-z]{2,3}\.php/siU';
85 85
				if(!preg_match($sPattern, $oFileInfo->getBasename())) { continue; }
86 86
				if($oFileInfo->isReadable()) {
87 87
					$sRetval = $oFileInfo->getBasename('.php');

Also available in: Unified diff