Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0aba9b1

Browse files
Updating TODO.md generator script
1 parent 667d35d commit 0aba9b1

File tree

5 files changed

+89
-38
lines changed

5 files changed

+89
-38
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

script/todo.php

Lines changed: 89 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,101 @@
11
<?php
22

3-
// Get list of languages
4-
$glob = scandir(__DIR__.'/..');
3+
class TodoGenerator
4+
{
5+
/* ------------------------------------------------------------------------------------------------
6+
| Properties
7+
| ------------------------------------------------------------------------------------------------
8+
*/
9+
/** @var string */
10+
protected $basePath;
511

6-
$languages = null;
12+
/** @var array */
13+
protected $excluded = [];
714

8-
foreach ($glob as $file) {
9-
if (is_dir(__DIR__.'/../'.$file) && (!in_array($file, ['.', '..', '.git', '.phpintel', 'en', 'script']))) {
10-
$languages[] = $file;
15+
/** @var string */
16+
protected $output = '';
17+
18+
/* ------------------------------------------------------------------------------------------------
19+
| Constructor
20+
| ------------------------------------------------------------------------------------------------
21+
*/
22+
public function __construct($basePath, $excluded = [])
23+
{
24+
$this->basePath = realpath($basePath);
25+
$this->excluded = $excluded;
26+
$this->output = '';
27+
$this->load();
1128
}
12-
}
1329

14-
// Get English version
15-
$english = [
16-
'auth' => include(__DIR__.'/../en/auth.php'),
17-
'pagination' => include(__DIR__.'/../en/pagination.php'),
18-
'passwords' => include(__DIR__.'/../en/passwords.php'),
19-
'validation' => include(__DIR__.'/../en/validation.php'),
20-
];
21-
22-
$text = "# Todo list\n\n";
23-
24-
// Return diff language by language
25-
foreach ($languages as $language) {
26-
$text .= "\n * ".$language.":\n";
27-
28-
$current = [
29-
'auth' => include(__DIR__.'/../'.$language.'/auth.php'),
30-
'pagination' => include(__DIR__.'/../'.$language.'/pagination.php'),
31-
'passwords' => include(__DIR__.'/../'.$language.'/passwords.php'),
32-
'validation' => include(__DIR__.'/../'.$language.'/validation.php'),
33-
];
34-
35-
foreach ($english as $key => $values) {
36-
foreach ($values as $key2 => $value2) {
37-
if ($key2 != 'custom' && $key2 != 'attributes') {
38-
if (!isset($current[$key][$key2])) {
39-
$text .= ' * '.$key.' : '.$key2." : not present\n";
40-
} elseif ($current[$key][$key2] == $english[$key][$key2]) {
41-
$text .= ' * '.$key.' : '.$key2."\n";
30+
public static function make($basePath, $excluded = [])
31+
{
32+
return new self($basePath, $excluded);
33+
}
34+
35+
/* ------------------------------------------------------------------------------------------------
36+
| Main Functions
37+
| ------------------------------------------------------------------------------------------------
38+
*/
39+
private function load()
40+
{
41+
// Get English version
42+
$english = $this->getTranslations(__DIR__.'/en');
43+
$languages = $this->getLanguages();
44+
45+
$this->output = "# Todo list\n\n";
46+
$this->compareTranslations($english, $languages);
47+
}
48+
49+
private function getTranslations($dir)
50+
{
51+
return [
52+
'auth' => include("$dir/auth.php"),
53+
'pagination' => include("$dir/pagination.php"),
54+
'passwords' => include("$dir/passwords.php"),
55+
'validation' => include("$dir/validation.php"),
56+
];
57+
}
58+
59+
private function getLanguages()
60+
{
61+
$directories = glob("{$this->basePath}/*", GLOB_ONLYDIR);
62+
63+
$languages = array_map(function ($dir) {
64+
$name = basename($dir);
65+
66+
return in_array($name, $this->excluded) ? null : $name;
67+
}, $directories);
68+
69+
return array_filter($languages);
70+
}
71+
72+
private function compareTranslations($default, $languages)
73+
{
74+
// Return diff language by language
75+
foreach ($languages as $language) {
76+
$this->output .= "\n * ".$language.":\n";
77+
$current = $this->getTranslations("{$this->basePath}/{$language}");
78+
79+
foreach ($default as $key => $values) {
80+
foreach ($values as $key2 => $value2) {
81+
if (in_array($key2, ['custom', 'attributes'])) {
82+
continue;
83+
}
84+
85+
if (!isset($current[$key][$key2])) {
86+
$this->output .= ' * '.$key.' : '.$key2." : not present\n";
87+
} elseif ($current[$key][$key2] == $default[$key][$key2]) {
88+
$this->output .= ' * '.$key.' : '.$key2."\n";
89+
}
4290
}
4391
}
4492
}
4593
}
46-
}
4794

48-
$pathTodoMd = __DIR__.'/../todo.md';
95+
public function save($path)
96+
{
97+
file_put_contents(realpath($path), $this->output);
98+
}
99+
}
49100

50-
file_put_contents($pathTodoMd, $text);
101+
TodoGenerator::make(__DIR__.'/..', ['script'])->save(__DIR__.'/../todo.md');

0 commit comments

Comments
 (0)