mirror of
https://github.com/shaka-project/shaka-player.git
synced 2026-06-16 16:16:40 +03:00
f584c9aab6
Issue #1157 Change-Id: Ie330cd870ccf14dc3f56987b2787970b46b1ac89
52 lines
1.4 KiB
JavaScript
52 lines
1.4 KiB
JavaScript
/**
|
|
* @license
|
|
* Copyright 2016 Google Inc.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
goog.provide('shaka.polyfill.Languages');
|
|
|
|
goog.require('shaka.polyfill');
|
|
|
|
|
|
/**
|
|
* @summary A polyfill to provide navigator.languages on all browsers.
|
|
* This is necessary for IE and possibly others we have yet to discover.
|
|
*/
|
|
shaka.polyfill.Languages = class {
|
|
/**
|
|
* Install the polyfill if needed.
|
|
*/
|
|
static install() {
|
|
if (navigator.languages) {
|
|
// No need.
|
|
return;
|
|
}
|
|
|
|
Object.defineProperty(navigator, 'languages', {
|
|
get: () => {
|
|
// If the browser provides a single language (all that we've seen), then
|
|
// make an array out of that. Otherwise, return English.
|
|
if (navigator.language) {
|
|
return [navigator.language];
|
|
}
|
|
return ['en'];
|
|
},
|
|
});
|
|
}
|
|
};
|
|
|
|
|
|
shaka.polyfill.register(shaka.polyfill.Languages.install);
|