In The Masque of Mandragora the Doctor tells Sarah that understanding other languages is 'a Time Lord gift I allow you to share'. Time Lords can understand all spoken languages (probably a function of their passive telepathic qualities). 'Allow' implies that it's a conscious decision on the Doctor's part to edit the words heard or spoken by his companions. The fan theory that its the TARDIS that does this is possible, but unsupported.
On some occasions, the Doctor can actually speak the language involved. He speaks Mandarin, Cantonese, Hokkien and Tibetan (The Talons of Weng-Chiang, The Mind of Evil, Planet of the Spiders), possibly as a result of his visits to Det-Sen, and a desire to show respect by using the subtleties and metaphorical content of a language. It would certainly be possible for a Time Lord to learn a language quickly (although the Doctor finds he can't talk with the brainless Zarbi in The Web Planet).
Initially, the Doctor's ability to include his companions faltered: the language of The Reign of Terror is an odd (if still understandable) mixture of French and English (e g 'The sign of Le Chien Gris'). The later Tibetan conversation, especially, since it's between two Time Lords, is the chat of two enthusiasts in their particular favourite tongue.
Sometimes, the Doctor suspends the 'gift' to make a particular point. He teaches Adric Earth digits in Logopolis, interested to see what the prodigy will make of the real information. In The War Games, the Doctor speaks German (a translation convention, generally we hear everything as English), but gets Carstairs to translate French for him (he was either too busy to keep the 'gift' going for so many people, or wanted to give Carstairs something useful to do).
In Four to Doomsday, he was going to make a joke of allowing Tegan the unlikely feat of speaking the correct one of thousands of Aborigine dialects for a native Australian who's from 35,000 years ago, but never gets round to the punchline. As demonstrated by Tegan's blasé reaction, those affected by the gift see nothing odd about their new abilities, perhaps a function of having their minds so altered. It was only Sarah noticing it, in The Masque of Mandragora, that alerted the Doctor to the fact that her mind had been further tampered with.
Written language is a much more difficult area for 'the gift', with many instances of understanding or not understanding alien documents. Perhaps that depends on whether a native speaker is nearby.