Question: I can understand why the name of Robert is Roberto in Spanish, and there's obviously a connection between a name such as Mary in English and María in Spanish. But how do you explain Diego, which is the Spanish for James? They aren't at all alike.
Answer: The short answer is that languages change over time, and the original name of Ya'akov in Hebrew changed in different directions in Spanish and English. In fact, both Spanish and English have several variations of that old Hebrew name, of which James and Diego are the most common, so technically there are several ways you could translate those names from one language to another.
As you might be able to guess if you're familiar with the characters of the Bible, Ya'akov was the name given to a grandson of Abraham, a name given in modern English and Spanish Bibles as Jacob. That name itself has an interesting origin: Ya'akov, which may have meant "may he protect" or something similar, appears to be a word play on the Hebrew for "heel." According to the book of Genesis, Jacob was holding the heel of his twin brother Esau when the two were born.
The name Ya'acov became Iakobos in Greek. If you keep in mind that in some languages the sounds of b and v are quite similar (in modern Spanish they're identical), the Hebrew and Greek versions of the name look quite similar. By the time the Greek Iakobos became Latin it had turned into Iacobus and then Iacomus. The big change came as some Latin morphed into French, where Iacomus was shortened to Gemmes. The English James is derived from that French version.
The etymological change in Spanish is not as well understood, and authorities differ on the details. What appears likely, although not certain, was that the Iacomus became shortened to Iaco and then Iago. Some authorities say that Iago became lengthened to Tiago and then Diego. Others say the phrase Sant Iaco (sant is an old form of "saint") turned into Santiago, which was then improperly divided by some speakers into San Tiago, leaving the name of Tiago, which morphed into Diego.
Some authorities say that the Spanish name Diego was derived from the Latin name Didacus, meaning "instructed." If those authorities are correct, the similarity between Santiago and San Diego is a matter of coincidence, not etymology. There are also some authorities who combine theories, saying that while Diego was derived from the old Hebrew name, it was influenced by Didacus.
In any case, Santiago is recognized as a name of its own today, and the New Testament book known as James in English goes according to the name of Santiago. That same book is known today as Jacques in French and Jakobus in German, making the etymological link to the Old Testament name more clear.
So while it can be said (depending on which theory you believe) that Diego can be translated to English as James, it can also be seen as the equivalent of Jacob, Jake and Jim. And in reverse, James can be translated to Spanish not only as Diego, but also as Iago, Jacobo and Santiago.
Also, these days it isn't unusual for the Spanish name Jaime to be used as a translation of James. Jaime is a name of Iberian origin that various sources indicate is connected with James, although its etymology is unclear.