-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
133 lines (121 loc) · 3.46 KB
/
Copy pathindex.js
File metadata and controls
133 lines (121 loc) · 3.46 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import LuHeader from './LuHeader.vue'
import LuBreadCrumb from './LuBreadCrumb.vue'
import LuMain from './LuMain.vue'
import LuRow from './LuRow.vue'
import LuFooter from './LuFooter.vue'
import LuInfobox from './LuInfobox.vue'
import LuSpinner from './LuSpinner.vue'
import LuToTop from './LuToTop.vue'
import sv from './locales/sv.json'
import en from './locales/en.json'
import { library } from '@fortawesome/fontawesome-svg-core'
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
import { faChevronCircleUp } from '@fortawesome/pro-solid-svg-icons'
import {
faChevronDoubleDown,
faChevronDoubleUp,
faChevronDown,
faChevronRight,
faBars,
faCircleNotch,
faGlobe,
faMinusCircle,
faPlusCircle,
faSearch,
faSignIn,
faSignOut,
faTimes,
} from '@fortawesome/pro-light-svg-icons'
const messages = {
sv,
en,
}
function isI18nInstance (i18n) {
return (
i18n &&
typeof i18n === 'object' &&
i18n.global &&
typeof i18n.global.getLocaleMessage === 'function' &&
typeof i18n.global.setLocaleMessage === 'function' &&
Array.isArray(i18n.global.availableLocales)
)
}
const luTemplatePlugin = {
install (app, i18n) {
const logPrefix = '%c[@lu.se/vue-template] '
const logStyle = 'font-weight: bold; color: #875E29; font-family: system-ui'
library.add(
faBars,
faChevronCircleUp,
faChevronDoubleDown,
faChevronDoubleUp,
faChevronDown,
faChevronRight,
faCircleNotch,
faGlobe,
faMinusCircle,
faPlusCircle,
faSearch,
faSignIn,
faSignOut,
faTimes,
)
app.component('FaIcon', FontAwesomeIcon)
if (!isI18nInstance(i18n)) {
console.error(
logPrefix, logStyle, 'A valid vue-i18n instance was not provided. ' +
'Please pass the i18n instance when installing the plugin: app.use(luTemplate, i18n)',
)
return
}
const matchingLocales = Object.keys(messages).filter(locale => i18n.global.availableLocales.includes(locale))
if (matchingLocales.length === 0) {
console.error(
logPrefix, logStyle, 'i18n instance locales do not match any of the package\'s locales. ' +
'Please check your vue-i18n configuration. ' +
'The format used in this packages is ISO 639 (e.g. "sv", "en"). ' +
'If you cannot resolve this, you can resort to manually merging the messages, ' +
'see this package\'s README: https://github.com/johandalabacka/lu.se-vue-template/tree/master',
)
return
}
try {
// Merge package's messages into global i18n (the consumer's messages)
matchingLocales.forEach(locale => {
const existingMessages = i18n.global.getLocaleMessage(locale) || {}
i18n.global.setLocaleMessage(locale, {
...messages[locale],
...existingMessages,
})
})
} catch (error) {
console.error(
logPrefix, logStyle, 'An error occurred while merging messages:',
error,
)
return
}
const localesOnlyInConsumer = i18n.global.availableLocales.filter(locale => !Object.keys(messages).includes(locale))
if (localesOnlyInConsumer.length) {
console.warn(
logPrefix,
logStyle,
'Your locales [',
localesOnlyInConsumer.join(', '),
'] do not exist in the package messages.',
)
}
},
}
export {
LuHeader,
LuBreadCrumb,
LuMain,
LuRow,
LuFooter,
LuInfobox,
LuSpinner,
LuToTop,
messages,
}
export default luTemplatePlugin