I've noticed that in a lot of movies and TV shows set in Victorian England (or the same time period in other countries such as France or America), the operas are being sung in foreign languages such as German. So did the audience actually understand what was being sung?
While I have no idea if people listening to an opera in a language foreign to them have any idea what's going on (I certainly don't understand a word in anything by Wagner, although being well-versed enough in a foreign language to understand an opera might be part of the "high culture" appeal and stereotype) I can say that regarding Italian Opera the answer is most certainly yes!
Opera was even one of the art forms through which Italians vented their desire for unification in the 19th century! As much as the masses were mobilized against repressive monarchies, the conflicts that led to Italian Unification were equal parts bourgeois and populist in their formulation. Themes tied to history and nationalism permeated high culture consumed by the bourgeoisie, impacting the visual arts and literature along with musical opera. The lyrical works of Giuseppe Verdi stand out as both influenced by and influencing popular dialogue around Italian unity. Famously, the plight of the Isrealites in Egypt as depicted in Giuseppe Verdi's third opera, the Nabucco, so resonated with audiences that its chorus titled Va Pensiero became an anthem of sorts amongst activists in favor of Italian unification. While Verdi probably didn't explicitly set out to compose a nationalist opera, nationalist themes were almost certainly on the mind of other members of the production team (the writer of the libretto, Temistocle Solera, was involved with nationalist activism and would even end up becoming a courier of secret messages between the Prime Minister of Piedmont and Napoleon III as they planned the downfall of Austrian hegemony in Italy). In any case, the theatergoing public made up their own minds lyrics' meaning as soon as they heard them.
As an aside regarding to the importance of understanding the lyrics and plot in opera, it'd be important to point out that it was also common for composers to adapt operas in foreign languages. Often, signifiant changes were made based on the tastes and preferences of local audiences. Notably, Verdi adapted his fourth opera I Lombardi alla Prima Crociata into French during a sojourn in Paris, calling the adapted work Jérusalem. While much of the music is unchanged, the plot is completely different involves characters from the French city of Toulouse instead of the Italian region of Lombardy. Verdi would also adapt a number of Shakespeare's plays into operas sung in Italian.
Returning to his support of Italian unity, it's important to point out that Verdi's life and work was always just short of explicit. While Verdi certainly sympathized with the cause he was never an outright activist, and the theatergoing public did much of the work in parsing his lyrics to find nationalist subtext. He was certainly enthusiastic about the prospect of a unified Italian state: when staging Jérusalem in Paris he received word that the citizens of Milan and Venice had revolted against Austria, and he returned in all haste to the Kingdom of Lombardy-Venetia convinced it would not remain a constituent realm of the Austrian Empire for long. Writing to friends who had taken up prominent roles in the previsionary administration, he described himself as "drunk with joy." However, Verdi would subsequently distance himself from subversive intellectuals as the Austrian army re-took Milan. All this did nothing to stop his operas from being interpreted as odes to Italian nationalism. Verdi's librettists as well as his promoters did little to subdue these notions, and he ended up opening his 1849 opera La Battaglia di Legnano in Rome just as the city was on the cusp of a republican revolt. The opera, depicting medieval Italians victorious against a foreign enemy, was enthusiastically received. Indeed, rapturous applause followed a protagonist belting "He who dies for the fatherland cannot be bad/evil!" as he succumbs to his wounds on the battlefield ("Chi muore per la patria non può essere malvagio!"). A possibly apocryphal story would have the La Battaglia di Legnano explicitly written to appeal to Italian unity at the request of famed revolutionary activist Giuseppe Mazzini. But while Verdi and Mazzini did meet several times, it is altogether unclear they first came into contact, nor is it entirely clear how close Verdi was to Mazzini's activist circle. Little mattered for the theatergoing public, who cemented Verdi as an icon of the unification movement. As his popularity filtered down from the bourgeoisie to the masses, Verdi's name even became a coded acronym for Vittorio Emanuele Re D'Italia, a cry appealing to the King of Piedmont Victor Emmanuel to claim the title King of Italy. The graffiti "Viva V.E.R.D.I.," ambiguously wishing long life to either the composer or King Victor Emmanuel, appeared on walls and public places all over Italy.
Verdi himself was adept at toeing the line between what his operas could and could not do to appease the nationalist public in the face of repressive authorities. After the enormous success of the Nabucco he spent much of his time overseeing productions in various theaters all over Italy, contributing to nationalist dialogue becoming a sort of pop-culture phenomenon. His popularity meant that the opportunity to host the opening night of a Verdi opera was too enormous an occasion for local censors to take any real action (in fact, the only thing more dangerous that hosting a Verdi debut would probably be cancelling a Verdi debut). However Verdi also knew when to stop short of running into trouble. He even abandoned a project for the neapolitan opera house titled The Siege of Florence for fear of angering censors with an overly nationalist original work, and he and his librettist instead prepared a safer adaptation of an existing Austrian Opera titled Kabale und Liebe: Ein bürgerliches Trauerspiel. Verdi exhibited similar caution in his debut in Venice with the opera Rigoletto. Basing the work on Victor Hugo's Le Roi s'amuse, Verdi substituted the King character with a safer Duke lest the censors accuse him of enticing regicide with his lyrics.
Verdi's place in the hearts of his countrymen eventually earned him political recognition. He was first elected to head a delegation representing his home province in Emilia as they transitioned to Piedmontese rule. Upon the proclamation of the Kingdom of Italy in 1861 he was elected to represent his province in parliament, having run on the urging of prominent figures in the new country's government. But Verdi was an unenthusiastic politician, and admitted he had expected to be able to resign his seat after a few token months of public service. In spite of seldom making an appearance for the length of the 1861-1865 legislature, he was nominated to the senate for life in 1874. The unenthusiastic Verdi never participated in any senate sessions. For a man consistently described as very reserved, he might have been surprised at the way he had become one of the most prominent icons in the struggle for Italian unity. I think it's safe to say Verdi's lyrics spoke louder and clearer to his audiences then he ever did.