dsh-remote-plugin 0.5.2 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/apk/dsh-remote.apk +0 -0
- package/package.json +1 -1
- package/public/admin.html +245 -45
- package/public/admin.js +137 -68
- package/public/app.js +294 -201
- package/public/i18n.js +52 -0
- package/public/index.html +328 -67
- package/public/styles.css +542 -173
- package/public/theme.js +57 -0
- package/public/update.json +3 -3
- package/public/version.json +1 -1
package/public/i18n.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/* DSH Remote 轻量 i18n · 零依赖
|
|
2
|
+
* 页面内联定义 window.XXX_STR = { zh: {...}, en: {...} } 后调用 I18N.init(XXX_STR)。
|
|
3
|
+
* 静态节点用 data-i18n / data-i18n-title / data-i18n-placeholder / data-i18n-aria;
|
|
4
|
+
* JS 动态文案用 I18N.t('key', {var}),支持 {var} 占位。
|
|
5
|
+
* 语言: localStorage dshLang > navigator.language(zh* → 中文, 其余英文),可在页面上切换。 */
|
|
6
|
+
'use strict'
|
|
7
|
+
;(function () {
|
|
8
|
+
const store = {
|
|
9
|
+
get(k) { try { return localStorage.getItem(k) } catch { return null } },
|
|
10
|
+
set(k, v) { try { localStorage.setItem(k, v) } catch {} }
|
|
11
|
+
}
|
|
12
|
+
function detect() {
|
|
13
|
+
const saved = store.get('dshLang')
|
|
14
|
+
if (saved === 'zh' || saved === 'en') return saved
|
|
15
|
+
return (navigator.language || 'zh').toLowerCase().startsWith('zh') ? 'zh' : 'en'
|
|
16
|
+
}
|
|
17
|
+
let dict = null
|
|
18
|
+
let lang = detect()
|
|
19
|
+
|
|
20
|
+
function t(key, vars) {
|
|
21
|
+
const table = (dict && (dict[lang] || dict.zh)) || {}
|
|
22
|
+
let s = table[key]
|
|
23
|
+
if (s == null) s = (dict && dict.zh && dict.zh[key]) != null ? dict.zh[key] : key
|
|
24
|
+
s = String(s)
|
|
25
|
+
if (vars) for (const [k, v] of Object.entries(vars)) s = s.replaceAll('{' + k + '}', String(v ?? ''))
|
|
26
|
+
return s
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function apply(root) {
|
|
30
|
+
root = root || document
|
|
31
|
+
root.querySelectorAll('[data-i18n]').forEach(el => { el.textContent = t(el.getAttribute('data-i18n')) })
|
|
32
|
+
root.querySelectorAll('[data-i18n-title]').forEach(el => { el.title = t(el.getAttribute('data-i18n-title')) })
|
|
33
|
+
root.querySelectorAll('[data-i18n-placeholder]').forEach(el => { el.placeholder = t(el.getAttribute('data-i18n-placeholder')) })
|
|
34
|
+
root.querySelectorAll('[data-i18n-aria]').forEach(el => { el.setAttribute('aria-label', t(el.getAttribute('data-i18n-aria'))) })
|
|
35
|
+
document.documentElement.lang = lang === 'zh' ? 'zh-CN' : 'en'
|
|
36
|
+
return lang
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function setLang(l) {
|
|
40
|
+
if (l !== 'zh' && l !== 'en') return lang
|
|
41
|
+
lang = l
|
|
42
|
+
store.set('dshLang', l)
|
|
43
|
+
apply(document)
|
|
44
|
+
return lang
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
window.I18N = {
|
|
48
|
+
init(strings) { dict = strings || dict; return apply(document) },
|
|
49
|
+
t, setLang, apply,
|
|
50
|
+
get lang() { return lang }
|
|
51
|
+
}
|
|
52
|
+
})()
|