MOBILE-4081 lang: Use AUTO comments to generate local module translation

main
Pau Ferrer Ocaña 2022-06-17 13:21:47 +02:00
parent ce2b3d868d
commit ca854d5fc4
1 changed files with 21 additions and 48 deletions

View File

@ -507,61 +507,34 @@ function override_component_lang_files($translations) {
* @param [array] $translations English translations. * @param [array] $translations English translations.
*/ */
function generate_local_module_file($appindex, $translations) { function generate_local_module_file($appindex, $translations) {
echo "Generate local_moodlemobileapp.\n"; echo 'Generate '.APPMODULENAME."\n";
$lmsstring = '<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/** $lmsstring = "";
* Version details.
*
* @package local
* @subpackage moodlemobileapp
* @copyright 2014 Juan Leyva <juanleyvadelgado@gmail.com>
* @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.
Wed 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";
foreach ($appindex as $appkey => $lmskey) { foreach ($appindex as $appkey => $lmskey) {
if (isset($translations[$appkey])) { if (isset($translations[$appkey])) {
$lmsstring .= '$string[\''.$appkey.'\'] = \''.str_replace("'", "\'", $translations[$appkey]).'\';'."\n"; $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'; $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);
} }