I have just run up against a problem and I cannot yet think of any way to solve it, so I am asking here because you are all very clever.
Consider this situation: Suppose you have a course that is written in English, but is about the French languages. In that case, you might want a page with Title: 'Conjugation of the verb Être'.
Now, if you care about accessiblity, then for screen readers that needs to be marked up as 'Conjugation of the verb <span lang="fr">Être</span>'. (Because the course is in Engllish, there will be a lang="en" attribute on the <html> tag.)
The other use-case we have to remember (so we don't break it) is the Moodle multi-lang filter. If you had a course bilingual in English and Russion, then you might have a page titled '<span lang="en" class="multilang">cat</span><span lang="ru" class="multilang">кошка</span>', and that works becuase all headings are fed through format_string, which applied the multilang filter, and so that will end up as either 'cat' or 'кошка', and the screen-reader will prounouce that correctly because that language selected will match the overall language of the page. This is all good.
But, unfortunately one part of the format_string code is to always call strip_tags - $CFG->formatstringstriptags is true by default. This is quite sensible from a security / preventing XSS attacked point-of-view. Unfortunately, it means that the mixed language in headings case cannot possibly work - unless we can think of something very clever.
Please apply your genius.