I’m used to googletranslating cell in google sheet, a solution that works quite well.
I wonder if there is any simple solution that can be used with DataFrames to translate some cell ?
The fact is i need to translate some hebrew to english.
I currently use formula like =GOOGLETRANSLATE(A1, "he", "en")
But this involve constantly shifting cell slices horizontally and vertically, which is very error prone.
A more reproducible research will be appreciated with DataFrames
using HTTP, JSON, DataFrames
function gtranslate(text, targetlang, sourcelang = "auto")
url = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=" * sourcelang * "&tl=" * targetlang * "&dt=t&q=" * HTTP.escapeuri(text)
result = JSON.parse(String(HTTP.request("GET", url).body))
join([s[1] for s in result[1]], "")
end
messages = ["Hello Julia." "Thank you for everything"; "You are welcome!" "Bye now"]
df = DataFrame(messages, :auto)
Row │ x1 x2
─────┼────────────────────────────────────────────
1 │ Hello Julia. Thank you for everything
2 │ You are welcome! Bye now
gtranslate.(df,"fr")
Row │ x1 x2
─────┼────────────────────────────────────────────
1 │ Bonjour Julia. Merci pour tout
2 │ Je vous en prie! Et maintenant, au revoir
gtranslate.(df,"iw")
Row │ x1 x2
─────┼───────────────────────────
1 │ שלום ג'וליה. תודה על הכל
2 │ בבקשה! להתראות
Absolutely. But the shorter form is not the only criteria IMO. I like a balance of concision and readability with context. The pipe conveys a sense of narrowing as used in modern query language for document db, graph db, stylesheet selector etc.
A game changer when refactoring / testing big document