tern: handle duplicate languages by stacking versions

This is pretty tricky, so we'll probably have to do some manual cleanup in a few
cases after the migration.  But I think it'll do the right thing for the most
part.
(cherry picked from commit f30b72010201908533bedf7e5c8a90892404cffc)