Skip to content

lang: [ja] update translations #709

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <[email protected]>
*
* 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