Whatever anyone's opinion on the live-action movie franchise, there's a scene in the first movie that provides insight:
Optimus Prime: My name is Optimus Prime. We are autonomous robotic organisms from the planet Cybertron.
Ratchet: But you can call us Autobots for short.
Jazz: What's crackin', little bitches?
Optimus Prime: My first lieutenant.
Optimus Prime: Designation Jazz.
Jazz: This looks like a cool place to kick it.
Sam: What is that? How did he learn to talk like that?
Optimus Prime: We've learned Earth's languages through the World Wide Web. My weapons specialist, Ironhide.
The point is that the Transformers could quickly pick up a new language using available resources. Obviously, earlier in the franchise the World Wide Web or Internet wouldn't have been an option, but there would have been radio signal broadcasts that they could have intercepted.
Different iterations of the franchise will have different specific explanations (or none at all), based on the time period the Transformers came to planet.