(Uogokoro areba mizugokoro; “If fish-heart, then water-heart.”)
If you show good will and courtesy, others will show the same to you. If the fish acts friendly to the water, the water will in turn befriend the fish.
We begin with the noun 魚, “fish,” often pronounced sakana but in this case uo. Next is 心, kokoro, “mind” or “heart” or “spirit.” The voicing to gokoro implies that 魚心 is a compound, but this seems to be a result of historical shift away from the original; see below. In any case a noun, whether the compound or just the 心, is given the copular verb (equivalent to “to be” in English) あり (ari) in subjunctive form, ending the clause. It is possible to translate the subjunctive marker ば as “when” (in the sense of “when in Rome”) rather than “if.”
The the second “clause” as it comes down to us is simply another pair of nouns: 水 (mizu, “water”) and 心 again. In the past the verb あり was also repeated, in sentence-final form, but this seems to have been lost. And there you have it!
The version of this saying that has been transmitted to the present day is actually slightly incorrect in parsing. While the terms and general concept already existed, the origin of this specific phrasing seems to be in the 1767 Joururi play Sekitori senryou nobori, from a time before punctuation was imported from the West, and might be more clearly parsed as 魚、心あれば、水、心あり (uo, kokoro areba, mizu, kokoro ari; roughly “The fish, if it has a heart, the water, has a heart”). Over time the nouns seem to have been compounded and the final あり lost.
The term 魚心 can be used in a standalone way to refer to goodwill and friendliness.
A number of Japanese dictionaries give “You scratch my back and I’ll scratch yours” as an English equivalent, but I feel that this phrasing conveys more aloof calculation and profit motive than the Japanese conveys.
(“Uogokoro areba mizugokoro aru to iu toori, youki na otoko no hito ga a-tto iu ma ni kinjo no hito to nakayoku natta.”)
[“As it is said, if the fish has a heart, the water will also have a heart. Thus the cheerful man was on good terms with the neighbors in the blink of an eye.”]