mirror of
https://github.com/videojs/video.js.git
synced 2025-07-15 01:34:23 +02:00
@mister-ben updated language to inherit correctly and respect the attribute on the player. closes #3426
This commit is contained in:
committed by
Gary Katsevman
parent
7ae2c885a7
commit
5883c9236e
@ -21,6 +21,7 @@ CHANGELOG
|
|||||||
* @misteroneill improved Logging for IE < 11 ([view](https://github.com/videojs/video.js/pull/3356))
|
* @misteroneill improved Logging for IE < 11 ([view](https://github.com/videojs/video.js/pull/3356))
|
||||||
* @vdeshpande updated control text of modal dialog ([view](https://github.com/videojs/video.js/pull/3400))
|
* @vdeshpande updated control text of modal dialog ([view](https://github.com/videojs/video.js/pull/3400))
|
||||||
* @ldayananda fixed mouse handling on menus by using mouseleave over mouseout ([view](https://github.com/videojs/video.js/pull/3404))
|
* @ldayananda fixed mouse handling on menus by using mouseleave over mouseout ([view](https://github.com/videojs/video.js/pull/3404))
|
||||||
|
* @mister-ben updated language to inherit correctly and respect the attribute on the player ([view](https://github.com/videojs/video.js/pull/3426))
|
||||||
|
|
||||||
--------------------
|
--------------------
|
||||||
|
|
||||||
|
@ -131,14 +131,14 @@ During a Video.js player instantiation you can force it to localize to a specifi
|
|||||||
Determining Player Language
|
Determining Player Language
|
||||||
---------------------------
|
---------------------------
|
||||||
|
|
||||||
The player language is set to one of the following in descending priority
|
The player language is set to one of the following in descending priority:
|
||||||
|
|
||||||
* The language set in setup options as above
|
* The language specified in setup options as above
|
||||||
* The document language (`lang` attribute of the `html` element)
|
* The language specified by the closet element with a `lang` attribute. This could be the player itself or a parent element. Usually the document language is specified on the `html` tag.
|
||||||
* Browser language preference
|
* Browser language preference (the first language if more than one is configured)
|
||||||
* 'en'
|
* 'en'
|
||||||
|
|
||||||
That can be overridden after instantiation with `language('fr')`.
|
The player language can be change after instantiation with `language('fr')`. However localizable text will not be modified by doing this, for best results set the language beforehand.
|
||||||
|
|
||||||
Language selection
|
Language selection
|
||||||
------------------
|
------------------
|
||||||
|
@ -92,6 +92,25 @@ class Player extends Component {
|
|||||||
// see enableTouchActivity in Component
|
// see enableTouchActivity in Component
|
||||||
options.reportTouchActivity = false;
|
options.reportTouchActivity = false;
|
||||||
|
|
||||||
|
// If language is not set, get the closest lang attribute
|
||||||
|
if (!options.language) {
|
||||||
|
if (typeof tag.closest === 'function') {
|
||||||
|
let closest = tag.closest('[lang]');
|
||||||
|
if (closest) {
|
||||||
|
options.language = closest.getAttribute('lang');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let element = tag;
|
||||||
|
while (element && element.nodeType === 1) {
|
||||||
|
if (Dom.getElAttributes(tag).hasOwnProperty('lang')) {
|
||||||
|
options.language = element.getAttribute('lang');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
element = element.parentNode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Run base component initializing with new options
|
// Run base component initializing with new options
|
||||||
super(null, options, ready);
|
super(null, options, ready);
|
||||||
|
|
||||||
@ -2862,7 +2881,7 @@ Player.prototype.options_ = {
|
|||||||
'textTrackSettings'
|
'textTrackSettings'
|
||||||
],
|
],
|
||||||
|
|
||||||
language: document.getElementsByTagName('html')[0].getAttribute('lang') || navigator.languages && navigator.languages[0] || navigator.userLanguage || navigator.language || 'en',
|
language: navigator.languages && navigator.languages[0] || navigator.userLanguage || navigator.language || 'en',
|
||||||
|
|
||||||
// locales and their language translations
|
// locales and their language translations
|
||||||
languages: {},
|
languages: {},
|
||||||
|
@ -839,6 +839,24 @@ expect(3);
|
|||||||
strictEqual(player.localize('Good'), 'Brilliant', 'Ignored case');
|
strictEqual(player.localize('Good'), 'Brilliant', 'Ignored case');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('inherits language from parent element', function() {
|
||||||
|
var fixture = document.getElementById('qunit-fixture');
|
||||||
|
var oldLang = fixture.getAttribute('lang');
|
||||||
|
var player;
|
||||||
|
|
||||||
|
fixture.setAttribute('lang', 'x-test');
|
||||||
|
player = TestHelpers.makePlayer();
|
||||||
|
|
||||||
|
equal(player.language(), 'x-test', 'player inherits parent element language');
|
||||||
|
|
||||||
|
player.dispose();
|
||||||
|
if (oldLang) {
|
||||||
|
fixture.setAttribute('lang', oldLang);
|
||||||
|
} else {
|
||||||
|
fixture.removeAttribute('lang');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
test('should return correct values for canPlayType', function(){
|
test('should return correct values for canPlayType', function(){
|
||||||
var player = TestHelpers.makePlayer();
|
var player = TestHelpers.makePlayer();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user