2023-08-07 17:29:04 +02:00
|
|
|
import { setLocale } from 'yup'
|
2023-11-25 20:14:12 +01:00
|
|
|
import { usePreferedLocale } from '@/composables/states'
|
2023-08-07 17:29:04 +02:00
|
|
|
|
2023-11-25 20:14:12 +01:00
|
|
|
export default defineNuxtPlugin({
|
|
|
|
setup() {
|
|
|
|
// Override default yup errors
|
|
|
|
// https://github.com/jquense/yup/blob/master/src/locale.ts
|
|
|
|
setLocale({
|
|
|
|
mixed: {
|
|
|
|
default: 'v.field_invalid',
|
|
|
|
required: 'v.field_required',
|
|
|
|
},
|
|
|
|
string: {
|
|
|
|
email: 'v.email',
|
|
|
|
min: ({ min }) => ({ key: 'v.string_too_short', values: { min } }),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
},
|
|
|
|
hooks: {
|
|
|
|
'app:created'() {
|
|
|
|
// Override browser locale if prefered language
|
|
|
|
const preferedLocale = usePreferedLocale()
|
|
|
|
if (preferedLocale.value !== 'auto') {
|
|
|
|
useNuxtApp().$i18n.locale.value = preferedLocale.value
|
|
|
|
}
|
2023-08-07 17:29:04 +02:00
|
|
|
},
|
2023-11-25 20:14:12 +01:00
|
|
|
},
|
2023-08-07 17:29:04 +02:00
|
|
|
})
|