mirror of
https://github.com/zammad/zammad
synced 2026-05-24 09:48:36 +00:00
65 lines
1.9 KiB
TypeScript
65 lines
1.9 KiB
TypeScript
// Copyright (C) 2012-2026 Zammad Foundation, https://zammad-foundation.org/
|
|
|
|
import { storeToRefs } from 'pinia'
|
|
import { computed, ref } from 'vue'
|
|
|
|
import {
|
|
NotificationTypes,
|
|
useNotifications,
|
|
} from '#shared/components/CommonNotifications/index.ts'
|
|
import { useUserCurrentLocaleMutation } from '#shared/entities/user/current/graphql/mutations/userCurrentLocale.api.ts'
|
|
import { useLocaleStore } from '#shared/stores/locale.ts'
|
|
|
|
import MutationHandler from '../server/apollo/handler/MutationHandler.ts'
|
|
|
|
const ZAMMAD_TRANSLATION_LINK = 'https://translations.zammad.org/'
|
|
|
|
export const useLocaleUpdate = () => {
|
|
const isSavingLocale = ref(false)
|
|
|
|
const localeMutation = new MutationHandler(useUserCurrentLocaleMutation({}), {
|
|
errorNotificationMessage: __('The language could not be updated.'),
|
|
})
|
|
|
|
const { notify } = useNotifications()
|
|
|
|
const localeStore = useLocaleStore()
|
|
const { setLocale } = localeStore
|
|
const { localeData, locales } = storeToRefs(localeStore)
|
|
|
|
const modelCurrentLocale = computed({
|
|
get: () => localeData.value?.locale ?? 'en-us',
|
|
set: (locale) => {
|
|
if (!locale || localeData.value?.locale === locale) return
|
|
isSavingLocale.value = true
|
|
Promise.all([setLocale(locale), localeMutation.send({ locale })])
|
|
.then(() => {
|
|
notify({
|
|
id: 'locale-update',
|
|
message: __('Profile language updated successfully.'),
|
|
type: NotificationTypes.Success,
|
|
})
|
|
})
|
|
.finally(() => {
|
|
isSavingLocale.value = false
|
|
})
|
|
},
|
|
})
|
|
|
|
const localeOptions = computed(() => {
|
|
return (
|
|
locales?.value?.map((locale) => {
|
|
return { label: locale.name, value: locale.locale }
|
|
}) || []
|
|
)
|
|
})
|
|
|
|
return {
|
|
translation: {
|
|
link: ZAMMAD_TRANSLATION_LINK,
|
|
},
|
|
isSavingLocale,
|
|
modelCurrentLocale,
|
|
localeOptions,
|
|
}
|
|
}
|