-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #709 from kenjis/update-lang-ja
lang: update ja
- Loading branch information
Showing
2 changed files
with
185 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
#!/usr/bin/env php | ||
<?php declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of CodeIgniter 4 framework. | ||
* | ||
* (c) CodeIgniter Foundation <admin@codeigniter.com> | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
require __DIR__ . '/../vendor/codeigniter4/framework/system/Test/bootstrap.php'; | ||
|
||
use CodeIgniter\CLI\CLI; | ||
|
||
helper('filesystem'); | ||
|
||
if ($argc !== 2) { | ||
CLI::error('Please specify a locale.'); | ||
|
||
exit(1); | ||
} | ||
|
||
$locale = $argv[1]; | ||
|
||
$langDir = realpath(__DIR__ . '/../src/Language/' . $locale); | ||
|
||
if (! is_dir($langDir)) { | ||
CLI::error('No such directory: "' . $langDir . '"'); | ||
|
||
exit(1); | ||
} | ||
|
||
$enDir = realpath(__DIR__ . '/../src/Language/en'); | ||
|
||
if (! is_dir($enDir)) { | ||
CLI::error('No "Language/en" directory. Please run "composer update".'); | ||
|
||
exit(1); | ||
} | ||
|
||
$files = get_filenames( | ||
$langDir, | ||
true, | ||
false, | ||
false | ||
); | ||
|
||
$enFiles = get_filenames( | ||
$enDir, | ||
true, | ||
false, | ||
false | ||
); | ||
|
||
foreach ($enFiles as $enFile) { | ||
$temp = $langDir . '/' . substr($enFile, strlen($enDir) + 1); | ||
$langFile = realpath($temp) ?: $temp; | ||
|
||
if (! is_file($langFile)) { | ||
CLI::error('No such file: "' . $langFile . '"'); | ||
|
||
continue; | ||
} | ||
|
||
$enFileLines = file($enFile); | ||
|
||
$items = []; | ||
|
||
$pattern = '/(.*)\'([a-zA-Z0-9_]+?)\'(\s*=>\s*)([\'"].+[\'"]),/u'; | ||
|
||
foreach ($enFileLines as $line) { | ||
if (preg_match($pattern, $line, $matches)) { | ||
$items[] = [$matches[2] => $matches[4]]; | ||
} | ||
} | ||
|
||
$langFileLines = file($langFile); | ||
|
||
$newLangFile = ''; | ||
|
||
$itemNo = 0; | ||
|
||
foreach ($langFileLines as $line) { | ||
// Remove en value comment. | ||
if (preg_match('!(.*,)(\s*//.*)$!u', $line, $matches)) { | ||
$line = $matches[1] . "\n"; | ||
} | ||
|
||
if (preg_match($pattern, $line, $matches) === 0) { | ||
$newLangFile .= $line; | ||
} else { | ||
$indent = $matches[1]; | ||
$key = $matches[2]; | ||
$arrow = $matches[3]; | ||
$value = $matches[4]; | ||
|
||
$newLangFile .= $indent . "'" . $key . "'" . $arrow . $value | ||
. ', // ' . $items[$itemNo][array_key_first($items[$itemNo])] . "\n"; | ||
$itemNo++; | ||
} | ||
} | ||
|
||
file_put_contents($langFile, $newLangFile); | ||
CLI::write('Updated: ' . $langFile); | ||
} |
Oops, something went wrong.