Skip to content

Commit 00d9d6b

Browse files
committed
Start to remove language strings which are not actually used in the plugin.
1 parent 974f8c7 commit 00d9d6b

7 files changed

Lines changed: 159 additions & 42 deletions

File tree

cli/langstrings.php

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
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+
69+
$ffound = 0;
70+
$nfound = 0;
71+
//$keys = ["ATAddConst_true"];
72+
foreach ($keys as $key) {
73+
if (substr($key, -5) === '_help' || substr($key, -5) === '_link') {
74+
$key = substr($key, 0, strlen($key) -5);
75+
}
76+
if (substr($key, -5) === '_name' || substr($key, -5) === '_fact') {
77+
break;
78+
}
79+
80+
// The following are legitimate ways language strings might appear in the code..
81+
$strs = [];
82+
$strs[] = "stack_string('" . $key . "'";
83+
$strs[] = "stack_string_error('" . $key . "'";
84+
$strs[] = "get_string('" . $key . "'";
85+
$strs[] = "output_cas_text('" . $key . "'";
86+
$strs[] = "{{#str}} " . $key;
87+
$strs[] = 'message=\\"' . $key;
88+
$strs[] = 'return(\\[true, \\"' . $key;
89+
$strs[] = 'return(\\[false, \\"' . $key;
90+
$strs[] = 'StackBasicReturn(false, false, \\"' . $key . '\\"';
91+
$strs[] = 'StackBasicReturn(true, false, \\"' . $key . '\\"';
92+
$strs[] = 'StackAddFeedback(\\"\\", \\"' . $key . '\\"';
93+
$strs[] = 'StackAddFeedback(FeedBack, \\"' . $key . '\\"';
94+
$strs[] = 'StackAddFeedback(fb, \\"' . $key . '\\"';
95+
$strs[] = 'StackAddNote(\\"\\", \\"' . $key . '\\"';
96+
$strs[] = 'StackAddNote(AnswerNote, \\"' . $key . '\\"';
97+
$strs[] = 'StackAddNote(ansnote, \\"' . $key . '\\"';
98+
99+
$found = false;
100+
if (array_key_exists($key, $known)) {
101+
$found = true;
102+
} else if (substr($key, 0, 28) === 'stackOptions_AnsTest_values_') {
103+
$found = true;
104+
} else if (substr($key, 0, 10) === 'pluginname') {
105+
$found = true;
106+
} else if (substr($key, 0, 9) === 'inputtype') {
107+
$found = true;
108+
} else {
109+
foreach ($strs as $str) {
110+
$ret = grep_for($str);
111+
if ($ret !== '') {
112+
$found = true;
113+
break;
114+
}
115+
}
116+
}
117+
if (!$found) {
118+
echo "Not found: " . $key . "\n";
119+
$nfound += 1;
120+
} else {
121+
$ffound += 1;
122+
}
123+
}
124+
125+
echo "\n\nFound: " . $ffound . "\n";
126+
echo "Not found: " . $nfound . "\n\n";

lang/en/qtype_stack.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@
139139
$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.';
140140
$string['feedbackvariables_link'] = '%%WWWROOT%%/question/type/stack/doc/doc.php/Authoring/Variables.md#Feedback_variables';
141141
$string['fieldshouldnotcontainplaceholder'] = '{$a->field} should not contain any [[{$a->type}:...]] placeholders.';
142-
$string['firstnodemusthavelowestnumber'] = 'The first node must have the lowest number.';
143142
$string['fixdollars'] = 'Fix dollars';
144143
$string['fixdollarslabel'] = 'Replace <code>$...$</code> with <code>\(...\)</code>, <code>$$...$$</code> with <code>\[...\]</code> and <code>@...@</code> with <code>{@...@}</code> on save.';
145144
$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.';
@@ -252,7 +251,6 @@
252251
$string['namealreadyused'] = 'You have already used this name.';
253252
$string['newnameforx'] = 'New name for \'{$a}\'';
254253
$string['next'] = 'Next';
255-
$string['nextcannotbeself'] = 'A node cannot link to itself as the next node.';
256254
$string['nodehelp'] = 'Response tree node';
257255
$string['nodehelp_help'] = '<h3> Answer test</h3>
258256
An answer test is used to compare two expressions to establish whether they satisfy some mathematical criteria.
@@ -343,7 +341,6 @@
343341
$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>';
344342
$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>';
345343
$string['renamequestionparts'] = 'Rename parts of the question';
346-
$string['requiredfield'] = 'This field is required!';
347344
$string['requirelowestterms'] = 'Require lowest terms';
348345
$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.';
349346
$string['requirelowestterms_link'] = '%%WWWROOT%%/question/type/stack/doc/doc.php/Authoring/Inputs.md#Require_lowest_terms';
@@ -506,7 +503,6 @@
506503
$string['replacedollarsindextitle'] = 'Replace $s in question texts';
507504
$string['replacedollarsnoproblems'] = 'No problem delimiters found.';
508505
$string['replacedollarstitle'] = 'Replace $s in question texts in {$a}';
509-
$string['replacedollarserrors'] = 'The following questions generated errors.';
510506

511507
// Strings used by the bulk run question tests script.
512508
$string['expand'] = 'Expand';
@@ -928,7 +924,6 @@
928924
$string['stackBlock_multiple_else'] = 'Multiple else branches in an if block.';
929925
$string['stackBlock_elif_after_else'] = '"elif" after an "else" in an if block.';
930926
$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>';
932927
$string['unknown_block'] = 'Unknown block of type {$a->type} requested!';
933928

934929
$string['Maxima_DivisionZero'] = 'Division by zero.';
@@ -1057,7 +1052,6 @@
10571052
$string['stackOptions_AnsTest_values_SRegExp'] = "SRegExp";
10581053
$string['stackOptions_AnsTest_values_Validator'] = "Validator";
10591054

1060-
$string['AT_NOTIMPLEMENTED'] = 'This answer test has not been implemented. ';
10611055
$string['TEST_FAILED'] = 'The answer test failed to execute correctly: please alert your teacher. {$a->errors}';
10621056
$string['TEST_FAILED_Q'] = 'The answer test failed to execute correctly: please alert your teacher. ';
10631057
$string['AT_MissingOptions'] = 'Missing option when executing the test. ';
@@ -1255,7 +1249,6 @@
12551249
$string['studentValidation_listofunits'] = 'The units found in your answer were: {$a}';
12561250
$string['studentValidation_invalidAnswer'] = 'This answer is invalid. ';
12571251
$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.';
12591252

12601253
$string['Interval_notinterval'] = 'An interval was expected, but instead we have {$a->m0}.';
12611254
$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;

stack/cas/castext2/blocks/parsons.block.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -504,37 +504,37 @@ public function validate(
504504
if (array_key_exists("columns", $this->params)) {
505505
if (!(preg_match('/^\d+$/', $this->params["columns"]) && intval($this->params["columns"]) > 0)) {
506506
$valid = false;
507-
$err[] = stack_string("stackBlock_parsons_invalid_columns_value");
507+
$err[] = stack_string('stackBlock_parsons_invalid_columns_value');
508508
}
509509
}
510510

511511
// Check value of rows is a string containing a numeric positive integer.
512512
if (array_key_exists("rows", $this->params)) {
513513
if (!(preg_match('/^\d+$/', $this->params["rows"]) && intval($this->params["rows"]) > 0)) {
514514
$valid = false;
515-
$err[] = stack_string("stackBlock_parsons_invalid_rows_value");
515+
$err[] = stack_string('stackBlock_parsons_invalid_rows_value');
516516
}
517517
}
518518

519519
// Check we cannot have rows specified without columns.
520520
if (array_key_exists("rows", $this->params) && !array_key_exists("columns", $this->params)) {
521521
$valid = false;
522-
$err[] = stack_string("stackBlock_parsons_underdefined_grid");
522+
$err[] = stack_string('stackBlock_parsons_underdefined_grid');
523523
}
524524

525525
// Check value of `item-height` is a string containing a positive integer.
526526
if (array_key_exists("item-height", $this->params)) {
527527
if (!(preg_match('/^\d+$/', $this->params["item-height"]) && intval($this->params["item-height"]) > 0)) {
528528
$valid = false;
529-
$err[] = stack_string("stackBlock_parsons_invalid_item-height_value");
529+
$err[] = stack_string('stackBlock_parsons_invalid_item-height_value');
530530
}
531531
}
532532

533533
// Check value of `item-width` is a string containing a positive integer.
534534
if (array_key_exists("item-width", $this->params)) {
535535
if (!(preg_match('/^\d+$/', $this->params["item-width"]) && intval($this->params["item-width"]) > 0)) {
536536
$valid = false;
537-
$err[] = stack_string("stackBlock_parsons_invalid_item-width_value");
537+
$err[] = stack_string('stackBlock_parsons_invalid_item-width_value');
538538
}
539539
}
540540

stack/cas/castext2/blocks/unknown.block.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function validate_extract_attributes(): array {
5555
* Unknown blocks are always invalid.
5656
*/
5757
public function validate(&$errors = [], $options = []): bool {
58-
$errors[] = new $options['errclass'](stack_string("unknown_block", ['type' => $this->params[' type']]),
58+
$errors[] = new $options['errclass'](stack_string('unknown_block', ['type' => $this->params[' type']]),
5959
$options['context'] . '/' . $this->position['start'] . '-' . $this->position['end']);
6060
return false;
6161
}

stack/maxima/intervals.mac

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ oc_num(x,y) := block([Ans],
7979
/* Validate student's input. */
8080

8181
/* Return a list of errors for a single connected component. */
82-
interval_validate_single_interval(ex) := block([ret, iop, il, ir],
83-
ret:"",
82+
interval_validate_single_interval(ex) := block([iop, il, ir],
8483
if trivialintervalp(ex) then return(""),
8584
if not(intervalp(ex)) then
8685
return(StackAddFeedback("", "Interval_notinterval", stack_disp(ex, "i"))),
@@ -91,8 +90,8 @@ interval_validate_single_interval(ex) := block([ret, iop, il, ir],
9190
il:first(args(ex)),
9291
ir:second(args(ex)),
9392
if real_numberp(il) and real_numberp(ir) and is(ir<il) then
94-
ret:StackAddFeedback(ret, "Interval_backwards", stack_disp(ex, "i"), stack_disp(apply(iop,[ir, il]), "i")),
95-
return(ret)
93+
return(StackAddFeedback("", "Interval_backwards", stack_disp(ex, "i"), stack_disp(apply(iop,[ir, il]), "i"))),
94+
return("")
9695
)$
9796

9897
/* Validate a realset, mostly for student feedback, so no errors thrown. */

0 commit comments

Comments
 (0)