You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importtype{Locale}from'vue-i18n'import{createI18n}from'vue-i18n'import{typeUserModule}from'~/types'// Import i18n resources// https://vitejs.dev/guide/features.html#glob-import//// Don't need this? Try vitesse-lite: https://github.com/antfu/vitesse-liteconsti18n=createI18n({legacy: false,locale: '',messages: {},})constlocalesMap=Object.fromEntries(Object.entries(import.meta.glob('../../locales/*.yml')).map(([path,loadLocale])=>[path.match(/([\w-]*)\.yml$/)?.[1],loadLocale]),)asRecord<Locale,()=>Promise<{default: Record<string,string>}>exportconstavailableLocales=Object.keys(localesMap)constloadedLanguages: string[]=[]exportconstactiveLang=ref('')functionsetI18nLanguage(lang: Locale){i18n.global.locale.value=langasanyif(typeofdocument!=='undefined'){activeLang.value=langdocument.querySelector('html')?.setAttribute('lang',lang)if(lang==='ar')document.querySelector('html')?.setAttribute('dir','rtl')elsedocument.querySelector('html')?.setAttribute('dir','ltr')}returnlang}exportasyncfunctionloadLanguageAsync(lang: string): Promise<Locale>{// If the same languageif(i18n.global.locale.value===lang)returnsetI18nLanguage(lang)// If the language was already loadedif(loadedLanguages.includes(lang))returnsetI18nLanguage(lang)// If the language hasn't been loaded yet// const messages = await localesMap[lang]()constmsgs: any=awaitnewPromise((resolve,reject)=>{setTimeout(async()=>{const{ data }=awaituseFetch(`http://127.0.0.1:8000/api/locales/content/${lang}`).get().json()resolve(data.value.data)},1000)})// eslint-disable-next-line no-consoleconsole.log(msgs)// i18n.global.setLocaleMessage(lang, messages.default)i18n.global.setLocaleMessage(lang,msgs)loadedLanguages.push(lang)returnsetI18nLanguage(lang)}exportconstinstall: UserModule=({ app })=>{app.use(i18n)loadLanguageAsync('ar')}
and here is my component script
import{useEditorStore}from'~/stores/editor'conststore=useEditorStore()constfield=ref('')constfieldKey=ref('')const{ t }=useI18n()constdialog=computed(()=>store.dialogModel)watch(dialog,async(newV)=>{if(newV===true)setupEditor()})const{ locale }=useI18n()functionsetupEditor(){field.value=t(store.fieldKey)fieldKey.value=store.fieldKey}constconfig=computed(()=>{return{page: fieldKey.value.split('.')[0],field: fieldKey.value.split('.')[1]}},)consturlAPI=computed(()=>`http://127.0.0.1:8000/api/locales/${config.value.page}/${config.value.field}/${locale.value}`)functionsave(model: any){const{ data }=useFetch(urlAPI.value).patch({value: model}).json()// update message value in 18n. ex : $('header.home') returndata}
function save(model: any) {
const { data } = useFetch(urlAPI.value).patch({ value: model }).json()
// update message value in 18n. ex : $('header.home') ❔ 😕
return data
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
hers is my i18n.ts module
and here is my component script
here were I want to upate the message
Beta Was this translation helpful? Give feedback.
All reactions