Core MediaWiki has code for simple grammar transformations, used with {{GRAMMAR}} in messages. This code has to be written (and tested) separately in PHP and JS (and also in jquery.i18n).
The logic is supposed to be the same for the backend and the frontend, so it makes sense to make as much of the code and the data as possible shared between the (programming) languages. For most (human) languages the idea is the same: if a word matches a pattern, transform it according to a rule.
@Nikerabbit and I (@Amire80) went over most of the current code that does this, and as far as we can see, it can be replaced with pairs of regular expression patterns and replacements.
The plan is more or less this:
- Make sure that all the relevant unit tests are written.
- Make the tests common to PHP and JS (T115218).
- Find the patterns for each language, convert them from PHP and JS to regular expressions in JSON files, and delete and PHP and JS code.
- Optional 1: Move these JSON files, the tests and the PHP and JS logic that processes them) from the core to a separate library.
- Optional 2: Allow sites to provide custom grammar rules (and possibly move custom $wgGrammarForms from PHP arrays to a more data-based format, but this requires some thought).