2008-10-16 22:42:41 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2008-10-16 22:42:41 +02:00
|
|
|
* @subpackage tasks
|
|
|
|
*/
|
|
|
|
class i18nTextCollectorTask extends BuildTask {
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2008-10-16 22:42:41 +02:00
|
|
|
protected $title = "i18n Textcollector Task";
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2008-10-16 22:42:41 +02:00
|
|
|
protected $description = "
|
|
|
|
Traverses through files in order to collect the 'entity master tables'
|
|
|
|
stored in each module.
|
2013-06-02 20:17:28 +02:00
|
|
|
|
|
|
|
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)
|
2008-10-16 22:42:41 +02:00
|
|
|
";
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function init() {
|
2008-10-16 22:42:41 +02:00
|
|
|
parent::init();
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2009-09-10 03:49:56 +02:00
|
|
|
$canAccess = (Director::isDev() || Director::is_cli() || Permission::check("ADMIN"));
|
2015-07-05 06:53:21 +02:00
|
|
|
if(!$canAccess) {
|
|
|
|
return Security::permissionFailure($this);
|
|
|
|
}
|
2008-10-16 22:42:41 +02:00
|
|
|
}
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2008-10-16 22:42:41 +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.
|
2016-01-06 00:34:58 +01:00
|
|
|
*
|
2008-10-16 22:42:41 +02:00
|
|
|
* @uses DataObject->collectI18nStatics()
|
2016-01-06 00:34:58 +01:00
|
|
|
*
|
2015-07-05 06:53:21 +02:00
|
|
|
* @param SS_HTTPRequest $request
|
2016-01-06 00:34:58 +01:00
|
|
|
*/
|
2008-10-16 22:42:41 +02:00
|
|
|
public function run($request) {
|
2009-06-28 04:36:46 +02:00
|
|
|
increase_time_limit_to();
|
2015-07-05 06:53:21 +02:00
|
|
|
$collector = i18nTextCollector::create($request->getVar('locale'));
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2015-07-05 06:53:21 +02:00
|
|
|
$merge = $this->getIsMerge($request);
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2015-07-05 06:53:21 +02:00
|
|
|
// Custom writer
|
|
|
|
$writerName = $request->getVar('writer');
|
|
|
|
if($writerName) {
|
|
|
|
$writer = Injector::inst()->get($writerName);
|
|
|
|
$collector->setWriter($writer);
|
|
|
|
}
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2015-07-05 06:53:21 +02:00
|
|
|
// Get restrictions
|
|
|
|
$restrictModules = ($request->getVar('module'))
|
|
|
|
? explode(',', $request->getVar('module'))
|
|
|
|
: null;
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2015-07-05 06:53:21 +02:00
|
|
|
$collector->run($restrictModules, $merge);
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2015-07-05 06:53:21 +02:00
|
|
|
Debug::message(__CLASS__ . " completed!", false);
|
|
|
|
}
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2015-07-05 06:53:21 +02:00
|
|
|
/**
|
|
|
|
* Check if we should merge
|
2016-01-06 00:34:58 +01:00
|
|
|
*
|
2015-07-05 06:53:21 +02:00
|
|
|
* @param SS_HTTPRequest $request
|
|
|
|
*/
|
|
|
|
protected function getIsMerge($request) {
|
|
|
|
$merge = $request->getVar('merge');
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2015-07-05 06:53:21 +02:00
|
|
|
// Default to false if not given
|
|
|
|
if(!isset($merge)) {
|
|
|
|
Deprecation::notice(
|
|
|
|
"4.0",
|
|
|
|
"merge will be enabled by default in 4.0. Please use merge=false if you do not want to merge."
|
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// merge=0 or merge=false will disable merge
|
|
|
|
return !in_array($merge, array('0', 'false'));
|
2008-10-16 22:42:41 +02:00
|
|
|
}
|
|
|
|
}
|