silverstripe-framework/Dev/Tasks/i18nTextCollectorTask.php

81 lines
2.1 KiB
PHP
Raw Normal View History

<?php
2016-06-23 01:37:22 +02:00
namespace SilverStripe\Dev\Tasks;
use SilverStripe\Control\SS_HTTPRequest;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\Debug;
use SilverStripe\Dev\BuildTask;
use SilverStripe\i18n\i18nTextCollector;
/**
* Collects i18n strings
*/
class i18nTextCollectorTask extends BuildTask {
2015-08-06 01:49:10 +02:00
private static $segment = 'i18nTextCollectorTask';
protected $title = "i18n Textcollector Task";
2015-08-06 01:49:10 +02:00
protected $description = "
Traverses through files in order to collect the 'entity master tables'
stored in each module.
Parameters:
- locale: Sets default locale
- writer: Custom writer class (defaults to i18nTextCollector_Writer_RailsYaml)
- module: One or more modules to limit collection (comma-separated)
- merge: Merge new strings with existing ones already defined in language files (default: FALSE)
";
2015-08-06 01:49:10 +02:00
/**
* This is the main method to build the master string tables with the original strings.
* It will search for existent modules that use the i18n feature, parse the _t() calls
* and write the resultant files in the lang folder of each module.
2015-08-06 01:49:10 +02:00
*
* @uses DataObject->collectI18nStatics()
2015-08-06 01:49:10 +02:00
*
* @param SS_HTTPRequest $request
2015-08-06 01:49:10 +02:00
*/
public function run($request) {
increase_time_limit_to();
$collector = i18nTextCollector::create($request->getVar('locale'));
2015-08-06 01:49:10 +02:00
$merge = $this->getIsMerge($request);
2015-08-06 01:49:10 +02:00
// Custom writer
$writerName = $request->getVar('writer');
if($writerName) {
$writer = Injector::inst()->get($writerName);
$collector->setWriter($writer);
}
2015-08-06 01:49:10 +02:00
// Get restrictions
$restrictModules = ($request->getVar('module'))
? explode(',', $request->getVar('module'))
: null;
2015-08-06 01:49:10 +02:00
$collector->run($restrictModules, $merge);
2015-08-06 01:49:10 +02:00
Debug::message(__CLASS__ . " completed!", false);
}
2015-08-06 01:49:10 +02:00
/**
* Check if we should merge
2015-08-06 01:49:10 +02:00
*
* @param SS_HTTPRequest $request
* @return bool
*/
protected function getIsMerge($request) {
$merge = $request->getVar('merge');
2015-08-06 01:49:10 +02:00
// Default to true if not given
if(!isset($merge)) {
return true;
}
// merge=0 or merge=false will disable merge
return !in_array($merge, array('0', 'false'));
}
}