The issue with the above code was that OpenTBS inputs strings into a pair of <w:r><w:t>
tags, which need to be closed, before you insert your own. (As Sarah Kemp said in comments, <w:t>
doesn't appear to be nestable.
The below is an updated, working version. xml:space="preserve"
also needed to be added to preserve spacing.
//Function called onmerge. I wrap the portion of string I want to change the text
//colour of with [UNTRANSLATED] and [ENDUNTRANSLATED] manually earlier, and attempt
//to swap them for tags at this point.
function lb($FieldName, &$CurrVal) {
$CurrVal= str_replace('[UNTRANSLATED]', '</w:t></w:r><w:r><w:rPr><w:color w:val="FF0000"/></w:rPr><w:t xml:space="preserve">', $CurrVal);
$CurrVal= str_replace('[ENDUNTRANSLATED]', '</w:t></w:r><w:r><w:t xml:space="preserve">', $CurrVal);
}