For example, the hieroglyphs were first translated in the 18th or 19th century. I know that the Rosetta Stone was used but having three different forms of a text (in my imagination) to translate a text whose language is pretty much lost completely. AFAIK the Egyptian language was already replaced by Arabic, meaning there were only distantly related languages to compare the text to. This would lead to customs being ignored, for example, as long as the topic stays the same, I don't need to mention it again in Japanese (I don't have to start every sentence with watashi ha, it is assumed after the first time sometimes even before that).
And how did we translate other texts like cuneiform?
There's always more to be said on the topic, but I wrote about the process for decipherment, with reference to cuneiform and Linear B, in these threads:
Why haven't we deciphered Indus Valley Civilization script yet?
When did the modern understanding of the history of Bronze Age Mesopotamia develop?
As I mention in the linked posts, you typically need either of the following for decipherment:
Knowledge of the underlying language(s) - ancient Greek for Linear B, the Maya languages for Maya hieroglyphs, etc.
A bilingual/multilingual inscription - the Rosetta Stone (Egyptian hieroglyphs), the Behistun inscription (cuneiform), the Karatepe bilingual (Anatolian hieroglyphs), the Idalion bilingual (Cypriot syllabary), etc.
In the cases in which we have neither, such as Linear A, decipherment remains elusive.
AFAIK the Egyptian language was already replaced by Arabic, meaning there were only distantly related languages to compare the text to.
Champollion, who played the key role in deciphering Egyptian hieroglyphs, was familiar with Coptic, the last stage of the Egyptian language. The grammar of Coptic differs markedly from the earliest phases of Egyptian (Old and Middle Egyptian) but is closely related to Late Egyptian and Demotic. For more on this, see my answer to How much did hieroglyphics change over time?