fix(ui): match ISO 639 lyric languages

This commit is contained in:
ranokay 2026-08-26 12:04:02 +03:00
commit 5fafda1544
No known key found for this signature in database
2 changed files with 25 additions and 2 deletions

View file

@ -1,5 +1,13 @@
const normalizeLanguageTag = (language) =>
(language || '').toLowerCase().replace(/_/g, '-')
const normalizeLanguageTag = (language) => {
const normalized = (language || '').trim().replace(/_/g, '-')
if (!normalized) return ''
try {
return Intl.getCanonicalLocales(normalized)[0].toLowerCase()
} catch {
return normalized.toLowerCase()
}
}
const LYRIC_KIND_MAIN = 'main'
const LYRIC_KIND_TRANSLATION = 'translation'

View file

@ -101,6 +101,21 @@ describe('lyrics helpers', () => {
expect(layers.main.line[0].value).toBe('繁體')
})
it('matches ISO 639-2 lyric languages to regional browser locales', () => {
const lyrics = [
structured('main', 'spa', 'Español'),
structured('main', 'eng', 'English'),
structured('main', 'por', 'Português'),
]
expect(selectLyricLayers(lyrics, 'en-US').main.line[0].value).toBe(
'English',
)
expect(selectLyricLayers(lyrics, 'pt-BR').main.line[0].value).toBe(
'Português',
)
})
it('resolves UTF-8 byte ranges without confusing repeated words', () => {
const text = 'caf\u00e9 caf\u00e9'