show iso if language name is not found (prevent error)

This commit is contained in:
dingedi 2022-10-02 14:20:20 +02:00
parent 3072219085
commit eee2cf2f33
No known key found for this signature in database
GPG key ID: EE23A12D271A3CED

View file

@ -228,7 +228,8 @@ document.addEventListener('DOMContentLoaded', function(){
self.loadingTranslation = false;
self.output = JSON.stringify(res, null, 4);
if(self.sourceLang == "auto" && res.detectedLanguage !== undefined){
self.detectedLangText = ": " + self.langs.find(l => l.code === res.detectedLanguage.language).name+" ("+res.detectedLanguage.confidence+"%)";
let lang = self.langs.find(l => l.code === res.detectedLanguage.language)
self.detectedLangText = ": " + (lang !== undefined ? lang.name : res.detectedLanguage.language) + " (" + res.detectedLanguage.confidence + "%)";
}
} else{
throw new Error(res.error || "Unknown error");