From 5961b50cfcda78e87dfe0e66ef6290a1b286e045 Mon Sep 17 00:00:00 2001 From: Vasilis Daloukas Date: Thu, 31 Dec 2015 10:47:31 +0200 Subject: [PATCH] Fix translations check at translate.php --- CHANGES.md | 4 +++ lang/en/game.php | 4 --- translate.php | 92 ++++++++++++++++++------------------------------ version.php | 4 +-- 4 files changed, 40 insertions(+), 64 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 9963830..0c54558 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,7 @@ +Changes in version 2015-12-31 (4) (2015123104) +------------------------------------------------------------------ +- Fix translations check at translate.php + Changes in version 2015-12-31 (3) (2015123103) ------------------------------------------------------------------ - Fix at backup. diff --git a/lang/en/game.php b/lang/en/game.php index 6c5b7c7..bd2fb0d 100755 --- a/lang/en/game.php +++ b/lang/en/game.php @@ -17,9 +17,7 @@ // Translated by Vasilis Daloukas. // File bookquiz/importodt.php. -$string[ 'bookquiz_import_odt'] = 'Import from an OpenOffice file (odt)'; $string[ 'bookquiz_not_select_book'] = 'You have not select book'; -$string[ 'bookquiz_subchapter'] = 'Create subchapters'; // File bookquiz/play.php. $string[ 'bookquiz_empty'] = 'The book is empty'; @@ -238,13 +236,11 @@ $string[ 'cross_max_attempts'] = 'Maximum number of attempts'; $string[ 'cross_maxwords'] = 'Maximum number of words'; $string[ 'cross_minwords'] = 'Minimum number of words'; $string[ 'cross_options'] = 'Crossword options'; -$string[ 'cross_showprint'] = 'Show print button'; $string[ 'cryptex_maxtries'] = 'Max tries'; $string[ 'cryptex_options'] = 'Cryptex options'; $string[ 'disablesummarize'] = 'Disable summarize'; $string[ 'gameclose'] = 'Close the game'; $string[ 'gameopen'] = 'Open the game'; -$string[ 'gameopenclose'] = 'Open and close dates'; $string[ 'gameopenclose_help'] = 'Students can only start their attempt(s) after the open time and they must complete their attempts before the close time.'; $string[ 'grademethod'] = 'Grading method'; $string[ 'hangman_allowspaces'] = 'Allow spaces in words'; diff --git a/translate.php b/translate.php index fdea7a2..b2b0bf5 100755 --- a/translate.php +++ b/translate.php @@ -34,8 +34,7 @@ require( 'locallib.php'); id); +$context = game_get_context_course_instance( $COURSE->id); if (!has_capability('mod/game:viewreports', $context)) { error( get_string( 'only_teachers', 'game')); } @@ -55,10 +54,12 @@ $langname['lt'] = 'Lietuviškai (lt)'; $langname['nl'] = 'Nederlands (nl)'; $langname['no'] = 'Norsk - bokmål (no)'; $langname['pl'] = 'Polski (pl)'; +$langname['pt_br'] = 'Português - Brasil (pt_br)'; +$langname['ro'] = 'Română (ro)'; $langname['ru'] = 'Русский (ru)'; $langname['sq'] = 'Shqip (sq)'; +$langmane['sr_cr'] = 'Српски (sr_cr)'; $langname['uk'] = 'Українська (uk)'; -$langname['pt_br'] = 'Português - Brasil (pt_br)'; $langname['zh_cn'] = '简体中文 (zh_cn)'; ksort( $langname); $a = read_dir( $CFG->dirroot.'/mod/game', 'php'); @@ -82,6 +83,7 @@ $strings[ 'game:preview'] = '/db/access.php * game:preview'; $strings[ 'game:reviewmyattempts'] = '/db/access.php * game:reviewmyattempts'; $strings[ 'game:view'] = '/db/access.php * game:view'; $strings[ 'game:viewreports'] = '/db/access.php * game:viewreports'; +$strings[ 'game:addinstance'] = '/db/access.php * game:viewreports'; $strings[ 'pluginname'] = 'index.php * pluginname'; $strings[ 'pluginadministration'] = 'index.php * pluginadministration'; $strings[ 'convertfrom'] = 'locallib.php * convertfrom'; @@ -99,11 +101,12 @@ $strings[ 'helpmillionaire'] = 'index.php * helpmillionaire'; $en = readlangfile( 'en', $header); unset( $en[ 'convertfrom']); unset( $en[ 'convertto']); -$langs = computelangs(); +$langs = array_keys( $langname); $sum = array(); $destdir = game_export_createtempdir(); +$auntranslated = array(); foreach ($langs as $lang) { - if ($lang != 'en' and $lang != 'CVS' and strpos( $lang, '_utf8') == 0 and strpos( $lang, '_uft8') == 0) { + if ($lang != 'en') { computediff( $en, $lang, $strings, $langname, $sum, $destdir, $untranslated); $auntranslated[ $lang] = $untranslated; } @@ -119,7 +122,7 @@ foreach ($sum as $s) { } echo ""; -echo "
wwwroot}/file.php/1/export/$filenotranslation\">Words that is not translated yet in each language"; +echo "

Words that is not translated yet in each language are in $filezip"; // Find missing strings on en/game.php. $not = array(); @@ -182,7 +185,7 @@ $destdir = game_export_createtempdir(); sort( $strings); foreach ($langname as $lang => $name) { $stringslang = readlangfile( $lang, $header); - if (empty($stringlang)) { + if ($stringslang === false) { continue; } $ret = ''; @@ -228,7 +231,7 @@ foreach ($langname as $lang => $name) { $filesorted = 'game_lang_sorted.zip'; $filezip = game_create_zip( $destdir, $COURSE->id, $filesorted); remove_dir( $destdir); -echo "
wwwroot}/file.php/1/export/$filesorted\">Sorted translation files"; +echo "

The sorted translation files is $destdir/$filesorted"; asort( $en); $sprev = ''; @@ -246,12 +249,22 @@ if ($ret != '') { echo ''.$ret.'
Word1Word2Translation
'; } -function readlangfile( $lang, &$header) { +function getlangfile( $lang) { global $CFG; - $file = $CFG->dirroot.'/mod/game/lang/'.$lang.'/game.php'; + if ($lang == 'en') { + return $CFG->dirroot.'/mod/game/lang/'.$lang.'/game.php'; + } else { + return $CFG->dataroot.'/lang/'.$lang.'/game.php'; + } +} + +function readlangfile( $lang, &$header) { + + $file = getlangfile( $lang); + if (!is_file($file)) { - return null; + return false; } $a = array(); @@ -272,10 +285,6 @@ function readlangfile( $lang, &$header) { } } - if ($lang != 'en') { - readlangfile_repairmoodle19( $lang, $a); - } - return $a; } @@ -414,34 +423,23 @@ function read_dir($dir, $ext) { return $ret; } -function computelangs() { - global $CFG; - - $dir = $CFG->dirroot.'/mod/game/lang'; - $ret = array(); - $d = dir( $dir); - while (false !== ($entry = $d->read())) { - if ($entry != '.' and $entry != '..') { - if (is_dir($dir.'/'.$entry)) { - $ret[] = $entry; - } - } - } - - return $ret; -} - function computediff( $en, $lang, $strings, $langname, &$sum, $outdir, &$untranslated) { global $CFG; $untranslated = ''; $counten = count($en); $trans = readlangfile( $lang, $header); - foreach ($trans as $s => $key) { - unset( $en[ $s]); + if ($trans != false) { + foreach ($trans as $s => $key) { + unset( $en[ $s]); + } } - $file = $CFG->dirroot.'/mod/game/lang/'.$lang.'/game.php'; - $lines = file( $file); + $file = getlangfile( $lang); + if (file_exists( $file)) { + $lines = file( $file); + } else { + $lines = array(); + } $count = 0; $s = ''; foreach ($lines as $line) { @@ -488,25 +486,3 @@ function computediff( $en, $lang, $strings, $langname, &$sum, $outdir, &$untrans $file = $outdir.'/'.$lang.'.php'; file_put_contents( $file, $s); } - -// Copies the translation from Moodle 19. -function readlangfile_repairmoodle19( $lang, &$stringslang) { - global $moodle19dir; - - if ($moodle19dir == '') { - return; - } - - $file = $moodle19dir.'/mod/game/lang/'.$lang.'_utf8/game.php'; - - $a = array(); - - $lines = file( $file); - foreach ($lines as $line) { - if (splitlangdefinition($line, $name, $trans)) { - if (!array_key_exists( $name, $stringslang)) { - $stringslang[ $name] = $trans; - } - } - } -} diff --git a/version.php b/version.php index 19f1a5a..3afe678 100755 --- a/version.php +++ b/version.php @@ -36,10 +36,10 @@ if (!isset( $plugin)) { } $plugin->component = 'mod_game'; // Full name of the plugin (used for diagnostics). -$plugin->version = 2015123103; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2015123104; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2010112400; // Requires Moodle 2.0. $plugin->cron = 0; // Period for cron to check this module (secs). -$plugin->release = '2015-12-31 (3)'; +$plugin->release = '2015-12-31 (4)'; if ($useplugin != 2) { $module = $plugin;