Skip to content

Commit

Permalink
Fix #577
Browse files Browse the repository at this point in the history
Test length of localnames and names atts before using them; also prefer name to names[0] in selection.
  • Loading branch information
eb1 committed May 31, 2024
1 parent 8c6a7e0 commit 6548c98
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions www/js/views/ProjectViews.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -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, ''));
Expand Down Expand Up @@ -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;
Expand All @@ -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, ''));
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 6548c98

Please sign in to comment.