# Google Translation constructURL and fetch with JS

**URL:** <https://community.glideapps.com/t/google-translation-constructurl-and-fetch-with-js/79185>\
**Category:** Ask for Help\
**Created:** [January 14, 2025, 5:05am UTC](https://community.glideapps.com/t/google-translation-constructurl-and-fetch-with-js/79185 "2025-01-14T05:05:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![\_Romieux](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/_romieux/32/83089_2.png) [@\_Romieux](https://community.glideapps.com/u/_Romieux)\
**Post date:** [January 14, 2025, 5:05am UTC](https://community.glideapps.com/t/google-translation-constructurl-and-fetch-with-js/79185/1 "2025-01-14T05:05:11Z")

</div>

Hi,  
ConstructUrl and fetch later with Js is not clear to me. Can someone help us in this way using translate.googleapis

[https://translate.googleapis.com/translate\_a/single?client=gtx&sl=en&tl=es&dt=t&q=Hello](https://translate.googleapis.com/translate_a/single?client=gtx&sl=en&tl=es&dt=t&q=Hello)

I see:

 ![Capture d’écran 2025-01-14 à 05.45.17](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/3/1/3124443a609796e29456271be4521ae060462684.png)

Later  
pass the ConstructUrl to Js is not working

JAVA column  
func translate(str: String, lang1: String, lang2: String) {

```
let escapedStr = str.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed)
let lastPart = lang1 + "&tl=" + lang2 + "&dt=t&dt=t&q=" + escapedStr!
let urlStr: String = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=" + lastPart
let url = URL(string: urlStr)

let task = URLSession.shared.downloadTask(with: url!) { localURL, urlResponse, error in
    if let localURL = localURL {
        if let string = try? String(contentsOf: localURL) {
            let index = string.firstIndex(of: "\"")
            let index2 = string.index(after: index!)
            let subst = string.substring(from: index2)
            let indexf = subst.firstIndex(of: "\"")
            let result = subst.substring(to: indexf!)
            DispatchQueue.main.async {
                if flag1country != flag2country {
                    self.texto.text = result
                }
            }
        }
    }
}
task.resume()

```

}

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [January 15, 2025, 1:35am UTC](https://community.glideapps.com/t/google-translation-constructurl-and-fetch-with-js/79185/2 "2025-01-15T01:35:24Z")

</div>

Here’s how you should set it up.

 ![CleanShot 2025-01-15 at 08.32.07](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/a/0/a06e4a7ce69fbee3a96168b2a92ece59ecd81d67.png)

 ![CleanShot 2025-01-15 at 08.32.24](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/0/3/03023ac467178d40f3058409d52221d45ff8b919.png)

---

<div class="post-metadata">

**Author:** ![\_Romieux](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/_romieux/32/83089_2.png) [@\_Romieux](https://community.glideapps.com/u/_Romieux)\
**Post date:** [January 15, 2025, 7:31am UTC](https://community.glideapps.com/t/google-translation-constructurl-and-fetch-with-js/79185/3 "2025-01-15T07:31:08Z")

</div>

Thanks very much I have my results, and how to copy the result in another column as value (to fix the value forever) to prevent more usage of this api call?

thanks for your help
