From a25d7d4da9967df4534c95a42fb49f14a89d52d0 Mon Sep 17 00:00:00 2001 From: yuusora Date: Tue, 25 Jan 2022 14:41:11 +0800 Subject: [PATCH] fix(subtitles): default search use this.options.lang; use lowercase langcode --- demo/demo.js | 4 ++-- src/js/i18n.js | 18 +++++++++--------- src/js/player.js | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/demo/demo.js b/demo/demo.js index 2509ff6..e877b98 100644 --- a/demo/demo.js +++ b/demo/demo.js @@ -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', }, ], diff --git a/src/js/i18n.js b/src/js/i18n.js index 6f7b477..8aaee2b 100644 --- a/src/js/i18n.js +++ b/src/js/i18n.js @@ -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)', }, }; diff --git a/src/js/player.js b/src/js/player.js index facf3f2..9af5efd 100644 --- a/src/js/player.js +++ b/src/js/player.js @@ -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; }