Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f92481561c | ||
|
|
75377e7ac3 | ||
|
|
46e0d0375c | ||
|
|
6476967415 | ||
|
|
20cb3ef9d7 | ||
|
|
0aba9b16c4 |
No files matched your search
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
@@ -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');
|
||||
Reference in new issue
Block a user