# Any equivalent of Google translate (like in gsheet) for DataFrames?

**URL:** https://discourse.julialang.org/t/any-equivalent-of-google-translate-like-in-gsheet-for-dataframes/73904
**Category:** General Usage
**Tags:** dataframes, big-data, nlp
**Created:** [January 1, 2022, 8:13pm UTC](https://discourse.julialang.org/t/any-equivalent-of-google-translate-like-in-gsheet-for-dataframes/73904 "2022-01-01T20:13:38Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![o314](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/o314/32/252_2.png) [@o314](https://discourse.julialang.org/u/o314)
#### Post date: [January 1, 2022, 8:13pm UTC](https://discourse.julialang.org/t/any-equivalent-of-google-translate-like-in-gsheet-for-dataframes/73904/1 "2022-01-01T20:13:38Z")

</div>

Hello there,

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

---

<div class="post-metadata">

### Author: ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)
#### Post date: [January 1, 2022, 8:23pm UTC](https://discourse.julialang.org/t/any-equivalent-of-google-translate-like-in-gsheet-for-dataframes/73904/2 "2022-01-01T20:23:50Z")

</div>

These are two separate tasks. You need a function that translates a hebrew string into an english string.

[https://github.com/sonicrules1234/GoogleTrans.jl](https://github.com/sonicrules1234/GoogleTrans.jl)

Then you can apply it to each of the values in the dataframe using `transform`.

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [January 2, 2022, 12:38am UTC](https://discourse.julialang.org/t/any-equivalent-of-google-translate-like-in-gsheet-for-dataframes/73904/3 "2022-01-02T00:38:35Z")

</div>

The `GoogleTrans.jl` package seems to be broken?

FWIW, the solution [posted here](https://discourse.julialang.org/t/how-to-use-google-translator-from-julia-level/33837/4) does work:

```julia
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 │ בבקשה! להתראות

```

---

<div class="post-metadata">

### Author: ![o314](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/o314/32/252_2.png) [@o314](https://discourse.julialang.org/u/o314)
#### Post date: [January 3, 2022, 5:26am UTC](https://discourse.julialang.org/t/any-equivalent-of-google-translate-like-in-gsheet-for-dataframes/73904/4 "2022-01-03T05:26:03Z")

</div>

Your snippet works for me too. Thanks.

A little remark about coding style concerning

```julia
join([s[1] for s in result[1]], "")

```

I prefer the form

```julia
result[1] .|> first |> join

```

`.|>` is not known enough (sometimes it right-associates eagerly, then block it with parenthesis or separated exprs)

Thanks anyway. Happy New Year to all

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [January 3, 2022, 7:44am UTC](https://discourse.julialang.org/t/any-equivalent-of-google-translate-like-in-gsheet-for-dataframes/73904/5 "2022-01-03T07:44:35Z")

</div>

> [@o314](#):
>
> `result[1] .|> first |> join`

This seems to be equivalent to the shorter: `join(first.(result[1]))`

---

<div class="post-metadata">

### Author: ![o314](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/o314/32/252_2.png) [@o314](https://discourse.julialang.org/u/o314)
#### Post date: [January 3, 2022, 9:10am UTC](https://discourse.julialang.org/t/any-equivalent-of-google-translate-like-in-gsheet-for-dataframes/73904/6 "2022-01-03T09:10:50Z")

</div>

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
