public static function kanjiToRomaji($input, &$returnCode = '')
{
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
return $input;
}
$japanese = "/([\\x{3000}-\\x{303f}\\x{3040}-\\x{309f}\\x{30a0}-\\x{30ff}\\x{ff00}-\\x{ff9f}\\x{4e00}-\\x{9faf}\\x{3400}-\\x{4dbf}])+/iu";
preg_match_all($japanese, $input, $matches);
if (empty($matches[0]) || !is_array($matches[0])) {
return $input;
}
$placeholders = ['in' => $matches[0], 'out' => []];
$uniq = uniqid();
$kakasi = 'kakasi -i euc -w | kakasi -i euc -Ha -Ka -Ja -Ea -ka';
$process = new Process($kakasi);
$words = implode($uniq, $placeholders['in']);
$convertedWords = mb_convert_encoding($words, 'eucjp', 'utf-8');
$process->setInput($convertedWords);
$process->run();
if (!$process->isSuccessful()) {
return IRCHelper::colorText('ERROR', IRCHelper::COLOR_RED) . ': can\'t run kakasi';
}
$romaji = $process->getOutput();
$placeholders['out'] = explode($uniq, $romaji);
$input = str_replace($placeholders['in'], $placeholders['out'], $input);
return $input;
}