fix(subtitles): default search use this.options.lang; use lowercase langcode

This commit is contained in:
yuusora 2022-01-25 14:41:11 +08:00
parent 3fb5f1b152
commit a25d7d4da9
3 changed files with 13 additions and 13 deletions

View File

@ -68,12 +68,12 @@ function initPlayers() {
url: [
{
subtitle: 'https://s-sh-17-dplayercdn.oss.dogecdn.com/hikarunara.vtt',
lang: 'zh-CN',
lang: 'zh-cn',
name: '光',
},
{
subtitle: 'https://gist.githubusercontent.com/samdutton/ca37f3adaf4e23679957b8083e061177/raw/e19399fbccbc069a2af4266e5120ae6bad62699a/sample.vtt',
lang: 'en-US',
lang: 'en-us',
name: 'github',
},
],

View File

@ -61,9 +61,9 @@ const tranTxt = {
Live: '直播',
'Video info': '视频统计信息',
Off: '关闭',
'zh-CN': '简体中文',
'zh-TW': '繁体中文',
'en-US': '英语',
'zh-cn': '简体中文',
'zh-tw': '繁体中文',
'en-us': '英语',
},
'zh-tw': {
'Danmaku is loading': '彈幕載入中',
@ -106,14 +106,14 @@ const tranTxt = {
Live: '直播',
'Video info': '影片統計訊息',
Off: '關閉',
'zh-CN': '簡體中文',
'zh-TW': '繁體中文',
'en-US': '英語',
'zh-cn': '簡體中文',
'zh-tw': '繁體中文',
'en-us': '英語',
},
'en-us': {
'zh-CN': 'Chinese(Simplified)',
'zh-TW': 'Chinese(Traditional)',
'en-US': 'English(US)',
'zh-cn': 'Chinese(Simplified)',
'zh-tw': 'Chinese(Traditional)',
'en-us': 'English(US)',
},
};

View File

@ -89,9 +89,9 @@ class DPlayer {
}
// defaultSubtitle not match or not exist or index bound(when defaultSubtitle is int), try browser language.
if (this.options.subtitle.index === -1 || !this.options.subtitle.index || this.options.subtitle.index > this.options.subtitle.url.length - 1) {
this.options.subtitle.index = this.options.subtitle.url.findIndex((sub) => sub.lang === navigator.language);
this.options.subtitle.index = this.options.subtitle.url.findIndex((sub) => sub.lang === this.options.lang);
}
// browser language not match, dedfault off title
// browser language not match, default off title
if (this.options.subtitle.index === -1) {
this.options.subtitle.index = this.options.subtitle.url.length - 1;
}