timetracker update
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
|
||||
import { useFetchJson } from '@/composable/useFetchJson'
|
||||
import { langs } from '@/router/langs'
|
||||
import type { Resp } from '@/types'
|
||||
import { getLangs } from '@/utils/fake'
|
||||
import { initLangs, langs } from '@/router/langs'
|
||||
import { watch } from 'vue'
|
||||
import { createI18n, type LocaleMessageValue, type PathValue, type VueMessageType } from 'vue-i18n'
|
||||
import { createI18n, type PathValue } from 'vue-i18n'
|
||||
|
||||
// const x =
|
||||
|
||||
await initLangs()
|
||||
export const i18ninstall = createI18n({
|
||||
legacy: false, // you must set `false`, to use Composition API
|
||||
locale: 'en',
|
||||
@@ -30,18 +29,22 @@ export const i18n = i18ninstall.global
|
||||
|
||||
let downloadedLangs = [] as string[]
|
||||
|
||||
const getLangs = async (l: string) => {
|
||||
|
||||
if (!downloadedLangs.includes(l)) {
|
||||
const lang = langs.find((x) => x.iso_code == l)
|
||||
if (!lang) return
|
||||
downloadedLangs.push(l)
|
||||
const res = await useFetchJson<any>(`/api/v1/translations?lang_id=${lang?.id}&scope=backoffice`)
|
||||
i18n.setLocaleMessage(l, res.items[lang.id]['backoffice'])
|
||||
}
|
||||
}
|
||||
|
||||
getLangs(i18n.locale.value)
|
||||
|
||||
watch(
|
||||
i18n.locale,
|
||||
async (l) => {
|
||||
if (!downloadedLangs.includes(l)) {
|
||||
const lang = langs.find((x) => x.iso_code == l)
|
||||
if (!lang) return
|
||||
downloadedLangs.push(l)
|
||||
const res = await useFetchJson<any>(`/api/v1/translations?lang_id=${lang?.id}&scope=backoffice`)
|
||||
// console.log(res.items[lang.id as number]['backoffice'])
|
||||
|
||||
i18n.setLocaleMessage(l, res.items[lang.id]['backoffice'])
|
||||
}
|
||||
},
|
||||
{},
|
||||
await getLangs(l)
|
||||
}
|
||||
)
|
||||
Reference in New Issue
Block a user