refactor: export global i18n config
This commit is contained in:
parent
df95804a53
commit
c3c61e78f3
|
@ -11,7 +11,7 @@ import AddFieldsDialog from './components/dialogs/AddFieldsDialog.vue'
|
||||||
import AppContent from './AppContent.vue'
|
import AppContent from './AppContent.vue'
|
||||||
import GroupDialog from './components/dialogs/GroupDialog.vue'
|
import GroupDialog from './components/dialogs/GroupDialog.vue'
|
||||||
import DeleteKeyDialog from './components/dialogs/DeleteKeyDialog.vue'
|
import DeleteKeyDialog from './components/dialogs/DeleteKeyDialog.vue'
|
||||||
import { computed, onBeforeMount, ref } from 'vue'
|
import { computed, onBeforeMount, onMounted, ref } from 'vue'
|
||||||
import usePreferencesStore from './stores/preferences.js'
|
import usePreferencesStore from './stores/preferences.js'
|
||||||
import useConnectionStore from './stores/connections.js'
|
import useConnectionStore from './stores/connections.js'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { ConnectionType } from './connection_type.js'
|
import { ConnectionType } from './connection_type.js'
|
||||||
|
|
||||||
const i18n = useI18n()
|
|
||||||
export const contextMenuKey = {
|
export const contextMenuKey = {
|
||||||
[ConnectionType.Server]: {
|
[ConnectionType.Server]: {
|
||||||
key: '',
|
key: '',
|
||||||
|
|
|
@ -1,27 +1,16 @@
|
||||||
import { createPinia } from 'pinia'
|
import { createPinia } from 'pinia'
|
||||||
import { createApp } from 'vue'
|
import { createApp } from 'vue'
|
||||||
import { createI18n } from 'vue-i18n'
|
|
||||||
import App from './App.vue'
|
import App from './App.vue'
|
||||||
import { lang } from './langs'
|
|
||||||
import './styles/style.scss'
|
import './styles/style.scss'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
import duration from 'dayjs/plugin/duration'
|
import duration from 'dayjs/plugin/duration'
|
||||||
import relativeTime from 'dayjs/plugin/relativeTime'
|
import relativeTime from 'dayjs/plugin/relativeTime'
|
||||||
|
import { i18n } from '@/utils/i18n.js'
|
||||||
|
|
||||||
dayjs.extend(duration)
|
dayjs.extend(duration)
|
||||||
dayjs.extend(relativeTime)
|
dayjs.extend(relativeTime)
|
||||||
|
|
||||||
const app = createApp(App)
|
const app = createApp(App)
|
||||||
app.use(
|
app.use(i18n)
|
||||||
createI18n({
|
|
||||||
locale: 'en',
|
|
||||||
fallbackLocale: 'en',
|
|
||||||
globalInjection: true,
|
|
||||||
legacy: false,
|
|
||||||
messages: {
|
|
||||||
...lang,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
app.use(createPinia())
|
app.use(createPinia())
|
||||||
app.mount('#app')
|
app.mount('#app')
|
||||||
|
|
|
@ -7,7 +7,10 @@ import {
|
||||||
RestorePreferences,
|
RestorePreferences,
|
||||||
SetPreferences,
|
SetPreferences,
|
||||||
} from 'wailsjs/go/services/preferencesService.js'
|
} from 'wailsjs/go/services/preferencesService.js'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useMessage } from '@/utils/message.js'
|
||||||
|
import { useConfirmDialog } from '@/utils/confirm_dialog.js'
|
||||||
|
import { BrowserOpenURL } from 'wailsjs/runtime/runtime.js'
|
||||||
|
import { i18nGlobal } from '@/utils/i18n.js'
|
||||||
|
|
||||||
const usePreferencesStore = defineStore('preferences', {
|
const usePreferencesStore = defineStore('preferences', {
|
||||||
/**
|
/**
|
||||||
|
@ -49,19 +52,18 @@ const usePreferencesStore = defineStore('preferences', {
|
||||||
},
|
},
|
||||||
|
|
||||||
themeOption() {
|
themeOption() {
|
||||||
const i18n = useI18n()
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
value: 'light',
|
value: 'light',
|
||||||
label: i18n.t('theme_light'),
|
label: i18nGlobal.t('theme_light'),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: 'dark',
|
value: 'dark',
|
||||||
label: i18n.t('theme_dark'),
|
label: i18nGlobal.t('theme_dark'),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: 'auto',
|
value: 'auto',
|
||||||
label: i18n.t('theme_auto'),
|
label: i18nGlobal.t('theme_auto'),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -71,14 +73,13 @@ const usePreferencesStore = defineStore('preferences', {
|
||||||
* @returns {{label: string, value: string}[]}
|
* @returns {{label: string, value: string}[]}
|
||||||
*/
|
*/
|
||||||
langOption() {
|
langOption() {
|
||||||
const i18n = useI18n()
|
|
||||||
const options = Object.entries(lang).map(([key, value]) => ({
|
const options = Object.entries(lang).map(([key, value]) => ({
|
||||||
value: key,
|
value: key,
|
||||||
label: value['lang_name'],
|
label: value['lang_name'],
|
||||||
}))
|
}))
|
||||||
options.splice(0, 0, {
|
options.splice(0, 0, {
|
||||||
value: 'auto',
|
value: 'auto',
|
||||||
label: i18n.t('system_lang'),
|
label: i18nGlobal.t('system_lang'),
|
||||||
})
|
})
|
||||||
return options
|
return options
|
||||||
},
|
},
|
||||||
|
@ -88,7 +89,6 @@ const usePreferencesStore = defineStore('preferences', {
|
||||||
* @returns {{path: string, label: string, value: string}[]}
|
* @returns {{path: string, label: string, value: string}[]}
|
||||||
*/
|
*/
|
||||||
fontOption() {
|
fontOption() {
|
||||||
const i18n = useI18n()
|
|
||||||
const option = map(this.fontList, (font) => ({
|
const option = map(this.fontList, (font) => ({
|
||||||
value: font.name,
|
value: font.name,
|
||||||
label: font.name,
|
label: font.name,
|
||||||
|
@ -96,7 +96,7 @@ const usePreferencesStore = defineStore('preferences', {
|
||||||
}))
|
}))
|
||||||
option.splice(0, 0, {
|
option.splice(0, 0, {
|
||||||
value: '',
|
value: '',
|
||||||
label: i18n.t('default'),
|
label: i18nGlobal.t('default'),
|
||||||
path: '',
|
path: '',
|
||||||
})
|
})
|
||||||
return option
|
return option
|
||||||
|
|
|
@ -1,24 +1,19 @@
|
||||||
import { createDiscreteApi } from 'naive-ui'
|
import { createDiscreteApi } from 'naive-ui'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { i18nGlobal } from '@/utils/i18n.js'
|
||||||
import { onMounted } from 'vue'
|
|
||||||
|
|
||||||
const { dialog } = createDiscreteApi(['dialog'])
|
const { dialog } = createDiscreteApi(['dialog'])
|
||||||
|
|
||||||
export function useConfirmDialog() {
|
export function useConfirmDialog() {
|
||||||
let i18n
|
|
||||||
onMounted(() => {
|
|
||||||
i18n = useI18n()
|
|
||||||
})
|
|
||||||
return {
|
return {
|
||||||
warning: (content, onConfirm) => {
|
warning: (content, onConfirm) => {
|
||||||
dialog.warning({
|
dialog.warning({
|
||||||
title: i18n.t('warning'),
|
title: i18nGlobal.t('warning'),
|
||||||
content: content,
|
content: content,
|
||||||
closable: false,
|
closable: false,
|
||||||
autoFocus: false,
|
autoFocus: false,
|
||||||
transformOrigin: 'center',
|
transformOrigin: 'center',
|
||||||
positiveText: i18n.t('confirm'),
|
positiveText: i18nGlobal.t('confirm'),
|
||||||
negativeText: i18n.t('cancel'),
|
negativeText: i18nGlobal.t('cancel'),
|
||||||
onPositiveClick: () => {
|
onPositiveClick: () => {
|
||||||
onConfirm && onConfirm()
|
onConfirm && onConfirm()
|
||||||
},
|
},
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
import { createI18n } from 'vue-i18n'
|
||||||
|
import { lang } from '@/langs/index.js'
|
||||||
|
|
||||||
|
export const i18n = createI18n({
|
||||||
|
locale: 'en',
|
||||||
|
fallbackLocale: 'en',
|
||||||
|
globalInjection: true,
|
||||||
|
legacy: false,
|
||||||
|
messages: {
|
||||||
|
...lang,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
export const i18nGlobal = i18n.global
|
|
@ -5,19 +5,19 @@ const { message } = createDiscreteApi(['message'])
|
||||||
export function useMessage() {
|
export function useMessage() {
|
||||||
return {
|
return {
|
||||||
error: (content, option = null) => {
|
error: (content, option = null) => {
|
||||||
message.error(content, option)
|
return message.error(content, option)
|
||||||
},
|
},
|
||||||
info: (content, option = null) => {
|
info: (content, option = null) => {
|
||||||
message.info(content, option)
|
return message.info(content, option)
|
||||||
},
|
},
|
||||||
loading: (content, option = null) => {
|
loading: (content, option = null) => {
|
||||||
message.loading(content, option)
|
return message.loading(content, option)
|
||||||
},
|
},
|
||||||
success: (content, option = null) => {
|
success: (content, option = null) => {
|
||||||
message.success(content, option)
|
return message.success(content, option)
|
||||||
},
|
},
|
||||||
warning: (content, option = null) => {
|
warning: (content, option = null) => {
|
||||||
message.warning(content, option)
|
return message.warning(content, option)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue