Compare commits

..
6 Commits
Author SHA1 Message Date
Fred Delrieu f92481561c Merge pull request #530 from caouecs/analysis-zGDkeO
Applied fixes from StyleCI
2016-03-22 22:53:38 +01:00
Fred Delrieu 75377e7ac3 Applied fixes from StyleCI 2016-03-22 17:53:23 -04:00
caouecs 46e0d0375c feature: en version 2016-03-22 22:52:26 +01:00
caouecs 6476967415 review: todo script 2016-03-22 22:52:18 +01:00
Fred Delrieu 20cb3ef9d7 Merge pull request #527 from ARCANEFORKS/patch-2
Updating TODO.md generator script
2016-03-22 22:33:58 +01:00
ARCANEDEV 0aba9b16c4 Updating TODO.md generator script 2016-03-20 16:46:22 +00:00
5 changed files with 130 additions and 36 deletions

No files matched your search

View File
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -91,7 +91,7 @@ return [
|
*/
'custom' => [
'custom' => [
'attribute-name' => [
'rule-name' => 'custom-message',
],
@@ -108,6 +108,6 @@ return [
|
*/
'attributes' => [],
'attributes' => [],
];
+128 -34
View File
@@ -1,50 +1,144 @@
<?php
/**
* Todo generator for Laravel-lang project.
*
* @author arcanedev-maroc
*/
class TodoGenerator
{
/**
* Base path.
*
* @var string
*/
protected $basePath;
// Get list of languages
$glob = scandir(__DIR__.'/..');
/**
* Excluded directories.
*
* @var array
*/
protected $excluded = [];
$languages = null;
/**
* Path of output file.
*
* @var string
*/
protected $output = null;
foreach ($glob as $file) {
if (is_dir(__DIR__.'/../'.$file) && (!in_array($file, ['.', '..', '.git', '.phpintel', 'en', 'script']))) {
$languages[] = $file;
/**
* Construct.
*
* @param string $basePath Base path.
* @param array $excluded Excluded directories.
*/
public function __construct($basePath, $excluded = [])
{
$this->basePath = realpath($basePath);
$this->excluded = $excluded;
$this->load();
}
}
// Get English version
$english = [
'auth' => include(__DIR__.'/../en/auth.php'),
'pagination' => include(__DIR__.'/../en/pagination.php'),
'passwords' => include(__DIR__.'/../en/passwords.php'),
'validation' => include(__DIR__.'/../en/validation.php'),
];
/**
* Returns object.
*
* @param string $basePath Base path.
* @param array $excluded Excluded directories.
*
* @return TodoGenerator
*/
public static function make($basePath, $excluded = [])
{
return new self($basePath, $excluded);
}
$text = "# Todo list\n\n";
/**
* Compare translations and generate file.
*/
private function load()
{
// Get English version
$english = $this->getTranslations(__DIR__.'/en');
$languages = $this->getLanguages();
// Return diff language by language
foreach ($languages as $language) {
$text .= "\n * ".$language.":\n";
$this->output = "# Todo list\n\n";
$this->compareTranslations($english, $languages);
}
$current = [
'auth' => include(__DIR__.'/../'.$language.'/auth.php'),
'pagination' => include(__DIR__.'/../'.$language.'/pagination.php'),
'passwords' => include(__DIR__.'/../'.$language.'/passwords.php'),
'validation' => include(__DIR__.'/../'.$language.'/validation.php'),
];
/**
* Returns array of translations by language.
*
* @param string $language Language code.
*
* @return array
*/
private function getTranslations($language)
{
return [
'auth' => include($language.'/auth.php'),
'pagination' => include($language.'/pagination.php'),
'passwords' => include($language.'/passwords.php'),
'validation' => include($language.'/validation.php'),
];
}
foreach ($english as $key => $values) {
foreach ($values as $key2 => $value2) {
if ($key2 != 'custom' && $key2 != 'attributes') {
if (!isset($current[$key][$key2])) {
$text .= ' * '.$key.' : '.$key2." : not present\n";
} elseif ($current[$key][$key2] == $english[$key][$key2]) {
$text .= ' * '.$key.' : '.$key2."\n";
/**
* Returns list of languages.
*
* @return array
*/
private function getLanguages()
{
$directories = glob($this->basePath.'/*', GLOB_ONLYDIR);
$languages = array_map(function ($dir) {
$name = basename($dir);
return in_array($name, $this->excluded) ? null : $name;
}, $directories);
return array_filter($languages);
}
/**
* Compare translations.
*
* @param array $default Language by default.
* @param array $languages Others languages.
*/
private function compareTranslations(array $default, array $languages)
{
// Return diff language by language
foreach ($languages as $language) {
$this->output .= "\n * ".$language.":\n";
$current = $this->getTranslations("{$this->basePath}/{$language}");
foreach ($default as $key => $values) {
foreach ($values as $key2 => $value2) {
if (in_array($key2, ['custom', 'attributes'])) {
continue;
}
if (!isset($current[$key][$key2])) {
$this->output .= ' * '.$key.' : '.$key2." : not present\n";
} elseif ($current[$key][$key2] == $default[$key][$key2]) {
$this->output .= ' * '.$key.' : '.$key2."\n";
}
}
}
}
}
/**
* Save todo list.
*
* @param string $path Path.
*/
public function save($path)
{
file_put_contents($path, $this->output);
}
}
$pathTodoMd = __DIR__.'/../todo.md';
file_put_contents($pathTodoMd, $text);
TodoGenerator::make(__DIR__.'/..', ['script'])->save(__DIR__.'/../todo.md');