forked from kodadot/nft-gallery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathi18n.ts
39 lines (35 loc) · 1.12 KB
/
i18n.ts
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
import Vue from 'vue';
import VueI18n, { LocaleMessages } from 'vue-i18n';
import MarkdownIt from 'markdown-it';
import commonData from './langDir/all_lang.json';
Vue.use(VueI18n);
const md = MarkdownIt({
breaks: false
});
function loadLocaleMessages(): LocaleMessages {
// File containing data common to ALL languages
const allLangDataFile = 'all_lang.json';
const locales = require.context('./langDir', true, /[A-Za-z0-9-_,\s]+\.json$/i);
const messages: LocaleMessages = {};
locales.keys().forEach(key => {
if (key === allLangDataFile) {
return;
}
const matched = key.match(/([A-Za-z0-9-_]+)\./i);
if (matched && matched.length > 1) {
const locale = matched[1];
messages[locale] = locales(key);
}
});
return messages;
}
// const locale = store.getters.getUserLang;
export default new VueI18n({
locale: process.env.VUE_APP_I18N_LOCALE || 'en',
fallbackLocale: process.env.VUE_APP_I18N_FALLBACK_LOCALE || 'en',
modifiers: {
md: str => md.renderInline(str),
common: str => str.split('.').reduce((o, i) => o[i], commonData as any)
},
messages: loadLocaleMessages()
});