diff --git a/CHANGELOG.md b/CHANGELOG.md index 0205f2ace..ce5ced9ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,8 @@ _Breaking developer changes, which may affect downstream projects or sites that * Fix wrongly flagged "incorrect geometry type" warnings for features with lifecycle-prefixed tags ([#9483], thanks [@biswajit-k]) * Fix corruption of tag values of fields with referenced strings, but restricted `options`, when an unavailable option is entered manually into the field. * Properly handle case sensitive tag values in taginfo suggestions in raw tag editor ([#9640]) +* Fix dysfunctional autocomplete of wikidata fields for some languages with country-codes ([#9638]) + #### :earth_asia: Localization * Send `Accept-Language` header on Nominatim API calls ([#9501], thanks [@k-yle]) * Add Address and Phone Format for India ([#9482], thanks [@biswajit-k]) @@ -68,6 +70,7 @@ _Breaking developer changes, which may affect downstream projects or sites that [#9493]: https://github.com/openstreetmap/iD/pull/9493 [#9520]: https://github.com/openstreetmap/iD/pull/9520 [#9501]: https://github.com/openstreetmap/iD/pull/9501 +[#9638]: https://github.com/openstreetmap/iD/pull/9638 [#9640]: https://github.com/openstreetmap/iD/issues/9640 [@biswajit-k]: https://github.com/biswajit-k diff --git a/modules/services/wikidata.js b/modules/services/wikidata.js index 1e242114a..9cf69e84c 100644 --- a/modules/services/wikidata.js +++ b/modules/services/wikidata.js @@ -17,13 +17,13 @@ export default { // Search for Wikidata items matching the query - itemsForSearchQuery: function(query, callback) { + itemsForSearchQuery: function _itemsForSearchQuery(query, callback, language) { if (!query) { if (callback) callback('No query', {}); return; } - var lang = this.languagesToQuery()[0]; + var lang = language || this.languagesToQuery()[0]; var url = apibase + utilQsString({ action: 'wbsearchentities', @@ -42,7 +42,14 @@ export default { d3_json(url) .then(function(result) { if (result && result.error) { - throw new Error(result.error); + if (result.error.code === 'badvalue' && + result.error.info.includes(lang) && + !language && lang.includes('-')) { + // retry without "country suffix" region subtag + _itemsForSearchQuery(query, callback, lang.split('-')[0]); + } else { + throw new Error(result.error); + } } if (callback) callback(null, result.search || {}); })