I imagine that google can do on-the-fly translation because they can eat the cost of the servers running the translation. Best I've seen for firefox uses deepl, which I've heard (on HN) is better than google translate.
https://Deepl.com/translator is really good IME. It provides more fluid translations and some better, more precise use of terms for me when translating technical documents (mechanical engineering) from French/German.