From 9e9b4bcbbe9b5cdea8e25ffdb056f5563a0e4d4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Thu, 12 Dec 2019 13:20:03 +0100 Subject: [PATCH] MOBILE-3213 strings: Have a better CLI interface --- scripts/lang_functions.php | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/scripts/lang_functions.php b/scripts/lang_functions.php index 0fa57b1f4..7765841ca 100644 --- a/scripts/lang_functions.php +++ b/scripts/lang_functions.php @@ -58,6 +58,7 @@ function build_languages($languages, $keys, $added_langs = []) { } function get_langindex_keys() { + $local = 0; // Process the index file, just once. $keys = file_get_contents('langindex.json'); $keys = (array) json_decode($keys); @@ -67,6 +68,7 @@ function get_langindex_keys() { if ($value == 'local_moodlemobileapp') { $map->file = $value; $map->string = $key; + $local++; } else { $exp = explode('/', $value, 2); $map->file = $exp[0]; @@ -87,7 +89,7 @@ function get_langindex_keys() { } $total = count($keys); - echo "Total strings to translate $total\n"; + echo "Total strings to translate $total ($local local)\n"; return $keys; } @@ -248,7 +250,11 @@ function build_lang($lang, $keys) { $success = count($translations); $percentage = floor($success/$total * 100); - echo "\t\t$success of $total -> $percentage% ($local local)\n"; + $bar = progressbar($percentage); + if (strlen($lang) <= 2 && !$parent) { + echo "\t"; + } + echo "\t\t$success of $total -> $percentage% $bar ($local local)\n"; if ($lang == 'en') { generate_local_moodlemobileapp($keys, $translations); @@ -258,6 +264,11 @@ function build_lang($lang, $keys) { return true; } +function progressbar($percentage) { + $done = $percentage/10; + return "\t".str_repeat('=', $done) . str_repeat('-', 10-$done); +} + function detect_lang($lang, $keys) { $langfoldername = get_langfolder($lang); if (!$langfoldername) { @@ -275,12 +286,14 @@ function detect_lang($lang, $keys) { return false; } - echo "Checking $lang"; + $title = $lang; if ($parent != "" && $parent != $lang) { - echo " ($parent)"; + $title .= " ($parent)"; } $langname = $string['thislanguage']; - echo " ".$langname." -D"; + $title .= " ".$langname." -D"; + + // Add the translation to the array. foreach ($keys as $key => $value) { @@ -304,7 +317,10 @@ function detect_lang($lang, $keys) { } $percentage = floor($success/$total * 100); - echo "\t\t$success of $total -> $percentage% ($local local)"; + $bar = progressbar($percentage); + + echo "Checking ".$title.str_repeat("\t", 7 - floor(mb_strlen($title, 'UTF-8')/8)); + echo "\t$success of $total -> $percentage% $bar ($local local)"; if (($percentage > 75 && $local > 50) || ($percentage > 50 && $local > 75)) { echo " \t DETECTED\n"; return true;