vp-translation.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <script setup lang="ts">
  2. import VPLink from '../common/vp-link.vue'
  3. import { useTranslation } from '../../composables/translation'
  4. const { switchLang, languageMap, langs, lang, helpTranslate } = useTranslation()
  5. </script>
  6. <template>
  7. <div class="translation-container">
  8. <ClientOnly>
  9. <ElPopover :show-arrow="false" trigger="hover" popper-class="translation-popup">
  10. <template #reference>
  11. <ElIcon :size="24">
  12. <i-ri-translate-2 />
  13. </ElIcon>
  14. </template>
  15. <div v-for="l in langs" :key="l" :class="{ language: true, selected: l === lang }" @click="switchLang(l)">
  16. {{ languageMap[l] }}
  17. </div>
  18. <div class="language">
  19. <VPLink :href="`/${lang}/guide/translation`">
  20. {{ helpTranslate }}
  21. </VPLink>
  22. </div>
  23. </ElPopover>
  24. </ClientOnly>
  25. </div>
  26. </template>
  27. <style lang="scss" scoped>
  28. @use '../../styles/mixins' as *;
  29. .translation-container {
  30. display: none;
  31. height: 24px;
  32. padding: 0 12px;
  33. @include respond-to('md') {
  34. display: block;
  35. }
  36. @at-root .translation-popup.el-popper {
  37. box-shadow: var(--el-box-shadow);
  38. .language {
  39. cursor: pointer;
  40. padding: 0 16px;
  41. line-height: 28px;
  42. &.selected {
  43. color: var(--brand-color);
  44. }
  45. .link-item {
  46. font-weight: 500;
  47. }
  48. }
  49. }
  50. }
  51. </style>