Skip to content
This repository
Browse code

MINOR Stability fixes on new tokenizer implementation of i18nTextColl…

…ector, allowing to specify writer and locale arguments on task execution
  • Loading branch information...
commit 7ce1572d3833234adcf63a32b5aad2ec71cfc355 1 parent df08c2f
Ingo Schommer authored
24  i18n/i18nTextCollector.php
@@ -209,6 +209,11 @@ public function collectFromCode($content, $module) {
209 209
 				if($id == T_STRING && $text == '_t') {
210 210
 					// start definition
211 211
 					$inTransFn = true;
  212
+				} elseif($inTransFn && $id == T_VARIABLE) {
  213
+					// Dynamic definition from provideEntities - skip
  214
+					$inTransFn = false;
  215
+					$inConcat = false;
  216
+					$currentEntity = array();
212 217
 				} elseif($inTransFn && $id == T_CONSTANT_ENCAPSED_STRING) {
213 218
 					// Fixed quoting escapes, and remove leading/trailing quotes
214 219
 					if(preg_match('/^\'/', $text)) {
@@ -221,8 +226,11 @@ public function collectFromCode($content, $module) {
221 226
 						$text = preg_replace('/"$/', '', $text);
222 227
 					}
223 228
 					
224  
-					if($inConcat) $currentEntity[count($currentEntity)-1] .= $text;
225  
-					else $currentEntity[] = $text;
  229
+					if($inConcat) {
  230
+						$currentEntity[count($currentEntity)-1] .= $text;
  231
+					} else {
  232
+						$currentEntity[] = $text;
  233
+					} 
226 234
 				} 
227 235
 			} elseif($inTransFn && $token == '.') {
228 236
 				$inConcat = true;	
@@ -239,6 +247,12 @@ public function collectFromCode($content, $module) {
239 247
 		}
240 248
 		
241 249
 		foreach($entities as $entity => $spec) {
  250
+			// call without master language definition
  251
+			if(!$spec) {
  252
+				unset($entities[$entity]);
  253
+				continue; 
  254
+			}
  255
+
242 256
 			unset($entities[$entity]);
243 257
 			$entities[$this->normalizeEntity($entity, $module)] = $spec;
244 258
 		}
@@ -291,7 +305,7 @@ function collectFromEntityProviders($filePath) {
291 305
 			// Not all classes can be instanciated without mandatory arguments,
292 306
 			// so entity collection doesn't work for all SilverStripe classes currently
293 307
 			// Requires PHP 5.1+
294  
-			if(class_exists($class) && in_array('i18nEntityProvider', class_implements($class))) {
  308
+			if(class_exists($class, false) && in_array('i18nEntityProvider', class_implements($class))) {
295 309
 				$reflectionClass = new ReflectionClass($class);
296 310
 				if($reflectionClass->isAbstract()) continue;
297 311
 
@@ -327,7 +341,7 @@ protected function normalizeEntity($fullName, $_namespace = null) {
327 341
 		// and skip the processing. This is mostly used for
328 342
 		// dynamically translating static properties, e.g. looping
329 343
 		// through $db, which are detected by {@link collectFromEntityProviders}.
330  
-		if(strpos('$', $entity) !== FALSE) return false;
  344
+		if($entity && strpos('$', $entity) !== FALSE) return false;
331 345
 		
332 346
 		return "{$namespace}.{$entity}";
333 347
 	}
@@ -441,7 +455,7 @@ public function langArrayCodeForEntitySpec($entityFullName, $entitySpec, $locale
441 455
 			user_error("i18nTextCollector::langArrayCodeForEntitySpec(): Wrong entity format for $entityFullName with values" . var_export($entitySpec, true), E_USER_WARNING);
442 456
 			return false;
443 457
 		}
444  
-		
  458
+	
445 459
 		$value = $entitySpec[0];
446 460
 		$comment = (isset($entitySpec[1])) ? addcslashes($entitySpec[1],'\'') : null;
447 461
 
4  tasks/i18nTextCollectorTask.php
@@ -28,7 +28,9 @@ function init() {
28 28
 	 */	
29 29
 	public function run($request) {
30 30
 		increase_time_limit_to();
31  
-		$c = new i18nTextCollector();
  31
+		$c = new i18nTextCollector($request->getVar('locale'));
  32
+		$writer = $request->getVar('writer');
  33
+		if($writer) $c->setWriter(new $writer());
32 34
 		$restrictModules = ($request->getVar('module')) ? explode(',', $request->getVar('module')) : null;
33 35
 		return $c->run($restrictModules);
34 36
 	}

0 notes on commit 7ce1572

Please sign in to comment.
Something went wrong with that request. Please try again.