Skip to content

Commit

Permalink
MINOR Stability fixes on new tokenizer implementation of i18nTextColl…
Browse files Browse the repository at this point in the history
…ector, allowing to specify writer and locale arguments on task execution
  • Loading branch information
chillu committed Apr 16, 2012
1 parent df08c2f commit 7ce1572
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
24 changes: 19 additions & 5 deletions i18n/i18nTextCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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}";
}
Expand Down Expand Up @@ -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;

Expand Down
4 changes: 3 additions & 1 deletion tasks/i18nTextCollectorTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 7ce1572

Please sign in to comment.