Is there a tool in Moodle (or elsewhere) to flag defined language strings that are not actually used? I've been doing some massive refactoring of plugins and I'm sure such unused strings exist, and it would be good to remove them.
Ages ago I hacked together something like this. It was never a polished tool, and I don't think I have the code any more.
The basic concept was to use CodeChecker. At the time, I had recently worked on adding some custom rules for that, and so I know that in the 'process' method of a rule (e.g. https://github.com/moodlehq/moodle-local_codechecker/blob/master/pear/PHP/CodeSniffer/Standards/Generic/Sniffs/Functions/CallTimePassByReferenceSniff.php#L56) you get the PHP_CodeSniffer_File data structure representing the parsed PHP code for each file it processes. Therefore, it is quite easy to find calls to get_string (or, the lang string constructor) and dig out the arguments.
The tricky bit is where the arguments are variables, rather than just a literal string, but still, you can list those, and investigate them further by hand.
Then you need to look at code like https://github.com/moodlehq/moodle-local_codechecker/blob/master/index.php#L67 for invoking PHP_CodeSniffer with a given custom ruleset (which in this case would be just the one sniff), and doing stuff with the results.
Thanks Tim.
I was hoping something already existed, but using codechecker is likely the best way forward. I played with creating sniffs a couple of years ago. I'll have to brush up on that again.
I know the plugins database does some string checking. I can't remember if it identifies missing or unused. Hoping David Mudrack can see this and chime in.
I've often wished there was something that would do this the other way round, i.e. find get_string() calls where the string doesn't exist.
Many years ago, I had a simple grep-based script that was used for cleaning up strings for Moodle 2.0. The relevant issue is MDL-16769. The script is available at https://github.com/moodlehq/moodle-local_amos/blob/master/bin/detect.sh and may be used as an inspiration for a custom solution. Please feel encouraged to share eventual improvements.