Thanks for the great code; it saved me a lot of time.
I made one fix to the way BB tags with uids are handled, which was necessary for the translation to work for me. In topic.tpl.php, I replaced these two lines:
$text = str_replace(':' . $bid, '', $text);
$text = preg_replace('/\[(\/?)code:\d*\]/', '[\1code]', $text);
With this one
$text = preg_replace('/\[(\/?)(.+?):(.*?)\]/', '[$1$2]', $text);
I think that the $bid variable was being set to empty, so extracting it directly failed. This new regular expression handles all the tags, including the [code] tags, and simply discards the colon and everything after it.