Skip to content

Commit 35fcaaa

Browse files
authored
Merge pull request #709 from kenjis/update-lang-ja
lang: update ja
2 parents b5ada46 + 046c411 commit 35fcaaa

File tree

2 files changed

+185
-78
lines changed

2 files changed

+185
-78
lines changed

bin/update-en-comments

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#!/usr/bin/env php
2+
<?php declare(strict_types=1);
3+
4+
/**
5+
* This file is part of CodeIgniter 4 framework.
6+
*
7+
* (c) CodeIgniter Foundation <[email protected]>
8+
*
9+
* For the full copyright and license information, please view
10+
* the LICENSE file that was distributed with this source code.
11+
*/
12+
13+
require __DIR__ . '/../vendor/codeigniter4/framework/system/Test/bootstrap.php';
14+
15+
use CodeIgniter\CLI\CLI;
16+
17+
helper('filesystem');
18+
19+
if ($argc !== 2) {
20+
CLI::error('Please specify a locale.');
21+
22+
exit(1);
23+
}
24+
25+
$locale = $argv[1];
26+
27+
$langDir = realpath(__DIR__ . '/../src/Language/' . $locale);
28+
29+
if (! is_dir($langDir)) {
30+
CLI::error('No such directory: "' . $langDir . '"');
31+
32+
exit(1);
33+
}
34+
35+
$enDir = realpath(__DIR__ . '/../src/Language/en');
36+
37+
if (! is_dir($enDir)) {
38+
CLI::error('No "Language/en" directory. Please run "composer update".');
39+
40+
exit(1);
41+
}
42+
43+
$files = get_filenames(
44+
$langDir,
45+
true,
46+
false,
47+
false
48+
);
49+
50+
$enFiles = get_filenames(
51+
$enDir,
52+
true,
53+
false,
54+
false
55+
);
56+
57+
foreach ($enFiles as $enFile) {
58+
$temp = $langDir . '/' . substr($enFile, strlen($enDir) + 1);
59+
$langFile = realpath($temp) ?: $temp;
60+
61+
if (! is_file($langFile)) {
62+
CLI::error('No such file: "' . $langFile . '"');
63+
64+
continue;
65+
}
66+
67+
$enFileLines = file($enFile);
68+
69+
$items = [];
70+
71+
$pattern = '/(.*)\'([a-zA-Z0-9_]+?)\'(\s*=>\s*)([\'"].+[\'"]),/u';
72+
73+
foreach ($enFileLines as $line) {
74+
if (preg_match($pattern, $line, $matches)) {
75+
$items[] = [$matches[2] => $matches[4]];
76+
}
77+
}
78+
79+
$langFileLines = file($langFile);
80+
81+
$newLangFile = '';
82+
83+
$itemNo = 0;
84+
85+
foreach ($langFileLines as $line) {
86+
// Remove en value comment.
87+
if (preg_match('!(.*,)(\s*//.*)$!u', $line, $matches)) {
88+
$line = $matches[1] . "\n";
89+
}
90+
91+
if (preg_match($pattern, $line, $matches) === 0) {
92+
$newLangFile .= $line;
93+
} else {
94+
$indent = $matches[1];
95+
$key = $matches[2];
96+
$arrow = $matches[3];
97+
$value = $matches[4];
98+
99+
$newLangFile .= $indent . "'" . $key . "'" . $arrow . $value
100+
. ', // ' . $items[$itemNo][array_key_first($items[$itemNo])] . "\n";
101+
$itemNo++;
102+
}
103+
}
104+
105+
file_put_contents($langFile, $newLangFile);
106+
CLI::write('Updated: ' . $langFile);
107+
}

0 commit comments

Comments
 (0)