I'm, using yandex api translate to detect language from input value. First fetch return a language ui code as a string. Than i'm using another one fetch to transform that code to a name of this language (en -> english).
const getLang = (lang) => {
fetch(`https://translate.yandex.net/api/v1.5/tr.json/getLangs?ui=en&key=${key}`)
.then(response => {
if (response.ok) return response
})
.then(response => {
return response.json();
})
.then(data => {
console.log(data.langs.lang);
})
}
getLang function return me undefined because lang is a string. When I',m typing "data.langs.en" in console function return "English". How can I remake my variable lang?