Skip to content

Commit

Permalink
Merge pull request #709 from kenjis/update-lang-ja
Browse files Browse the repository at this point in the history
lang: update ja
  • Loading branch information
kenjis authored Apr 24, 2023
2 parents b5ada46 + 046c411 commit 35fcaaa
Show file tree
Hide file tree
Showing 2 changed files with 185 additions and 78 deletions.
107 changes: 107 additions & 0 deletions bin/update-en-comments
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);
}
Loading

0 comments on commit 35fcaaa

Please sign in to comment.