As you mentioned Star Trek, I thought I'd note that show's usual
explanation: a computer that translates alien tongues into English.
Every now and again a Trek script would play with the concept a
little. Sometimes an alien language is so strange it takes a little while
for the translator to make sense of it. In the movie Star Trek VI,
there's a scene where our heroes, having been arrested by aliens, and their
personal translators (tiny earpieces, presumably?) confiscated, have to listen
to live simultaneous translation through intercom. And on the show
Star Trek: The Next Generation, there was an episode where the
words of an alien language could be translated, but the language was structured
as a series of metaphors to the alien species' history, so it still couldn't be
understood. (That is, a sentence might translate as something like, "Anash and
Gadul on the plains on Zirup," which sounds practically nonsensical but has an
actual meaning of, "Well met," because the reference is to some ancient happy
meeting.)
Too much information, I'm sure.
There's always the Hitchhiker's Guide to the Galaxy method: a
little translating fish that you stick in your
ear.