Fix Japanese voice ordering on Firefox for Android

This commit is contained in:
toasted-nutbread 2019-10-13 16:30:31 -04:00
parent f8e666b70c
commit 4f8c84d524

View File

@ -358,24 +358,28 @@ function updateTextToSpeechVoices() {
select.val(select.attr('data-value')); select.val(select.attr('data-value'));
} }
function compareLanguageTags(a, b) { function languageTagIsJapanese(languageTag) {
if (a.substr(0, 3) === 'ja-') { return (
return (b.substr(0, 3) === 'ja-') ? 0 : -1; languageTag.startsWith('ja-') ||
} else { languageTag.startsWith('jpn-')
return (b.substr(0, 3) === 'ja-') ? 1 : 0; );
}
} }
function textToSpeechVoiceCompare(a, b) { function textToSpeechVoiceCompare(a, b) {
const i = compareLanguageTags(a.voice.lang, b.voice.lang); const aIsJapanese = languageTagIsJapanese(a.voice.lang);
if (i !== 0) { return i; } const bIsJapanese = languageTagIsJapanese(b.voice.lang);
if (aIsJapanese) {
if (a.voice.default) { if (!bIsJapanese) { return -1; }
if (!b.voice.default) { } else {
return -1; if (bIsJapanese) { return 1; }
} }
} else if (b.voice.default) {
return 1; const aIsDefault = a.voice.default;
const bIsDefault = b.voice.default;
if (aIsDefault) {
if (!bIsDefault) { return -1; }
} else {
if (bIsDefault) { return 1; }
} }
if (a.index < b.index) { return -1; } if (a.index < b.index) { return -1; }