From 8eb07af09a2caf2f392adf166127b0c4b4745c2d Mon Sep 17 00:00:00 2001 From: WooLNinesun Date: Tue, 29 Aug 2017 15:58:14 +0800 Subject: [PATCH 1/3] src/options: Browser langage support IE6 ~ IE8 use lowercase to prevent case typo from user src/i18n.js: Use language-code to support more language trans --- src/i18n.js | 91 +++++++++++++++++++++++++++++++++++---------------- src/option.js | 6 +++- 2 files changed, 67 insertions(+), 30 deletions(-) diff --git a/src/i18n.js b/src/i18n.js index 326d749..04d94b4 100644 --- a/src/i18n.js +++ b/src/i18n.js @@ -1,37 +1,70 @@ -const tranZH = { - 'Danmaku is loading': '弹幕加载中', - 'Top': '顶部', - 'Bottom': '底部', - 'Rolling': '滚动', - 'Input danmaku, hit Enter': '输入弹幕,回车发送', - 'About author': '关于作者', - 'DPlayer feedback': '播放器意见反馈', - 'About DPlayer': '关于 DPlayer 播放器', - 'Loop': '洗脑循环', - 'Speed': '速度', - 'Opacity for danmaku': '弹幕透明度', - 'Normal': '正常', - 'Please input danmaku content!': '要输入弹幕内容啊喂!', - 'Set danmaku color': '设置弹幕颜色', - 'Set danmaku type': '设置弹幕类型', - 'Danmaku': '弹幕', - 'This video fails to load': '视频加载失败', - 'Switching to': '正在切换至', - 'Switched to': '已经切换至', - 'quality': '画质', - 'FF to': '快进至', - 'REW to': '快退至', - 'Volume': '音量' -}; +/* +W3C def language codes is : + language-code = primary-code ( "-" subcode ) + primary-code ISO 639-1 ( the names of language with 2 code ) + subcode ISO 3166 ( the names of countries ) + +NOTE: use lowercase to prevent case typo from user! +Use this as shown below..... */ module.exports = function (lang) { this.lang = lang; this.tran = (text) => { - if (this.lang === 'en') { + if (this.lang === 'en-us') { return text; } - else if (this.lang === 'zh') { - return tranZH[text]; - } + else if ( + // add language-code list here + this.lang === 'zh-cn' || + this.lang === 'zh-tw' + ) { return tranTxt[this.lang][text]; } }; +}; + +// add translation text here +const tranTxt = { + "zh-cn" : { + 'Danmaku is loading': '弹幕加载中', + 'Top': '顶部', + 'Bottom': '底部', + 'Rolling': '滚动', + 'Input danmaku, hit Enter': '输入弹幕,回车发送', + 'About author': '关于作者', + 'DPlayer feedback': '播放器意见反馈', + 'About DPlayer': '关于 DPlayer 播放器', + 'Loop': '洗脑循环', + 'Speed': '速度', + 'Opacity for danmaku': '弹幕透明度', + 'Normal': '正常', + 'Please input danmaku content!': '要输入弹幕内容啊喂!', + 'Set danmaku color': '设置弹幕颜色', + 'Set danmaku type': '设置弹幕类型', + 'Danmaku': '弹幕', + 'This video fails to load': '视频加载失败', + 'Switching to': '正在切换至', + 'Switched to': '已经切换至', + 'quality': '画质', + }, + "zh-tw" : { + 'Danmaku is loading': '彈幕加載中', + 'Top': '頂部', + 'Bottom': '底部', + 'Rolling': '滾動', + 'Input danmaku, hit Enter': '輸入彈幕,Enter 發送', + 'About author': '關於作者', + 'DPlayer feedback': '播放器意見反饋', + 'About DPlayer': '關於 DPlayer 播放器', + 'Loop': '循環播放', + 'Speed': '速度', + 'Opacity for danmaku': '彈幕透明度', + 'Normal': '正常', + 'Please input danmaku content!': '請輸入彈幕内容啊!', + 'Set danmaku color': '設置彈幕顏色', + 'Set danmaku type': '設置彈幕類型', + 'Danmaku': '彈幕', + 'This video fails to load': '視頻加載失敗', + 'Switching to': '正在切換至', + 'Switched to': '已經切換至', + 'quality': '畫質', + } }; \ No newline at end of file diff --git a/src/option.js b/src/option.js index c1f5f66..4645df0 100644 --- a/src/option.js +++ b/src/option.js @@ -13,7 +13,7 @@ module.exports = (option) => { autoplay: false, theme: '#b7daff', loop: false, - lang: navigator.language.indexOf('zh') !== -1 ? 'zh' : 'en', + lang: (navigator.language || navigator.browserLanguage).toLowerCase().indexOf('zh-cn') !== -1 ? 'zh-cn' : 'en-us', screenshot: false, hotkey: true, preload: 'auto', @@ -53,5 +53,9 @@ module.exports = (option) => { option.video.url = [option.video.quality[option.video.defaultQuality].url]; } + if (option.lang) { + option.lang.toLowerCase(); + } + return option; }; \ No newline at end of file From ce936277e3d309273e4bdfc5dc3a64e34382dab9 Mon Sep 17 00:00:00 2001 From: WooLNinesun Date: Tue, 29 Aug 2017 17:06:59 +0800 Subject: [PATCH 2/3] add option.danmaku.margin to prevent block video subtitles --- demo/index.html | 5 ++++- src/html.js | 12 +++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/demo/index.html b/demo/index.html index 001ff57..d4eb9d6 100644 --- a/demo/index.html +++ b/demo/index.html @@ -23,7 +23,10 @@ }, danmaku: { id: '9E2E3368B56CDBB4', - api: 'https://api.prprpr.me/dplayer/' + api: 'https://api.prprpr.me/dplayer/', + margin: { + bottom:'15%' + } } }); diff --git a/src/html.js b/src/html.js index 8ed39ca..124e559 100644 --- a/src/html.js +++ b/src/html.js @@ -13,7 +13,7 @@ const html = { ${option.logo ? ` ` : ``} -
+
@@ -174,6 +174,16 @@ const html = {
`; }, + danmakumargin: (margin) => { + let result = ''; + if (margin) { + for (const key in margin) { + result += `${key}:${margin[key]};`; + } + } + return result; + }, + contextmenuList: (contextmenu) => { let result = '
'; for (let i = 0; i < contextmenu.length; i++) { From 42efc6b47991c657bc813eac76a5c2735252516e Mon Sep 17 00:00:00 2001 From: WooLNinesun Date: Tue, 29 Aug 2017 20:05:33 +0800 Subject: [PATCH 3/3] All corrected --- demo/index.html | 2 +- src/i18n.js | 10 ++++------ src/option.js | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/demo/index.html b/demo/index.html index d4eb9d6..eb391f9 100644 --- a/demo/index.html +++ b/demo/index.html @@ -25,7 +25,7 @@ id: '9E2E3368B56CDBB4', api: 'https://api.prprpr.me/dplayer/', margin: { - bottom:'15%' + bottom: '15%' } } }); diff --git a/src/i18n.js b/src/i18n.js index 04d94b4..ae1befb 100644 --- a/src/i18n.js +++ b/src/i18n.js @@ -10,14 +10,12 @@ Use this as shown below..... */ module.exports = function (lang) { this.lang = lang; this.tran = (text) => { - if (this.lang === 'en-us') { + if (tranTxt[this.lang]) { + return tranTxt[this.lang][text]; + } + else { return text; } - else if ( - // add language-code list here - this.lang === 'zh-cn' || - this.lang === 'zh-tw' - ) { return tranTxt[this.lang][text]; } }; }; diff --git a/src/option.js b/src/option.js index 4645df0..b63e3c0 100644 --- a/src/option.js +++ b/src/option.js @@ -13,7 +13,7 @@ module.exports = (option) => { autoplay: false, theme: '#b7daff', loop: false, - lang: (navigator.language || navigator.browserLanguage).toLowerCase().indexOf('zh-cn') !== -1 ? 'zh-cn' : 'en-us', + lang: (navigator.language || navigator.browserLanguage).toLowerCase(), screenshot: false, hotkey: true, preload: 'auto',