The Midrash says that when Rebekah went to inquire of the LORD about her troubled pregnancy, she went to Jerusalem and asked the prophet Shem, who told her: "Two nations are in your womb, and two peoples from within you shall be divided; the one shall be stronger than the other, the older shall serve the younger" (Gen. 25:22-23). The prophet also told her that twelve tribes would descend from the younger son, who was chosen to be the patriarch of Israel.
Jacob grew up with the expectation that he would be the promised heir of Abraham and Isaac. He "bought" the birthright from his twin brother Esau and later conspired with his mother to have the "blessing of the firstborn" imparted to him. When he fled to Abraham's former homeland (in Haran) to escape Esau's wrath, Jacob received the vision of the ladder (i.e., sullam: Χ‘Φ»ΧΦΌΦΈΧ) that confirmed he was indeed the chosen heir (Gen. 28:12-14).
While in Haran Jacob got married to his uncle's daughters (first to Leah - by duplicity - and then to Rachel) and his family began to grow. Jacob believed the prophecy given to his mother (that he would be the father of twelve sons), and he doubtlessly shared his vision with his wives. Leah was the first to bear Jacob a son (Reuben). In the madness of the sibling rivalry between Leah and Rachel, handmaidens were given to Jacob to help produce the twelve sons of Israel (for details, see the Torah summary page on Vayetzei).
It is likely that each wife thought she would give birth to three sons for a total of twelve. Rachel, however, was barren, and when Leah gave birth to her fourth son, she exclaimed: "This time I will praise (ΧΧΦΉΧΦΆΧ) the LORD, and therefore she called his name Judah" (Gen. 29:35). Note that Leah's praise was not meant to gloat over her victory of Rachel, and indeed the midrash says that Rachel was genuinely happy for her sister and understood that Leah was blessed by the LORD. It seems at this point, the "rivalry" between the sisters had effectively come to an end.... So Leah's praise was somewhat different in the case of the birth of Judah - but in what way?
The Talmud states that from the time of creation, no one offered gratitude (ΧΧΦΉΧΦΈΧΦΈΧ) to the LORD until Leah (Berachot 7a). Perhaps this is hyperbole, but what made them regard Leah's gratitude as so special? The word hoda'ah (ΧΧΦΉΧΦΈΧΦΈΧ) has two connotations; one is gratitude and the other is admission (or confession). "There is a gratitude that expresses appreciation for a kindness, but a deeper, more profound form of gratitude is when one admits that what initially appeared as something detrimental was in reality a great favor" (Maayan Shel Torah).
Initially Leah considered it a personal tragedy that Jacob loved her less than Rachel, though eventually she came to realize that it was precisely because of this that God granted her the greater share of the tribes: "When the LORD saw that Leah was hated, he opened her womb" (Gen. 29:31). With the birth of Judah, Leah foresaw that both the priesthood (through Levi) and the Messiah (through Judah) would come from her descendants, and this caused her to rejoice and give thanks to God. She realized that God's compassion and love came to her despite her rejection, and therefore she gratefully acknowledged that the LORD worked it out for the best. It is altogether fitting that by the love and grace of the LORD, the rejected woman (i.e., Leah, a type of Eve) would become the "mother of the Messiah."
"According to the pain, is the reward" (Avot 5:22). God sometimes allows difficulties in the lives of those whom He favors in order to ultimately reward them. Why were Sarah, Rebekah, and Rachel barren for so many years? So that God would hear their prayers and reward them for their steadfast faith. Why was Leah more fruitful than the other wives of Jacob? Because she was "hated" and subject to unending gossip that she tried to steal her sister's husband, yet she persevered in hope. In this connection, some of the Chassidic sages render Psalm 118:21 as, "I thank you that you have pained me (Χ’Φ²Χ Φ΄ΧΧͺΦΈΧ Φ΄Χ) and have become my salvation." The pain that I regarded as punishment became the means by which I obtained the salvation of the LORD. Similarly, "It was good that I was afflicted (Χ’Φ»Χ ΦΌΦ΅ΧΧͺΦ΄Χ), that I might learn your decrees" (Psalm 119:71). Leah's expression of praise to the LORD - despite the various hardships of her life in this world - was later echoed by King David and the prophet Daniel, both descendants of her son Judah.
The Hebrew word hakarah (ΧΦ·ΧΦΌΦΈΧ¨ΦΈΧ) means recognition or consciousness, and the word tov (ΧΧΦΉΧ) means good. The phrase hakarat tovah (ΧΦ·ΧΦΌΦΈΧ¨Φ·Χͺ ΧΧΦΉΧΦΈΧ) therefore means recognizing or being conscious of the good, that is, gratitude... Hakarat tovah is one of the middot ha-lev (qualities of heart) that marks the life of someone who is made conscious of God's grace (ΟΞ±ΟΞΉΟ). Leah's praise of the LORD came when she finally confessed that despite the nisayonot (tests) of her life, the LORD was indeed loving and good to her.