Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
@chillu chillu authored
Showing with 22 additions and 6 deletions.
  1. +19 −5 i18n/i18nTextCollector.php
  2. +3 −1 tasks/i18nTextCollectorTask.php
View
24 i18n/i18nTextCollector.php
@@ -209,6 +209,11 @@ public function collectFromCode($content, $module) {
if($id == T_STRING && $text == '_t') {
// start definition
$inTransFn = true;
+ } elseif($inTransFn && $id == T_VARIABLE) {
+ // Dynamic definition from provideEntities - skip
+ $inTransFn = false;
+ $inConcat = false;
+ $currentEntity = array();
} elseif($inTransFn && $id == T_CONSTANT_ENCAPSED_STRING) {
// Fixed quoting escapes, and remove leading/trailing quotes
if(preg_match('/^\'/', $text)) {
@@ -221,8 +226,11 @@ public function collectFromCode($content, $module) {
$text = preg_replace('/"$/', '', $text);
}
- if($inConcat) $currentEntity[count($currentEntity)-1] .= $text;
- else $currentEntity[] = $text;
+ if($inConcat) {
+ $currentEntity[count($currentEntity)-1] .= $text;
+ } else {
+ $currentEntity[] = $text;
+ }
}
} elseif($inTransFn && $token == '.') {
$inConcat = true;
@@ -239,6 +247,12 @@ public function collectFromCode($content, $module) {
}
foreach($entities as $entity => $spec) {
+ // call without master language definition
+ if(!$spec) {
+ unset($entities[$entity]);
+ continue;
+ }
+
unset($entities[$entity]);
$entities[$this->normalizeEntity($entity, $module)] = $spec;
}
@@ -291,7 +305,7 @@ function collectFromEntityProviders($filePath) {
// Not all classes can be instanciated without mandatory arguments,
// so entity collection doesn't work for all SilverStripe classes currently
// Requires PHP 5.1+
- if(class_exists($class) && in_array('i18nEntityProvider', class_implements($class))) {
+ if(class_exists($class, false) && in_array('i18nEntityProvider', class_implements($class))) {
$reflectionClass = new ReflectionClass($class);
if($reflectionClass->isAbstract()) continue;
@@ -327,7 +341,7 @@ protected function normalizeEntity($fullName, $_namespace = null) {
// and skip the processing. This is mostly used for
// dynamically translating static properties, e.g. looping
// through $db, which are detected by {@link collectFromEntityProviders}.
- if(strpos('$', $entity) !== FALSE) return false;
+ if($entity && strpos('$', $entity) !== FALSE) return false;
return "{$namespace}.{$entity}";
}
@@ -441,7 +455,7 @@ public function langArrayCodeForEntitySpec($entityFullName, $entitySpec, $locale
user_error("i18nTextCollector::langArrayCodeForEntitySpec(): Wrong entity format for $entityFullName with values" . var_export($entitySpec, true), E_USER_WARNING);
return false;
}
-
+
$value = $entitySpec[0];
$comment = (isset($entitySpec[1])) ? addcslashes($entitySpec[1],'\'') : null;
View
4 tasks/i18nTextCollectorTask.php
@@ -28,7 +28,9 @@ function init() {
*/
public function run($request) {
increase_time_limit_to();
- $c = new i18nTextCollector();
+ $c = new i18nTextCollector($request->getVar('locale'));
+ $writer = $request->getVar('writer');
+ if($writer) $c->setWriter(new $writer());
$restrictModules = ($request->getVar('module')) ? explode(',', $request->getVar('module')) : null;
return $c->run($restrictModules);
}
Please sign in to comment.
Something went wrong with that request. Please try again.