LanguageSwitcher.vue 657 B

12345678910111213141516171819202122232425262728
  1. <script setup>
  2. const { locale, locales, setLocale } = useI18n()
  3. const availableLocales = computed(() => {
  4. return (locales.value)
  5. })
  6. function updateLocale(event) {
  7. setLocale(event.target.value)
  8. window.location.reload()
  9. }
  10. onMounted(() => {
  11. const langSwitcher = document.querySelector('#langSwitcher')
  12. langSwitcher.value = locale.value
  13. })
  14. </script>
  15. <template>
  16. <div flex gap2 items-center mt-5>
  17. Language:
  18. <select id="langSwitcher" rounded-md text-sm p-1 @change="updateLocale">
  19. <option v-for="loc in availableLocales" :key="loc.code" :value="loc.code" p-1>
  20. {{ loc.name }}
  21. </option>
  22. </select>
  23. </div>
  24. </template>