From ca854d5fc41708b38617c18ec17ebb523d4d158e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Fri, 17 Jun 2022 13:21:47 +0200 Subject: [PATCH] MOBILE-4081 lang: Use AUTO comments to generate local module translation --- scripts/lang_functions.php | 69 ++++++++++++-------------------------- 1 file changed, 21 insertions(+), 48 deletions(-) diff --git a/scripts/lang_functions.php b/scripts/lang_functions.php index 1de87482c..9fdc5c0b9 100644 --- a/scripts/lang_functions.php +++ b/scripts/lang_functions.php @@ -507,61 +507,34 @@ function override_component_lang_files($translations) { * @param [array] $translations English translations. */ function generate_local_module_file($appindex, $translations) { - echo "Generate local_moodlemobileapp.\n"; - $lmsstring = '. + echo 'Generate '.APPMODULENAME."\n"; -/** - * Version details. - * - * @package local - * @subpackage moodlemobileapp - * @copyright 2014 Juan Leyva - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -$string[\'appstoredescription\'] = \'NOTE: This official Moodle Mobile app will ONLY work with Moodle sites that have been set up to allow it. Please talk to your Moodle administrator if you have any problems connecting. - -If your Moodle site has been configured correctly, you can use this app to: - -- browse the content of your courses, even when offline -- receive instant notifications of messages and other events -- quickly find and contact other people in your courses -- upload images, audio, videos and other files from your mobile device -- view your course grades -- and more! - -Please see http://docs.moodle.org/en/Mobile_app for all the latest information. - -We’d really appreciate any good reviews about the functionality so far, and your suggestions on what else you want this app to do! - -The app requires the following permissions: -Record audio - For recording audio to upload to Moodle -Read and modify the contents of your SD card - Contents are downloaded to the SD Card so you can see them offline -Network access - To be able to connect with your Moodle site and check if you are connected or not to switch to offline mode -Run at startup - So you receive local notifications even when the app is running in the background -Prevent phone from sleeping - So you can receive push notifications anytime\';'."\n"; + $lmsstring = ""; foreach ($appindex as $appkey => $lmskey) { if (isset($translations[$appkey])) { $lmsstring .= '$string[\''.$appkey.'\'] = \''.str_replace("'", "\'", $translations[$appkey]).'\';'."\n"; } } - $lmsstring .= '$string[\'pluginname\'] = \'Moodle Mobile language strings\';'."\n"; + + if (empty($lmsstring)) { + echo "ERROR, translations not found, you probably didn't run gulp lang!\n"; + + return; + } $filepath = '../../moodle-'.APPMODULENAME.'/lang/en/'.APPMODULENAME.'.php'; + $filecontents = file_get_contents($filepath); - file_put_contents($filepath, $lmsstring."\n"); + $startcomment = "/* AUTO START */\n"; + $endcomment = '/* AUTO END */'; + + $start = strpos($filecontents, $startcomment); + $start = $start === false ? 0 : $start + strlen($startcomment); + + $end = strpos($filecontents, $endcomment, $start); + $end = $end === false ? strlen($filecontents) : $end; + + $filecontents = substr_replace($filecontents, $lmsstring, $start, $end - $start); + + file_put_contents($filepath, $filecontents); }