mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
3ee8f505b7
The main benefit of this is so that authors who make use of .editorconfig don't end up with whitespace changes in their PRs. Spaces vs. tabs has been left alone, although that could do with a tidy-up in SS4 after the switch to PSR-1/2. The command used was this: for match in '*.ss' '*.css' '*.scss' '*.html' '*.yml' '*.php' '*.js' '*.csv' '*.inc' '*.php5'; do find . -path ./thirdparty -not -prune -o -path ./admin/thirdparty -not -prune -o -type f -name "$match" -exec sed -E -i '' 's/[[:space:]]+$//' {} \+ find . -path ./thirdparty -not -prune -o -path ./admin/thirdparty -not -prune -o -type f -name "$match" | xargs perl -pi -e 's/ +$//' done
83 lines
2.1 KiB
PHP
83 lines
2.1 KiB
PHP
<?php
|
|
/**
|
|
* @package framework
|
|
* @subpackage tasks
|
|
*/
|
|
class i18nTextCollectorTask extends BuildTask {
|
|
|
|
protected $title = "i18n Textcollector Task";
|
|
|
|
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)
|
|
";
|
|
|
|
public function init() {
|
|
parent::init();
|
|
|
|
$canAccess = (Director::isDev() || Director::is_cli() || Permission::check("ADMIN"));
|
|
if(!$canAccess) {
|
|
return Security::permissionFailure($this);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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.
|
|
*
|
|
* @uses DataObject->collectI18nStatics()
|
|
*
|
|
* @param SS_HTTPRequest $request
|
|
*/
|
|
public function run($request) {
|
|
increase_time_limit_to();
|
|
$collector = i18nTextCollector::create($request->getVar('locale'));
|
|
|
|
$merge = $this->getIsMerge($request);
|
|
|
|
// Custom writer
|
|
$writerName = $request->getVar('writer');
|
|
if($writerName) {
|
|
$writer = Injector::inst()->get($writerName);
|
|
$collector->setWriter($writer);
|
|
}
|
|
|
|
// Get restrictions
|
|
$restrictModules = ($request->getVar('module'))
|
|
? explode(',', $request->getVar('module'))
|
|
: null;
|
|
|
|
$collector->run($restrictModules, $merge);
|
|
|
|
Debug::message(__CLASS__ . " completed!", false);
|
|
}
|
|
|
|
/**
|
|
* Check if we should merge
|
|
*
|
|
* @param SS_HTTPRequest $request
|
|
*/
|
|
protected function getIsMerge($request) {
|
|
$merge = $request->getVar('merge');
|
|
|
|
// 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'));
|
|
}
|
|
}
|