Update CreateLanguage.php

Can now analyze existing languages and specify status
This commit is contained in:
EV-soft 2021-06-13 13:55:13 +02:00 committed by GitHub
parent b1876aa719
commit d0f6eafd1f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,13 +1,34 @@
<?php ## EV-soft - 2021-06-13
## to: Create / Update / Maintain list of translate strings by scanning the source-file(s)
## Place this file in the same folder as tinyfilemanager.php and read the file in your browser
if (!isset($compareCode))
$compareCode= 'ru'; ## Adjust this code to the default language you want to analyze (cant use 'en')
$d = dir("./");
$total= 0; $buff= array(); $arrStrings= array(); $longest= 0;
$total= 0; $buff= array(); $arrStrings= array(); $longest= 0; $miss= 0;
echo '<meta charset="utf-8">';
echo "<br><big>".'Projektscann: '."</big><br>";
echo "<br>".'Scanning for prefix: "lng(\'" '." in .php/.htm files in current folder,";
echo "<br>and create a complete list of language texts that you can translate";
echo '<p style="font-family:courier; font-size:18; ">';
$arrTrans= []; $arrCode= [];
$content = file_get_contents('translation.json');
if($content !== FALSE) {
$lng = json_decode($content, TRUE);
foreach ($lng["language"] as $key => $value) {
$code = $value["code"];
$lang_list[$code] = $value["name"];
$arrTrans[$code] = $value["translation"];
$arrCode[]= $code;
}
}
echo '<form action="#" method="post">
<label for="lngCode">Select a code:</label>
<select id="lngCode" name="lngCode">';
foreach ($arrCode as $code) echo '<option value="'.$code.'" '.($code==$compareCode ? 'selected ' : '').' >'.$code.'</option>';
echo '</select>
<input type="submit" name="submit" value="Analyze Selected" />
</form>';
if (isset($_POST['submit'])) $compareCode = $_POST['lngCode'];
while (false !== ($entry = $d->read())) {
$dir= $entry.'/';
if (is_dir($entry) ) {
@ -35,7 +56,7 @@
}
}
$count= substr('000'.$count,-4);
if ($count>0) $buff[] = 'Total: '.$count.' found : "<font color=red>'.$search.'</font>" i <i>'.$dir.'</i><b>'.$source.'</b><br>';
if ($count>0) $buff[] = 'Total: '.$count.' found : "<font color=red>'.$search.'</font>" in file <i>'.$dir.'</i><b>'.$source.'</b><br>';
}
}
}
@ -47,7 +68,7 @@
$arrStrings= array_unique($arrStrings, SORT_REGULAR);
// sort($arrStrings, SORT_NATURAL | SORT_FLAG_CASE);
sort($arrStrings);
echo '<br>Sorted list without duplicates:';
echo '<br>Sorted list without duplicates for code: '.$compareCode;
echo '<p style="font-family:courier; font-size:11; ">';
echo '<pre>
{
@ -55,16 +76,20 @@ echo '<pre>
"version": "2.4.6",
"language": [
{
"name": "Fill: English name for the language",
"code": "Fill: language ISO code",
"name": "<font color=red>Fill: English name for the language</font>",
"code": "<font color=red>Fill: language ISO code</font>",
"translation": {';
foreach ($arrStrings as $string)
{if (strlen($string[0])>3)
echo '<br>'.str_repeat("&nbsp;",8).$string[0].':'.
str_repeat("&nbsp;",$longest+3-strlen(utf8_decode(substr($string[0],0)))).
'"Missing_native_translated_string",';
};
echo ' <- REMOVE THIS LAST COMMA !
foreach ($arrStrings as $string) {
if (strlen($string[0])>3) {
echo '<br>'.str_repeat("&nbsp;",8).$string[0].':'.
str_repeat("&nbsp;",$longest+3-strlen(utf8_decode(substr($string[0],0))));
if (array_key_exists(trim($string[0],'"'),$arrTrans[$compareCode])) {
echo '"'.$arrTrans[$compareCode][trim($string[0],'"')].'",';
$miss++;
}
else echo '"<font color=red>Missing_native_translated_string</font>",';
}};
echo ' <font color=red><- REMOVE THIS LAST COMMA !</font>
}
},
{... Insert all other languages here ...}
@ -74,5 +99,6 @@ echo ' <- REMOVE THIS LAST COMMA !
echo '</p>';
echo '<br>Total: '.count($arrStrings).' strings i the sorted list. Longest string is on '.$longest.' chars.';
echo '<br>You can copy - paste this list to your editor';
echo '<br>Remember to escape the char: " with a slash like this: \" if it occurs on translated text !';
echo '<br><font color=red>Remember to escape the char: " </font>with a slash like this: \" if it occurs on translated text !';
echo '<br>Status of the analyzed language is '.round($miss / count($arrStrings) * 100).' % translated.';
?>