From 6548c9836ab2d5f393769eab7f51c40b7892d9d6 Mon Sep 17 00:00:00 2001 From: Erik Brommers <1458944+eb1@users.noreply.github.com> Date: Fri, 31 May 2024 13:25:31 -0700 Subject: [PATCH] Fix #577 Test length of localnames and names atts before using them; also prefer name to names[0] in selection. --- www/js/views/ProjectViews.js | 44 ++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/www/js/views/ProjectViews.js b/www/js/views/ProjectViews.js index 3f8e9655..96f9fc26 100644 --- a/www/js/views/ProjectViews.js +++ b/www/js/views/ProjectViews.js @@ -714,13 +714,13 @@ define(function (require) { if (data.attributes.localname) { return data.attributes.localname; } - if (data.attributes.localnames) { + if (data.attributes.localnames && data.attributes.localnames.length > 0) { return data.attributes.localnames[0]; } - if (data.attributes.names) { - return data.attributes.names[0]; + if (data.attributes.name) { + return data.attributes.name; } - return data.attributes.name; + return data.attributes.names[0]; }, source: this.languageMatches(this.theLangs), limit: 200, @@ -793,13 +793,13 @@ define(function (require) { if (data.attributes.localname) { return data.attributes.localname; } - if (data.attributes.localnames) { + if (data.attributes.localnames && data.attributes.localnames.length > 0) { return data.attributes.localnames[0]; } - if (data.attributes.names) { - return data.attributes.names[0]; + if (data.attributes.name) { + return data.attributes.name; } - return data.attributes.name; + return data.attributes.names[0]; }, source: this.languageMatches(this.theLangs), limit: 200, @@ -1198,9 +1198,9 @@ define(function (require) { // try autonym, fall back on language name in English if (firstLang.attributes.localname) { currentView.langName = firstLang.attributes.localname; - } else if (firstLang.attributes.localnames) { + } else if (firstLang.attributes.localnames && firstLang.attributes.localnames.length > 0) { currentView.langName = firstLang.attributes.localnames[0]; - } else if (firstLang.attributes.names) { + } else if (firstLang.attributes.names && firstLang.attributes.names.length > 0) { currentView.langName = firstLang.attributes.names[0]; } else { currentView.langName = firstLang.attributes.name; @@ -1220,12 +1220,12 @@ define(function (require) { // try autonym, fall back on language name in English if (suggestion.attributes.localname) { currentView.langName = suggestion.attributes.localname; - } else if (suggestion.attributes.localnames) { + } else if (suggestion.attributes.localnames && suggestion.attributes.localnames.length > 0) { currentView.langName = suggestion.attributes.localnames[0]; - } else if (suggestion.attributes.names) { - currentView.langName = suggestion.attributes.names[0]; - } else { + } else if (suggestion.attributes.name) { currentView.langName = suggestion.attributes.name; + } else { + currentView.langName = suggestion.attributes.names[0]; } newLangCode = suggestion.attributes.tag; currentView.langCode = buildFullLanguageCode(newLangCode, $('#LanguageVariant').val().trim().replace(/\s+/g, '')); @@ -1697,9 +1697,9 @@ define(function (require) { // try autonym, fall back on language name in English if (firstLang.attributes.localname) { currentView.langName = firstLang.attributes.localname; - } else if (firstLang.attributes.localnames) { + } else if (firstLang.attributes.localnames && firstLang.attributes.localnames.length > 0) { currentView.langName = firstLang.attributes.localnames[0]; - } else if (firstLang.attributes.names) { + } else if (firstLang.attributes.names && firstLang.attributes.names.length > 0) { currentView.langName = firstLang.attributes.names[0]; } else { currentView.langName = firstLang.attributes.name; @@ -1719,12 +1719,12 @@ define(function (require) { // try autonym, fall back on language name in English if (suggestion.attributes.localname) { currentView.langName = suggestion.attributes.localname; - } else if (suggestion.attributes.localnames) { + } else if (suggestion.attributes.localnames && suggestion.attributes.localnames.length > 0) { currentView.langName = suggestion.attributes.localnames[0]; - } else if (suggestion.attributes.names) { - currentView.langName = suggestion.attributes.names[0]; - } else { + } else if (suggestion.attributes.name) { currentView.langName = suggestion.attributes.name; + } else { + currentView.langName = suggestion.attributes.names[0]; } newLangCode = suggestion.attributes.tag; currentView.langCode = buildFullLanguageCode(newLangCode, $('#LanguageVariant').val().trim().replace(/\s+/g, '')); @@ -1918,9 +1918,9 @@ define(function (require) { // try autonym, fall back on language name in English if (firstLang.attributes.localname) { strLangName = firstLang.attributes.localname; - } else if (firstLang.attributes.localnames) { + } else if (firstLang.attributes.localnames && firstLang.attributes.localnames.length > 0) { strLangName = firstLang.attributes.localnames[0]; - } else if (firstLang.attributes.names) { + } else if (firstLang.attributes.names && firstLang.attributes.names.length > 0) { strLangName = firstLang.attributes.names[0]; } else { strLangName = firstLang.attributes.name;