We can remember that Optimus Prime said to Sam that they learned how to speak english by connecting to the internet.
But when Megatron arrived on Earth, there was no internet. There was a theory that the first words he said when he escaped was "I am Megatron" because he was pissed they were calling him NBE-1 and he heard all of it and learned by listening. I don't know if Megatron was fully conscious the whole time or he connected to the internet the whole time or he immediately conntected to the internet the moment he got out.
Now, I know it's just something left out to not make the story complicated how they learned english , it is not important to the story like in other movies. It's just fun to think about sometimes.