In
src
folder do you need create this folder with name
locales
and in locales folder you create all json file with name example
en.json
or
pt.json
or
es.json
with your translate file ocurrences follow this example json below
Now do you need usage translate in component and create this a select or a button for changing language of locale with hook global
useI18n
A example basic use in component with a select change of language
<scriptsetup>import{watch}from'vue';import{useI18n}from'vue-i18n';import{SUPPORT_LOCALESassupportLocales,setI18nLanguage}from'../i18n';const{locale}=useI18n({useScope:'global'});watch(locale,(val)=>{setI18nLanguage(val);</script><template><h1>{{$t('title.config')}}</h1><selectclass="App-language"v-model="locale"><optionv-for="optionLocale in supportLocales":key="`locale-${optionLocale}`"
:value="optionLocale">{{optionLocale}}</option></select></template>Enter fullscreen modeExit fullscreen mode
Front-end Developer and Designer specialist in creating technological solutions with Web standards
Always developing solutions with technologies: CSS, HTML, JavaScript, React, Angular, Vue.js
Front-end Developer and Designer specialist in creating technological solutions with Web standards
Always developing solutions with technologies: CSS, HTML, JavaScript, React, Angular, Vue.js
Built on Forem — the open source software that powers DEV and other inclusive communities.