SetLanguage.vue 967 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <script setup lang="ts">
  2. import { watch } from 'vue'
  3. import { useSettingsStore } from '@/pinia'
  4. import gettext from '@/gettext'
  5. import loadTranslations from '@/api/translations'
  6. const settings = useSettingsStore()
  7. const route = useRoute()
  8. const current = computed({
  9. get() {
  10. return gettext.current
  11. },
  12. set(v) {
  13. gettext.current = v
  14. },
  15. })
  16. const languageAvailable = gettext.available
  17. watch(current, v => {
  18. loadTranslations(route)
  19. settings.set_language(v)
  20. gettext.current = v
  21. const name = route.meta.name as never as () => string
  22. document.title = `${name()} | Nginx UI`
  23. })
  24. </script>
  25. <template>
  26. <div>
  27. <ASelect
  28. v-model:value="current"
  29. size="small"
  30. style="width: 60px"
  31. >
  32. <ASelectOption
  33. v-for="(language, key) in languageAvailable"
  34. :key="key"
  35. :value="key"
  36. >
  37. {{ language }}
  38. </ASelectOption>
  39. </ASelect>
  40. </div>
  41. </template>
  42. <style lang="less" scoped>
  43. </style>