Fix to avoid displaying duplicate results caused by redirects
This commit is contained in:
@@ -207,20 +207,31 @@
|
|||||||
var autofillLabel,
|
var autofillLabel,
|
||||||
results = [];
|
results = [];
|
||||||
|
|
||||||
$.each( result.languagesearch, function ( code, name ) {
|
$.each( result.languagesearch, function ( apiCode, name ) {
|
||||||
var target;
|
var code,
|
||||||
|
redirect = $.uls.data.isRedirect( apiCode );
|
||||||
|
|
||||||
if ( this.options.languages[ code ] ) {
|
if ( this.options.languages[ apiCode ] ) {
|
||||||
autofillLabel = autofillLabel || name;
|
code = apiCode;
|
||||||
results.push( code );
|
} else if ( redirect && this.options.languages[ redirect ] ) {
|
||||||
|
// Language tags are messy. Try to make sure we handle
|
||||||
|
// them gracefully with regards to redirects.
|
||||||
|
code = redirect;
|
||||||
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to hide issues caused by inconsistent language codes
|
// Because of the redirect checking above, we might get duplicates.
|
||||||
target = $.uls.data.isRedirect( code );
|
// For example if API returns both `sr` and `sr-cyrl`, the former
|
||||||
if ( target && this.options.languages[ target ] ) {
|
// could get mapped to `sr-cyrl` and then we would have it twice.
|
||||||
|
// The exact cases when this happens of course depends on what is in
|
||||||
|
// options.languages, which might contain redirects such as `sr`. In
|
||||||
|
// this case we only show `sr` if no other variants are there.
|
||||||
|
// This also protects against broken search APIs returning duplicate
|
||||||
|
// results, although that is not happening in practice.
|
||||||
|
if ( results.indexOf( code ) === -1 ) {
|
||||||
autofillLabel = autofillLabel || name;
|
autofillLabel = autofillLabel || name;
|
||||||
results.push( target );
|
results.push( code );
|
||||||
}
|
}
|
||||||
}.bind( this ) );
|
}.bind( this ) );
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user