Skip to content

Commit 9b6d72e

Browse files
authored
Merge pull request #1451 from maths/langtidy
Langtidy
2 parents 974f8c7 + 8f520d3 commit 9b6d72e

8 files changed

Lines changed: 171 additions & 56 deletions

File tree

cli/langstrings.php

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
<?php
2+
// This file is part of Stack - http://stack.maths.ed.ac.uk/
3+
//
4+
// Stack is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Stack is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Stack. If not, see <http://www.gnu.org/licenses/>.
16+
17+
/**
18+
* This script searches to make sure language strings are really in use in the plugin.
19+
*
20+
* @package qtype_stack
21+
* @subpackage cli
22+
* @copyright 2025 The University of Edinburgh
23+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24+
*/
25+
26+
define('CLI_SCRIPT', true);
27+
require(__DIR__ . '/../../../../config.php');
28+
require_once($CFG->libdir . '/clilib.php');
29+
include_once(__DIR__ . '/../lang/en/qtype_stack.php');
30+
$keys = array_keys($string);
31+
32+
/*
33+
* This function finds all the occurances of $str.
34+
*/
35+
function grep_for($str) {
36+
$command = "cd ..\n grep -rn \"{$str}\" *\n";
37+
//echo $command . "\n";
38+
$env = ['PATH' => getenv('PATH')];
39+
$descriptors = [
40+
0 => ['pipe', 'r'],
41+
1 => ['pipe', 'w'],
42+
];
43+
$grepprocess = proc_open($command . ' 2>&1', $descriptors, $pipes, null, $env);
44+
if (!is_resource($grepprocess)) {
45+
throw new exception('Could not open a process: ' . $command);
46+
}
47+
48+
$ret = '';
49+
while (!feof($pipes[1])) {
50+
$out = fread($pipes[1], 1024);
51+
if ('' == $out) {
52+
// Pause.
53+
usleep(1000);
54+
}
55+
$ret .= $out;
56+
}
57+
58+
fclose($pipes[0]);
59+
fclose($pipes[1]);
60+
61+
return trim($ret);
62+
}
63+
64+
$known = [];
65+
$known['exceptionmessage'] = true;
66+
$known['autosimplify'] = true;
67+
$known['autosimplifyprt'] = true;
68+
$known['ValidateVarsSpurious'] = true;
69+
$known['ValidateVarsMissing'] = true;
70+
$known['privacy:metadata'] = true;
71+
$known['stack:usediagnostictools'] = true;
72+
$known['answernotedefaulttrue'] = true;
73+
$known['answernotedefaultfalse'] = true;
74+
$known['bulktestindexintro'] = true;
75+
$known['healthuncached'] = true;
76+
77+
$ffound = 0;
78+
$nfound = 0;
79+
//$keys = ["questiontextplaceholderswhitespace"];
80+
foreach ($keys as $key) {
81+
if (substr($key, -5) === '_help' || substr($key, -5) === '_link') {
82+
$key = substr($key, 0, strlen($key) -5);
83+
}
84+
if (substr($key, -5) === '_name' || substr($key, -5) === '_fact') {
85+
break;
86+
}
87+
88+
// The following are legitimate ways language strings might appear in the code..
89+
$strs = [];
90+
$strs[] = "stack_string('" . $key . "'";
91+
$strs[] = "stack_string_error('" . $key . "'";
92+
$strs[] = "get_string('" . $key . "'";
93+
$strs[] = "output_cas_text('" . $key . "'";
94+
$strs[] = "{{#str}} " . $key;
95+
$strs[] = 'message=\\"' . $key;
96+
$strs[] = 'return(\\[true, \\"' . $key;
97+
$strs[] = 'return(\\[false, \\"' . $key;
98+
$strs[] = 'StackBasicReturn(false, false, \\"' . $key . '\\"';
99+
$strs[] = 'StackBasicReturn(true, false, \\"' . $key . '\\"';
100+
$strs[] = 'StackAddFeedback(\\"\\", \\"' . $key . '\\"';
101+
$strs[] = 'StackAddFeedback(FeedBack, \\"' . $key . '\\"';
102+
$strs[] = 'StackAddFeedback(fb, \\"' . $key . '\\"';
103+
$strs[] = 'StackAddNote(\\"\\", \\"' . $key . '\\"';
104+
$strs[] = 'StackAddNote(AnswerNote, \\"' . $key . '\\"';
105+
$strs[] = 'StackAddNote(ansnote, \\"' . $key . '\\"';
106+
107+
$found = false;
108+
if (array_key_exists($key, $known)) {
109+
$found = true;
110+
} else if (substr($key, 0, 28) === 'stackOptions_AnsTest_values_') {
111+
$found = true;
112+
} else if (substr($key, 0, 10) === 'pluginname') {
113+
$found = true;
114+
} else if (substr($key, 0, 9) === 'inputtype') {
115+
$found = true;
116+
} else if (substr($key, 0, 11) === 'healthcheck') {
117+
$found = true;
118+
} else {
119+
foreach ($strs as $str) {
120+
$ret = grep_for($str);
121+
if ($ret !== '') {
122+
$found = true;
123+
break;
124+
}
125+
}
126+
}
127+
if (!$found) {
128+
echo "Not found: " . $key . "\n";
129+
$nfound += 1;
130+
} else {
131+
$ffound += 1;
132+
}
133+
}
134+
135+
echo "\n\nFound: " . $ffound . "\n";
136+
echo "Not found: " . $nfound . "\n\n";

lang/en/qtype_stack.php

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@
3030
$string['pluginnamesummary'] = 'STACK provides mathematical questions for the Moodle quiz. These use a computer algebra system to establish the mathematical properties of the student\'s responses.';
3131

3232
$string['privacy:metadata'] = 'The STACK question type plugin does not store any personal data.';
33-
$string['cachedef_parsercache'] = 'STACK parsed Maxima expressions';
34-
$string['cachedef_librarycache'] = 'STACK question library renders and file structure';
35-
3633
$string['mbstringrequired'] = 'Installing the MBSTRING library is required for STACK.';
3734
$string['yamlrecommended'] = 'Installing the YAML library is recommended for STACK.';
3835

@@ -139,7 +136,6 @@
139136
$string['feedbackvariables_help'] = 'The feedback variables enable you to manipulate any of the inputs, together with the question variables, prior to traversing the tree. Variables defined here may be used anywhere else in this tree.';
140137
$string['feedbackvariables_link'] = '%%WWWROOT%%/question/type/stack/doc/doc.php/Authoring/Variables.md#Feedback_variables';
141138
$string['fieldshouldnotcontainplaceholder'] = '{$a->field} should not contain any [[{$a->type}:...]] placeholders.';
142-
$string['firstnodemusthavelowestnumber'] = 'The first node must have the lowest number.';
143139
$string['fixdollars'] = 'Fix dollars';
144140
$string['fixdollarslabel'] = 'Replace <code>$...$</code> with <code>\(...\)</code>, <code>$$...$$</code> with <code>\[...\]</code> and <code>@...@</code> with <code>{@...@}</code> on save.';
145141
$string['fixdollars_help'] = 'This option is useful if are copying and pasting (or typing) TeX with <code>$...$</code> and <code>$$...$$</code> delimiters. Those delimiters will be replaced by the recommended delimiters during the save process.';
@@ -167,7 +163,6 @@
167163
$string['showvalidationcompact'] = 'Yes, compact';
168164
$string['inputinvalidparamater'] = 'Invalid parameter';
169165
$string['mustverifyshowvalidation'] = 'You cannot choose to require two step validation but not show the results of validation to the student after the first step. This puts the student in an impossible position.';
170-
$string['htmlfragment'] = 'You appear to have some HTML elements in your expression.';
171166
$string['illegalcaschars'] = 'The characters @ and \\ are not allowed in CAS input.';
172167
$string['inputextraoptions'] = 'Extra options';
173168
$string['inputextraoptions_help'] = 'Some input types require extra options in order to work. You can enter them here. This value is a CAS expression.';
@@ -252,7 +247,6 @@
252247
$string['namealreadyused'] = 'You have already used this name.';
253248
$string['newnameforx'] = 'New name for \'{$a}\'';
254249
$string['next'] = 'Next';
255-
$string['nextcannotbeself'] = 'A node cannot link to itself as the next node.';
256250
$string['nodehelp'] = 'Response tree node';
257251
$string['nodehelp_help'] = '<h3> Answer test</h3>
258252
An answer test is used to compare two expressions to establish whether they satisfy some mathematical criteria.
@@ -281,7 +275,6 @@
281275
$string['nonempty'] = 'This must not be empty.';
282276
$string['noprtsifnoinputs'] = 'A question with no inputs cannot have any PRTs.';
283277
$string['notavalidname'] = 'Not a valid name';
284-
$string['optionsnotrequired'] = 'This input type does not require any options.';
285278
$string['penalty'] = 'Penalty';
286279
$string['penalty_help'] = 'The penalty scheme deducts this value from the result of each PRT for each different and valid attempt which is not completely correct.';
287280
$string['penalty_link'] = '%%WWWROOT%%/question/type/stack/doc/doc.php/Authoring/Feedback.md';
@@ -343,7 +336,6 @@
343336
$string['quiet_icon_true'] = '<span title ="Quiet on" alt="Quiet On Microphone icon" style="font-size: 1.25em; color:red;"><i class="fa fa-microphone-slash" aria-hidden="true"></i></span>';
344337
$string['quiet_icon_false'] = '<span title ="Quiet off" alt="Quiet Off Microphone icon" "style="font-size: 1.25em; color:blue;"><i class="fa fa-commenting-o"></i></span>';
345338
$string['renamequestionparts'] = 'Rename parts of the question';
346-
$string['requiredfield'] = 'This field is required!';
347339
$string['requirelowestterms'] = 'Require lowest terms';
348340
$string['requirelowestterms_help'] = 'When this option is set to yes, any coefficients or other rational numbers in an expression, must be written in lowest terms. Otherwise the answer is rejected as invalid.';
349341
$string['requirelowestterms_link'] = '%%WWWROOT%%/question/type/stack/doc/doc.php/Authoring/Inputs.md#Require_lowest_terms';
@@ -506,7 +498,6 @@
506498
$string['replacedollarsindextitle'] = 'Replace $s in question texts';
507499
$string['replacedollarsnoproblems'] = 'No problem delimiters found.';
508500
$string['replacedollarstitle'] = 'Replace $s in question texts in {$a}';
509-
$string['replacedollarserrors'] = 'The following questions generated errors.';
510501

511502
// Strings used by the bulk run question tests script.
512503
$string['expand'] = 'Expand';
@@ -648,15 +639,13 @@
648639
$string['chattitle'] = 'Test the connection to the CAS';
649640
$string['clearedthecache'] = 'CAS cached has been cleared.';
650641
$string['clearingcachefiles'] = 'Clearing cached STACK plot files {$a->done}/{$a->total}';
651-
$string['clearingthecache'] = 'Clearing the cache';
652642
$string['clearthecache'] = 'Clear the cache';
653643
$string['healthcheck'] = 'STACK healthcheck';
654644
$string['healthcheck_desc'] = 'The <a href="{$a->link}">healthcheck script</a> helps you verify that all aspects of STACK are working properly.';
655645
$string['healthcheckcache_db'] = 'CAS results are being cached in the database.';
656646
$string['healthcheckcache_none'] = 'CAS results are not being cached.';
657647
$string['healthcheckcache_otherdb'] = 'CAS results are being cached in another database.';
658648
$string['healthcheckcachestatus'] = 'The cache currently contains {$a} entries.';
659-
$string['healthcheckconfigintro1'] = 'Found, and using, Maxima in the following directory:';
660649
$string['healthcheckconnect'] = 'Trying to connect to the CAS';
661650
$string['healthcheckconnectintro'] = 'We are trying to evaluate the following CAS text:';
662651
$string['healthcheckfilters'] = 'Please ensure that the {$a->filter} is enabled on the <a href="{$a->url}">Manage filters</a> page.';
@@ -665,8 +654,6 @@
665654
$string['healthchecklatexintro'] = 'STACK generates LaTeX on the fly, and enables teachers to write LaTeX in questions. It assumes that LaTeX will be converted by a moodle filter. Below are samples of displayed and inline expressions in LaTeX which should be appear correctly in your browser. Problems here indicate incorrect moodle filter settings, not faults with STACK itself. STACK only uses the single and double dollar notation itself, but some question authors may be relying on the other forms.';
666655
$string['healthchecklatexmathjax'] = 'STACK relies on the Moodle MathJax filter. An alternative is to add javascript code to Moodle\'s additional HTML. See the STACK installation docs for more details of this option.';
667656
$string['healthcheckmathsdisplaymethod'] = 'Maths display method being used: {$a}.';
668-
$string['healthcheckmaximabat'] = 'The maxima.bat file is missing';
669-
$string['healthcheckmaximabatinfo'] = 'This script tried to automatically copy the maxima.bat script from inside "C:\Program files\Maxima-1.xx.y\bin" into "{$a}\stack". However, this seems not to have worked. Please copy this file manually.';
670657
$string['healthcheckproxysettings'] = '<strong>Warning:</strong> Moodle is set to use a proxy server but calls to maxima are bypassing this. Switch platform from "server" to "server (via proxy)" to route calls via the proxy server or add the maxima server to $CFG->proxybypass to make the bypass explicit. STACK should still function for now even if you do not make a change but Moodle proxy settings will be enforced in a later version.';
671658
$string['healthchecksamplecas'] = 'The derivative of {@ x^4/(1+x^4) @} is \[ \frac{\mathrm{d}}{\mathrm{d}x} \frac{x^4}{1+x^4} = {@ diff(x^4/(1+x^4),x) @}. \]';
672659
$string['healthcheckconnectunicode'] = 'Trying to send unicode to the CAS';
@@ -748,6 +735,7 @@
748735
<br/><p>C=<input id="_fakeinputC" value="[4, 1]" size="40"/></p>
749736
</div>';
750737
$string['healthchecksstackmaximaversion'] = 'Maxima version';
738+
$string['healthchecksstackmaximawarning'] = 'WARNING: the version of the STACK-Maxima libraries used do not match the expected version. Please visit the STACK heathcheck page to resolve the problems.';
751739
$string['healthchecksstackmaximaversionfixoptimised'] = 'Please <a href="{$a->url}">rebuild your optimised Maxima executable</a>.';
752740
$string['healthchecksstackmaximaversionfixserver'] = 'Please rebuild the Maxima code on your MaximaPool server.';
753741
$string['healthchecksstackmaximaversionfixunknown'] = 'It is not really clear how that happened. You will need to debug this problem yourself. Start by clearing the CAS cache.';
@@ -928,7 +916,6 @@
928916
$string['stackBlock_multiple_else'] = 'Multiple else branches in an if block.';
929917
$string['stackBlock_elif_after_else'] = '"elif" after an "else" in an if block.';
930918
$string['unrecognisedfactstags'] = 'The following facts tag(s) are not recognized: {$a->tags}.';
931-
$string['stackHintOld'] = 'The CASText has old-style hint tags. These should now be in the form <pre>[[facts:tag]]</pre>';
932919
$string['unknown_block'] = 'Unknown block of type {$a->type} requested!';
933920

934921
$string['Maxima_DivisionZero'] = 'Division by zero.';
@@ -1057,7 +1044,6 @@
10571044
$string['stackOptions_AnsTest_values_SRegExp'] = "SRegExp";
10581045
$string['stackOptions_AnsTest_values_Validator'] = "Validator";
10591046

1060-
$string['AT_NOTIMPLEMENTED'] = 'This answer test has not been implemented. ';
10611047
$string['TEST_FAILED'] = 'The answer test failed to execute correctly: please alert your teacher. {$a->errors}';
10621048
$string['TEST_FAILED_Q'] = 'The answer test failed to execute correctly: please alert your teacher. ';
10631049
$string['AT_MissingOptions'] = 'Missing option when executing the test. ';
@@ -1114,12 +1100,10 @@
11141100
$string['ATSet_wrongsz'] = 'Your set should have {$a->m0} different elements, but it actually has {$a->m1}. ';
11151101
$string['ATSet_wrongentries'] = 'The following entries are incorrect, although they may appear in a simplified form from that which you actually entered. {$a->m0} ';
11161102

1117-
$string['irred_Q_factored'] = 'The term {$a->m0} should be unfactored, but is not. ';
11181103
$string['irred_Q_commonint'] = 'You need to take out a common factor. '; // Needs a space at the end.
11191104
$string['irred_Q_optional_fac'] = 'You could do more work, since {$a->m0} can be further factored. However, you don\'t need to. ';
11201105

11211106
$string['FacForm_UnPick_morework'] = 'You could still do some more work on the term {$a->m0}. ';
1122-
$string['FacForm_UnPick_intfac'] = 'You need to take out a common factor. ';
11231107

11241108
$string['ATFacForm_error_list'] = 'The answer test failed. Please contact your systems administrator';
11251109
$string['ATFacForm_isfactored'] = 'Your answer is factored, well done. '; // Needs a space at the end.
@@ -1129,7 +1113,6 @@
11291113

11301114
$string['ATPartFrac_error_list'] = 'The answer test failed. Please contact your systems administrator';
11311115
$string['ATPartFrac_true'] = '';
1132-
$string['ATPartFrac_single_fraction'] = 'Your answer seems to be a single fraction, it needs to be in a partial fraction form. ';
11331116
$string['ATPartFrac_diff_variables'] = 'The variables in your answer are different to those of the question, please check them. ';
11341117
$string['ATPartFrac_denom_ret'] = 'If your answer is written as a single fraction then the denominator would be {$a->m0}. In fact, it should be {$a->m1}. ';
11351118
$string['ATPartFrac_ret_expression'] = 'Your answer as a single fraction is {$a->m0} ';
@@ -1255,7 +1238,6 @@
12551238
$string['studentValidation_listofunits'] = 'The units found in your answer were: {$a}';
12561239
$string['studentValidation_invalidAnswer'] = 'This answer is invalid. ';
12571240
$string['studentValidation_notes'] = '(This input is not assessed automatically by STACK.)';
1258-
$string['stackQuestion_noQuestionParts'] = 'This item has no question parts for you to answer.';
12591241

12601242
$string['Interval_notinterval'] = 'An interval was expected, but instead we have {$a->m0}.';
12611243
$string['Interval_wrongnumargs'] = 'Interval construction must have exactly two arguments, so this must be an error: {$a->m0}.';

stack/answertest/at_general_cas.class.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,17 @@ public function __construct(stack_ast_container $sans, stack_ast_container $tans
5757
public function do_test() {
5858

5959
if ('' == trim($this->sanskey->ast_to_string())) {
60-
$this->aterror = stack_string('TEST_FAILED', ['errors' => stack_string("AT_EmptySA")]);
61-
$this->atfeedback = stack_string('TEST_FAILED', ['errors' => stack_string("AT_EmptySA")]);
60+
$this->aterror = stack_string('TEST_FAILED', ['errors' => stack_string('AT_EmptySA')]);
61+
$this->atfeedback = stack_string('TEST_FAILED', ['errors' => stack_string('AT_EmptySA')]);
6262
$this->atansnote = $this->casfunction.'TEST_FAILED-Empty SA.';
6363
$this->atmark = 0;
6464
$this->atvalid = false;
6565
return null;
6666
}
6767

6868
if ('' == trim($this->tanskey->ast_to_string())) {
69-
$this->aterror = stack_string('TEST_FAILED', ['errors' => stack_string("AT_EmptyTA")]);
70-
$this->atfeedback = stack_string('TEST_FAILED', ['errors' => stack_string("AT_EmptyTA")]);
69+
$this->aterror = stack_string('TEST_FAILED', ['errors' => stack_string('AT_EmptyTA')]);
70+
$this->atfeedback = stack_string('TEST_FAILED', ['errors' => stack_string('AT_EmptyTA')]);
7171
$this->atansnote = $this->casfunction.'TEST_FAILED-Empty TA.';
7272
$this->atmark = 0;
7373
$this->atvalid = false;
@@ -77,7 +77,7 @@ public function do_test() {
7777
if (stack_ans_test_controller::process_atoptions($this->atname)) {
7878
if (null == $this->atoption) {
7979
$this->aterror = 'TEST_FAILED';
80-
$this->atfeedback = stack_string('TEST_FAILED', ['errors' => stack_string("AT_MissingOptions")]);
80+
$this->atfeedback = stack_string('TEST_FAILED', ['errors' => stack_string('AT_MissingOptions')]);
8181
$this->atansnote = 'STACKERROR_OPTION.';
8282
$this->atmark = 0;
8383
$this->atvalid = false;
@@ -94,7 +94,7 @@ public function do_test() {
9494
}
9595
if ('' == $this->atoption->ast_to_string()) {
9696
$this->aterror = 'TEST_FAILED';
97-
$this->atfeedback = stack_string('TEST_FAILED', ['errors' => stack_string("AT_MissingOptions")]);
97+
$this->atfeedback = stack_string('TEST_FAILED', ['errors' => stack_string('AT_MissingOptions')]);
9898
$this->atansnote = 'STACKERROR_OPTION.';
9999
$this->atmark = 0;
100100
$this->atvalid = false;

0 commit comments

Comments
 (0)