As the preceding contributors have described, the background (and sometimes foreground) sounds are either added or redone in post-production. When you’re watching the typical Hollywood movie, between three-quarters and nine-tenths of what you’re hearing wasn’t recorded onsite. During an action scene, often a hundred percent of the soundtrack is fabricated.
Trivia note: When shooting a dialogue scene in a location (wherein it’s hoped that the spoken words can be used in the film, instead of re-recorded, or “looped”), the sound guy gets a couple of minutes to record what’s called “room hum.” Everyone and everybody either stops what they’re doing or leaves entirely, and the “silence” is recorded for some period of time, from thirty seconds to five minutes depending on various factors. This is because every location has its own distinct sound, including air-conditioner hums, birds, wind, distant water, or even just the specific resonance off the walls. This background “silence” is used underneath studio-recorded dialogue to make it match dialogue recorded onsite.
By the way, you can actually hear the recorded-dialogue effect yourself a lot of the time. Next time you’re watching a movie, pay close attention to the sound behind the spoken words. In many cases, you can hear a hiss or other sound effects very quietly underneath the dialogue. When the actor stops talking, this background will ramp down fairly quickly, in order to let the manufactured soundtrack take over. Generally, this is done because in a “two-shot,” i.e. two people facing each other with the camera looking at alternating faces over the other’s shoulder, the actual shooting can happen an hour or more apart, or even on different days. When this happens, the background conditions can change over time, creating discrepancies in sound; if they just cut back and forth between the soundtracks with the visual edit, you’d definitely hear the difference. So they isolate the two dialogue tracks and carefully craft a “blended” background so you don’t notice the difference. (Sometimes it isn’t necessary; the shot in Fight Club where Pitt and Norton discuss blankets at the bar, for example, was shot with two cameras, one on each actor, so there’s only one soundtrack for both shots. That’s rare, though.) Anyway, if you listen closely, you can hear how the elements have been isolated and assembled.
This leads to one of my biggest pet peeves in movie sound. As Thylacinewas taken describes, crowd scenes in loud locations are shot, whenever possible, with a silent background. In a nightclub, for example, there would be no music, and anyone dancing would be doing it in sync to a beat set by somebody on a ladder waving a stick (or some other soundless method). If you think about it for a minute, you understand why this is done; otherwise you’d have the nightmare of trying to get actors to speak their lines in exactly the same place over the background song from shot to shot, so the editing matches. With a silent background, you can edit the dialogue any way you like, and add the music later. Anyway, because the set is silent when the scene is being shot, actors and crew frequently forget that, in the actual environment, they’d have to shout, so conversation takes place at a normal volume. Then, later, when the music is added, we get a nonsensical reality wherein two characters are sitting at a table twenty feet from a band onstage, yet they can murmur sweet nothings to each other despite the thumping soundtrack. (This happened a lot on Buffy.) Occasionally, of course, someone will remember, so you have actors feeling silly shouting at each other for no apparent reason, but sometimes that doesn’t work either; I saw a movie a while back (don’t remember which) where they remembered to do this, but the tone of the actors’ voices was wrong: on the soundtrack, you could hear their voices echoing off the bare walls of the silent-during-filming room, which sounded really weird.
Incidentally, the art of adding sound effects to actors’ actions — footsteps, doorknobs, scratching of crotches, or whatever — is called “foley.” Look for it in the credits. You do read the credits, right? 
Anyway, as others have described, using the above techniques, it’s a fairly easy trick to lift out the dialogue and put back a spoken track of any language you choose without impacting the rest of the sound.