A correspondent writes:
1) I am writing a template grader with combinator option, in which I
want to use 'showdifferences' option. Moodle 3.9 on which I work has two
languages: Polish (main) and English; users can change language in the
top bar of the page. From what I've seen the 'Show differences' button
appears when there are columns named 'Expected' and 'Got' in the table
or name of columns are translated according to the language set (I read
the discussion https://coderunner.org.nz/mod/forum/discuss.php?d=115).
I wanted to make a universal template grader that returns a table with
'Expected' and 'Got' column names depending on what language the user
(student) has set (Polish: 'Oczekiwane' and 'Otrzymane', English:
'Expected' and 'Got'). I thought I could find such information in one of
the pre-defined Twig variables, but checking {{ _context | json_encode
}} I didn't find anything like that. Is this goal even possible to achieve?
Going further, we may have for example an English-speaking student who
should see the 'Expected' and 'Got' columns, and a teacher using the
Polish version of Moodle who should see the 'Oczekiwane' and 'Otrzymane'
columns in the student's solution. Does the template grader with the
combinator option assume that the column names are fixed?
2) Is it possible in template grader with combinator to hide result
table header (and actually whole result table) only for a student if all
test cases are hidden? Well, actually I did it by some HTML and
JavaScript in 'epiloguehtml' but I wonder if there is a better option.
Question (1): this is relatively easy to solve if you have a single-language site. The Combinator Template grader prints a JSON object defining the feedback. One of the possible attributes of that object is 'showdifferences'. If this has a true value (i.e. {"showdifferences": true, ... } the Show Differences button is enabled. The associated JavaScript looks in the result table header for the values of 'Expected' and 'Got' in whatever language Moodle is currently running. So if all your students are Polish, your returned result table can have your Polish column titles in it, and Show differences (which will of course display in Polish too) should work.
If you have different students using different languages it's more problematic.
With a combinator template grader you have complete control over the feedback you provide the student but because the grader is running on the Jobe server, completely separate from Moodle, you don't have access to the usual Moodle language strings. So you can't deliver feedback that depends on the language of the Moodle site as selected by a particular student. One thing I could do is add to the STUDENT record a field specifying the chosen language. That isn't hard and can go on my TODO list. But you will have to implement your own language translations. There's really no way of avoiding that in general since the combinator grader gives complete control to the question author and I wouldn't wish to constrain it to use only strings from the Moodle language-string set.
Question (2): the fact the result table was printed when all rows were empty was a bug, which was fixed in May 2021 by Matthew Toohey. The updated code is on github but hasn't yet been released to the Moodle plugin repository. I hope to do that some time this week.