Browse Source

refactor(gui-v2): remove vuetify from language switcher

pull/3099/head
braks 2 years ago
parent
commit
6d966965db
  1. 77
      packages/nc-gui-v2/components/general/Language.vue
  2. 5
      packages/nc-gui-v2/nuxt.config.ts

77
packages/nc-gui-v2/components/general/Language.vue

@ -1,28 +1,33 @@
<script lang="ts" setup>
import { useI18n } from 'vue-i18n'
import { Language } from '~/lib'
import { useNuxtApp } from '#imports'
import { onMounted, useGlobal, useI18n, useNuxtApp } from '#imports'
const { $e, $state } = useNuxtApp()
const { $e } = useNuxtApp()
const { lang: currentLang } = useGlobal()
const { availableLocales = ['en'], locale } = useI18n()
const languages = $computed(() => availableLocales.sort())
const isRtlLang = $computed(() => ['fa'].includes($state.lang.value))
const isRtlLang = $computed(() => ['fa'].includes(currentLang.value))
function applyDirection() {
const targetDirection = isRtlLang ? 'rtl' : 'ltr'
const oppositeDirection = targetDirection === 'ltr' ? 'rtl' : 'ltr'
document.body.classList.remove(oppositeDirection)
document.body.classList.add(targetDirection)
document.body.style.direction = targetDirection
}
function changeLanguage(lang: string) {
$state.lang.value = lang
currentLang.value = lang
locale.value = lang
applyDirection()
$e('c:navbar:lang', { lang })
}
@ -32,41 +37,39 @@ onMounted(() => {
</script>
<template>
<v-menu class="select-none">
<template #activator="{ props }">
<MaterialSymbolsTranslate v-bind="$attrs" class="md:text-xl cursor-pointer nc-menu-translate" @click="props.onClick" />
</template>
<a-dropdown class="select-none" :trigger="['click']">
<MaterialSymbolsTranslate v-bind="$attrs" class="md:text-xl cursor-pointer nc-menu-translate" />
<v-list class="scrollbar min-w-50 max-h-90vh overflow-auto !py-0 dark:(!bg-gray-800 !text-white)">
<v-list-item
v-for="lang of languages"
:key="lang"
:class="lang === locale ? '!bg-primary/10 text-primary dark:(!bg-gray-700 !text-secondary)' : ''"
class="!min-h-8 group"
:value="lang"
@click="changeLanguage(lang)"
>
<v-list-item-subtitle
:class="lang === locale ? '!font-semibold' : ''"
class="capitalize md:(!leading-8) group-hover:(text-primary font-semibold) dark:(group-hover:text-secondary)"
<template #overlay>
<a-menu class="scrollbar min-w-50 max-h-90vh overflow-auto !py-0 dark:(!bg-gray-800 !text-white)">
<a-menu-item
v-for="lang of languages"
:key="lang"
:class="lang === locale ? '!bg-primary/10 text-primary dark:(!bg-gray-700 !text-secondary)' : ''"
class="!min-h-8 group"
:value="lang"
@click="changeLanguage(lang)"
>
{{ Language[lang] || lang }}
</v-list-item-subtitle>
</v-list-item>
<v-divider />
<div
:class="lang === locale ? '!font-semibold !text-primary' : ''"
class="capitalize md:(!leading-8) group-hover:(text-primary font-semibold) dark:(group-hover:text-secondary)"
>
{{ Language[lang] || lang }}
</div>
</a-menu-item>
<v-list-item>
<a
href="https://docs.nocodb.com/engineering/translation/#how-to-contribute--for-community-members"
target="_blank"
class="caption py-2 text-primary underline hover:opacity-75"
>
{{ $t('activity.translate') }}
</a>
</v-list-item>
</v-list>
</v-menu>
<a-menu-item>
<a
href="https://docs.nocodb.com/engineering/translation/#how-to-contribute--for-community-members"
target="_blank"
class="caption py-2 text-primary underline hover:opacity-75"
>
{{ $t('activity.translate') }}
</a>
</a-menu-item>
</a-menu>
</template>
</a-dropdown>
</template>
<style scoped>

5
packages/nc-gui-v2/nuxt.config.ts

@ -106,4 +106,9 @@ export default defineNuxtConfig({
image: {
dir: 'assets/',
},
autoImports: {
dirs: ['./context', './utils', './lib'],
imports: [{ name: 'useI18n', from: 'vue-i18n' }],
},
})

Loading…
Cancel
Save