Files
ShakaPlayer/test/ui/language_utils_unit.js
Álvaro Velad Galván 5e3a246ee9 feat(UI): Disambiguate video tracks with the same role by language (#10307)
Follow-up to #10198: PR #10256 exposed per-stream
audioLanguage/videoLanguage on tracks, but the UI and preference APIs
still treated video tracks as distinguishable by role alone. Manifests
carrying multiple sign-language video tracks under the same 'sign' role
(e.g. American vs. Dutch Sign Language) could not be told apart or
selected individually.

Add language to `shaka.extern.VideoPreference` and filter by it in
`PreferenceBasedCriteria.applyVideoPreferences_`. Fix selectVideoTrack's
matching filter, which compared every video attribute except language.
Update `ResolutionSelection` to filter/dedupe by video language instead
of collapsing same-resolution tracks in different languages, and
VideoTypeSelection to group by (role, language) instead of role alone,
showing the language only when it's needed to disambiguate and omitting
a now-redundant role prefix when every option shares one.

Resolve deprecated 'sgn-XX' BCP-47 tags (not valid ISO 639-3 codes) to
their RFC 5645 replacement, and add a small name table for the
sign-language codes that neither mozilla.LanguageMapping nor
Intl.DisplayNames reliably names.
2026-07-12 10:09:53 -07:00

64 lines
2.4 KiB
JavaScript

/*! @license
* Shaka Player
* Copyright 2016 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
// cspell:words العربية
describe('LanguageUtils (UI)', () => {
const LanguageUtils = shaka.ui.LanguageUtils;
describe('getLanguageName', () => {
/** @type {!shaka.ui.Localization} */
let localization;
beforeEach(() => {
localization = new shaka.ui.Localization('en');
shaka.ui.Locales.addTo(localization);
});
it('resolves well-known languages', () => {
expect(LanguageUtils.getLanguageName('en', localization, true))
.toBe('English');
});
it('does not show a raw re-canonicalized code as a language name', () => {
// Regression test for
// https://github.com/shaka-project/shaka-player/issues/10198
// Some ICU implementations canonicalize the deprecated 'sgn-NL' tag to
// 'dse' and, lacking a display name for it, echo 'dse' back verbatim.
// We must not present that string as if it were a real language name.
const name = LanguageUtils.getLanguageName('sgn-NL', localization, true);
expect(name).not.toBe('Dse');
expect(name).not.toBe('dse');
});
it('resolves the deprecated sgn-XX form to its RFC 5645 replacement',
() => {
expect(LanguageUtils.getLanguageName('sgn-US', localization, true))
.toBe('American Sign Language');
expect(LanguageUtils.getLanguageName('sgn-NL', localization, true))
.toBe('Dutch Sign Language');
expect(LanguageUtils.getLanguageName('sgn-FR', localization, true))
.toBe('French Sign Language');
});
it('resolves sign-language names without Intl.DisplayNames', () => {
// preferIntlDisplayNames=false must still work, proving the name
// comes from our own table and not from the platform.
expect(LanguageUtils.getLanguageName('sgn-NL', localization, false))
.toBe('Dutch Sign Language');
expect(LanguageUtils.getLanguageName('sgn-US', localization, false))
.toBe('American Sign Language');
});
it('resolves the plain ISO 639-3 sign-language code directly', () => {
// Some manifests may already use the modern code instead of the
// deprecated 'sgn-XX' form.
expect(LanguageUtils.getLanguageName('dse', localization, false))
.toBe('Dutch Sign Language');
});
});
});