From db050a340c1b5afbd627ab99af45af75c213ac7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Wed, 4 Oct 2023 12:38:14 +0200 Subject: [PATCH] Fix missing strings using fallback --- parser/functions.php | 23 ++++++++++++++++++++--- parser/parse.sh | 11 ++++++++--- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/parser/functions.php b/parser/functions.php index b7bd2581..7a2eea61 100644 --- a/parser/functions.php +++ b/parser/functions.php @@ -149,16 +149,35 @@ function build_lang(&$language) { echo " Parent: $parent"; } + $langFile = false; + if (file_exists($lang.'.json')) { + // Load lang files just once. + $langFile = load_json($lang.'.json'); + } + $translations = []; // Add the translation to the array. foreach ($LANGINDEX as $file => $keys) { $lmsstring = get_translation_strings($langfoldername, $file); if (empty($lmsstring)) { + if ($lang == 'en') { + echo "\n*DEBUG* File $file not found in $lang\n"; + } continue; } foreach ($keys as $appkey => $lmskey) { if (!isset($lmsstring[$lmskey])) { + if ($appkey != 'core.parentlanguage') { + if ($langFile && isset($langFile[$appkey])) { + if ($lang == 'en') { + echo "\n*DEBUG* $appkey not found in $lang using fallback \n"; + } + $translations[$appkey] = $langFile[$appkey]; + } else if ($lang == 'en') { + echo "\n*DEBUG* $appkey not found in $lang!!! \n"; + } + } continue; } @@ -175,9 +194,7 @@ function build_lang(&$language) { } else { // @TODO: Remove that line when core.cannotconnect and core.login.invalidmoodleversion are completelly changed to use $a if (($appkey == 'core.cannotconnect' || $appkey == 'core.login.invalidmoodleversion') && strpos($text, '2.4')) { - if (DEBUG) { - echo "****** Found 2.4 \n"; - } + echo "\n*DEBUG* Found 2.4 in $lang $appkey \n"; $text = str_replace('2.4', '{{$a}}', $text); } $language->local++; diff --git a/parser/parse.sh b/parser/parse.sh index 32111c37..7b400076 100755 --- a/parser/parse.sh +++ b/parser/parse.sh @@ -73,6 +73,12 @@ function get_languages { done < $LANGPACKSFOLDER/languages.md5 } +force=0 + +if [ ! -d $LANGPACKSFOLDER ]; then + mkdir $LANGPACKSFOLDER +fi + if [ ! -z $GIT_TOKEN ] && [ ! -z $GITHUB_REPOSITORY ]; then # Set up Github Actions bot user # See https://github.community/t/github-actions-bot-email-address/17204/6 @@ -101,15 +107,14 @@ if [ ! -f 'langindex.json' ]; then download_file "$LANGINDEX_URL" - cp $LANGPACKSFOLDER langindex.json + cp $LANGPACKSFOLDER/langindex.json langindex.json fi langindexupdate=`date -r langindex.json +%s` currenttime=`date +%s` ellapsedtime=$((currenttime - langindexupdate)) -force=0 if [ $ellapsedtime -lt 3600 ]; then - echo 'Recently updated, force update all languages' + echo 'Index recently updated, force update all languages' force=1 fi