48 lines
1.1 KiB
PHP
48 lines
1.1 KiB
PHP
<?php
|
|
function extract_strings($cont)
|
|
{
|
|
preg_match_all("/([a-z_]+): `([^`]*)`,/", $cont, $matches, PREG_SET_ORDER, 0);
|
|
$strings = [];
|
|
foreach ($matches as $match)
|
|
{
|
|
$strings[$match[1]] = $match[2];
|
|
}
|
|
return $strings;
|
|
}
|
|
|
|
$source = file_get_contents("client-webui/en.js");
|
|
$source_strings = extract_strings($source);
|
|
$source_lines = explode("\n", $source);
|
|
|
|
foreach (scandir("client-webui") as $file)
|
|
{
|
|
if (is_file("client-webui/$file") && $file != "en.js")
|
|
{
|
|
$cont = file_get_contents("client-webui/$file");
|
|
$target_strings = extract_strings($cont);
|
|
$fh = fopen("client-webui/$file", "wb");
|
|
fwrite($fh, explode("\n", $cont)[0]."\n");
|
|
foreach ($source_lines as $line)
|
|
{
|
|
if ($strings = extract_strings($line))
|
|
{
|
|
foreach ($strings as $key => $value)
|
|
{
|
|
if (array_key_exists($key, $target_strings))
|
|
{
|
|
fwrite($fh, "\t$key: `$target_strings[$key]`,\n");
|
|
}
|
|
else
|
|
{
|
|
fwrite($fh, "\t$key: `[UNTRANSLATED] $value`,\n");
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
fwrite($fh, $line."\n");
|
|
}
|
|
}
|
|
}
|
|
}
|