Browse Source

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

yuusora 3 years ago
parent
commit
a25d7d4da9
3 changed files with 13 additions and 13 deletions
  1. 2 2
      demo/demo.js
  2. 9 9
      src/js/i18n.js
  3. 2 2
      src/js/player.js

+ 2 - 2
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',
                 },
             ],

+ 9 - 9
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)',
     },
 };
 

+ 2 - 2
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;
                 }