forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlang.js
More file actions
88 lines (71 loc) · 2.06 KB
/
lang.js
File metadata and controls
88 lines (71 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import Vue from 'vue'
import defaultLang from '../lang/en-us.js'
import { isSSR, fromSSR } from './plugins/Platform.js'
function getLocale () {
if (isSSR === true) { return }
const val =
navigator.language ||
navigator.languages[0] ||
navigator.browserLanguage ||
navigator.userLanguage ||
navigator.systemLanguage
if (val) {
return val.toLowerCase()
}
}
const Plugin = {
getLocale,
install ($q, queues, lang) {
const initialLang = lang || defaultLang
this.set = (langObject = defaultLang, ssrContext) => {
const lang = {
...langObject,
rtl: langObject.rtl === true,
getLocale
}
if (isSSR === true) {
if (ssrContext === void 0) {
console.error('SSR ERROR: second param required: Quasar.lang.set(lang, ssrContext)')
return
}
const dir = lang.rtl === true ? 'rtl' : 'ltr'
const attrs = `lang=${lang.isoName} dir=${dir}`
lang.set = ssrContext.$q.lang.set
ssrContext.Q_HTML_ATTRS = ssrContext.Q_PREV_LANG !== void 0
? ssrContext.Q_HTML_ATTRS.replace(ssrContext.Q_PREV_LANG, attrs)
: attrs
ssrContext.Q_PREV_LANG = attrs
ssrContext.$q.lang = lang
}
else {
if (fromSSR === false) {
const el = document.documentElement
el.setAttribute('dir', lang.rtl === true ? 'rtl' : 'ltr')
el.setAttribute('lang', lang.isoName)
}
lang.set = this.set
$q.lang = this.props = lang
this.isoName = lang.isoName
this.nativeName = lang.nativeName
}
}
if (isSSR === true) {
queues.server.push((q, ctx) => {
q.lang = {}
q.lang.set = langObject => {
this.set(langObject, ctx.ssr)
}
q.lang.set(initialLang)
})
this.isoName = initialLang.isoName
this.nativeName = initialLang.nativeName
this.props = initialLang
}
else {
Vue.util.defineReactive($q, 'lang', {})
this.set(initialLang)
}
}
}
export default Plugin
export { defaultLang }