What's he saying?
"Shall I compare thee to a summer's day? / Thou art more lovely and more temperate:"
What if I were to compare you to a summer day? You are lovelier and more temperate (the perfect temperature):
"Rough winds do shake the darling buds of May / And summer's lease hath all too short a date:"
Summer's beauty is fragile and can be shaken, and summertime fades away all too quickly:
"Sometime too hot the eye of heaven shines / And often is his gold complexion dimm'd;"
Sometimes the sun is far too hot, and often it is too cool, dimmed by clouds and shade;
"And every fair from fair sometime declines / By chance or nature's changing course untrimm'd;"
And everything that is beautiful eventually loses its beauty, whether by chance or by the uncontrollable course of nature;
"But thy eternal summer shall not fade / Nor lose possession of that fair thou owest;"
But your eternal beauty (or youth) will not fade, nor will your beauty by lost;
"Nor shall Death brag thou wander'st in his shade / When in eternal lines to time thou growest:"
Nor will Death boast that you wander in his shadow, since you shall grow with time through these sonnets:
"So long as men can breathe or eyes can see / So long lives this and this gives life to thee."
For as long as people can breathe and see, this sonnet will live on, and you (and your beauty) with it.
Why is he saying it?
Sonnet 18 is arguably the most famous of the sonnets, its opening line competitive with "Romeo, Romeo, wherefore art thou Romeo?" in the long list of Shakespeare's quotable quotations. The gender of the addressee is not explicit, but this is the first sonnet after the so-called "procreation sonnets" (sonnets 1-17), i.e., it apparently marks the place where the poet has abandoned his earlier push to persuade the fair lord to have a child. The first two quatrains focus on the fair lord's beauty: the poet attempts to compare it to a summer's day, but shows that there can be no such comparison, since the fair lord's timeless beauty far surpasses that of the fleeting, inconstant season.
Here the theme of the ravages of time again predominates; we see it especially in line 7, where the poet speaks of the inevitable mortality of beauty: "And every fair from fair sometime declines." But the fair lord's is of another sort, for it "shall not fade" - the poet is eternalizing the fair lord's beauty in his verse, in these "eternal lines." Note the financial imagery ("summer's lease") and the use of anaphora (the repetition of opening words) in lines 6-7, 10-11, and 13-14. Also note that May (line 3) was an early summer month in Shakespeare's time, because England did not adopt the Gregorian calendar until 1752.
The poet describes summer as a season of extremes and disappointments. He begins in lines 3-4, where "rough winds" are an unwelcome extreme and the shortness of summer is its disappointment. He continues in lines 5-6, where he lingers on the imperfections of the summer sun. Here again we find an extreme and a disappointment: the sun is sometimes far too hot, while at other times its "gold complexion" is dimmed by passing clouds. These imperfections contrast sharply with the poet's description of the fair lord, who is "more temperate" (not extreme) and whose "eternal summer shall not fade" (i.e., will not become a disappointment) thanks to what the poet proposes in line 12.
In line 12 we find the poet's solution - how he intends to eternalize the fair lord's beauty despite his refusal to have a child. The poet plans to capture the fair lord's beauty in his verse ("eternal lines"), which he believes will withstand the ravages of time. Thereby the fair lord's "eternal summer shall not fade," and the poet will have gotten his wish. Here we see the poet's use of "summer" as a metaphor for youth, or perhaps beauty, or perhaps the beauty of youth.
But has the poet really abandoned the idea of encouraging the fair lord to have a child? Some scholars suggest that the "eternal lines" in line 12 have a double meaning: the fair lord's beauty can live on not only in the written lines of the poet's verse but also in the family lines of the fair lord's progeny. Such an interpretation would echo the sentiment of the preceding sonnet's closing couplet: "But were some child of yours alive that time / You should live twice; in it and in my rhyme." The use of "growest" also implies an increasing or changing: we can envision the fair lord's family lines growing over time, yet this image is not as readily applicable to the lines of the poet's verse - unless it refers only to his intention to continue writing about the fair lord's beauty, his verse thereby "growing." On the other hand, line 14 seems to counter this interpretation, the singular "this" (as opposed to "these") having as its most likely antecedent the poet's verse, and nothing more.