Skip to content

Commit

Permalink
API partial implementation of translations task
Browse files Browse the repository at this point in the history
  • Loading branch information
Damian Mooyman committed Aug 19, 2015
1 parent ba388a1 commit 120fd5e
Show file tree
Hide file tree
Showing 8 changed files with 346 additions and 13 deletions.
10 changes: 9 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ it will install to the path specified by `./release-<version>` in the current di

`release` actually has several sub-commands which can be run independently. These are as below:

* `release:changelog` Just generates the changelog and commits this to source control.
* `release:create` creates the project folder
* `release:changelog` Just generates the changelog and commits this to source control.
* `release:translate` Updates translations and commits this to source control

## Module-level commands

Outside of doing core releases, you can use this for specific modules

* `module:translate <modules>` Updates translations for modules and commits this to source control. If you
don't specify a list of modules then all modules will be translated. Specify 'installer' for root module.

2 changes: 2 additions & 0 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ protected function getDefaultCommands()
$commands[] = new Commands\Release\Create();
$commands[] = new Commands\Release\Changelog();
$commands[] = new Commands\Release\Release();

$commands[] = new Commands\Module\Translate();

return $commands;
}
Expand Down
47 changes: 47 additions & 0 deletions src/Commands/Module/Module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace SilverStripe\Cow\Commands\Module;

use SilverStripe\Cow\Commands\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;

/**
* Abstract base command for all module commands
*
* @author dmooyman
*/
abstract class Module extends Command {

protected function configure() {
parent::configure();
$this->addArgument(
'modules',
InputArgument::IS_ARRAY | InputArgument::OPTIONAL,
'Optional list of modules to filter (separate by space)'
);
$this->addOption('directory', 'd', InputOption::VALUE_REQUIRED, 'Module directory');
}

/**
* Get the directory the project is, or will be in
*
* @return string
*/
protected function getInputDirectory() {
$directory = $this->input->getOption('directory');
if(!$directory) {
$directory = getcwd();
}
return $directory;
}

/**
* Gets the list of module names to filter by (or empty if all modules)
*
* @return array
*/
protected function getInputModules() {
return $this->input->getArgument('modules') ?: array();
}
}
30 changes: 30 additions & 0 deletions src/Commands/Module/Translate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace SilverStripe\Cow\Commands\Module;

use SilverStripe\Cow\Steps\Release\UpdateTranslations;

/**
* Description of Create
*
* @author dmooyman
*/
class Translate extends Module {

/**
* @var string
*/
protected $name = 'module:translate';

protected $description = 'Translate your modules';

protected function fire() {
$directory = $this->getInputDirectory();
$modules = $this->getInputModules();

$translate = new UpdateTranslations($this, $directory, $modules);
$translate->run($this->input, $this->output);
//$step->run($this->input, $this->output);
}

}
27 changes: 27 additions & 0 deletions src/Model/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,40 @@ public function __construct($directory, $name, Project $parent = null) {
public function getDirectory() {
return $this->directory;
}

/**
* Gets the module lang dir
*
* @return string
*/
public function getLangDirectory() {
return $this->directory . '/lang';
}

/**
* Base name only of location of code
*
* @return string
*/
public function getCodeDirectory() {
return $this->getName();
}

/**
* A project is valid if it has a root composer.json
*/
public function isValid() {
return $this->directory && realpath($this->directory . '/composer.json');
}

/**
* Determine if this project has a .tx configured
*
* @return bool
*/
public function isTranslatable() {
return $this->directory && realpath($this->directory . '/.tx/config');
}

public function getName() {
return $this->name;
Expand Down
18 changes: 17 additions & 1 deletion src/Model/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace SilverStripe\Cow\Model;

use InvalidArgumentException;

/**
* Represents information about a project in a given directory
*
Expand All @@ -11,10 +13,16 @@ class Project extends Module {

public function __construct($directory) {
parent::__construct($directory, 'installer');

if(!realpath($this->directory . '/mysite')) {
throw new InvalidArgumentException("No installer found in \"{$this->directory}\"");
}
}

/**
* Gets the list of modules in this installer
*
* @return Module[]
*/
public function getModules() {
// Include self as head module
Expand Down Expand Up @@ -44,7 +52,7 @@ public function getModule($name) {
}

/**
* Check if the given path contains a module
* Check if the given path contains a non-installer module
*
* @return bool
*/
Expand All @@ -59,4 +67,12 @@ protected function isModulePath($path) {
$ignore = array('mysite', 'assets', 'vendor');
return !in_array($name, $ignore);
}

public function getLangDirectory() {
return $this->directory . '/mysite/lang';
}

public function getCodeDirectory() {
return 'mysite';
}
}
Loading

0 comments on commit 120fd5e

Please sign in to comment.