Language select in search bar broken

The language select in the search bar is broken. You can select languages and search, but then when the page loads with the search results it’s still showing the selected languages, but if you search again it fails back to current_locale.

There appears to be quite a simple reason for this:

	languages = Cookies.get("languages");
    if (!languages || languages.trim() === "" || !isValidLanguage(languages)) {
        languages = current_locale;
    }

	$('#current_languages').val(languages);
	$('.lang_ln').each(function(){
		var href=$(this).attr("href");
		href=href.replace("lngprm",languages);
		$(this).attr("href",href);
	});

function isValidLanguage(language) {
var supportedLanguages = [“ab”,“af”,“am”,“sq”,“ar”,“an”,“hy”,“as”,“at”,“az-AZ”,“az-ZB”,“tm-TD”,“eu”,“be”,“bn”,“bs”,“br”,“bg”,“my”,“ca”,“ze”,“zh-CN”,“zh-TW”,“zh-CA”,“hr”,“cs”,“da”,“pr”,“nl”,“en”,“eo”,“et”,“ex”,“fi”,“fr”,“gd”,“gl”,“ka”,“de”,“el”,“he”,“hi”,“hu”,“is”,“ig”,“id”,“ia”,“ga”,“it”,“ja”,“kn”,“kk”,“km”,“kr”,“ku”,“lv”,“lt”,“lb”,“mk”,“ms”,“ml”,“ma”,“mr”,“mn”,“me”,“nv”,“ne”,“se”,“no”,“oc”,“or”,“fa”,“pl”,“pt-PT”,“pt-BR”,“pm”,“ps”,“ro”,“ru”,“sx”,“sr”,“sd”,“si”,“sk”,“sl”,“so”,“es”,“sp”,“ea”,“sw”,“sv”,“sy”,“tl”,“ta”,“tt”,“te”,“th”,“tp”,“tr”,“tk”,“uk”,“ur”,“uz”,“vi”,“cy”];
return supportedLanguages.includes(language);
}

The problem here is that the languages are stored as a comma separated string in the cookie, so as soon as it contains more than one language isValidLanguage() will always return false.

Now, without looking at the full code it’s hard to say if this is all that’s needed to solve it, but it will solve not falling back to the current locale when more than one language is in the cookie.

const languages = (Cookies.get("languages") || "")
    .split(",")
    .map(language => language.trim())
    .filter(isValidLanguage);
if (!languages.length) languages = [current_locale];


$('#current_languages').val(languages);

the flag you see on the search bar is the language preference to search subtitles, it can contain one or multiple languages.

the flag on the right is got the locale preference, it can contain only one language.

maybe you are experiencing a bug I can’t reproduce and I just don’t understand your question, please try to clear the page cache data in your browser or try with a different one.

note also that we are about to release the upgraded layout for opensubtites.com and all the code you see now is already replaced - we don’t work anymore on what you see online now.