forked from snapshot-labs/snapshot-v1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuseI18n.ts
31 lines (25 loc) · 800 Bytes
/
useI18n.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
import { ref } from 'vue';
import { lsGet, lsSet } from '@/helpers/utils';
import i18n, {
defaultLocale,
setI18nLanguage,
loadLocaleMessages
} from '@/helpers/i18n';
const currentLocale = ref(lsGet('locale', defaultLocale));
export function useI18n() {
const { t, d, tc } = i18n.global;
async function setLocale(locale) {
currentLocale.value = locale;
lsSet('locale', locale);
await loadLocaleMessages(i18n, locale);
setI18nLanguage(i18n, locale);
}
async function loadLocale() {
await loadLocaleMessages(i18n, currentLocale.value);
setI18nLanguage(i18n, currentLocale.value);
}
function setPageTitle(message, params: any = {}) {
document.title = t(message, params);
}
return { t, d, tc, setLocale, loadLocale, currentLocale, setPageTitle };
}