-
I was wondering if Localizing Field Names only works with <template>
<form @submit.prevent="save" novalidate>
<v-text-field
name="forename"
:label="$t('forename')"
v-model="forename.value.value"
:error-messages="forename.errorMessage.value"
/>
<v-btn
color="primary"
type="submit"
:loading="isSubmitting"
>{{ $t("save") }}</v-btn>
</form>
</template>
<script setup>
import { useForm, useField } from "vee-validate";
import { useI18n } from "vue-i18n";
const { t } = useI18n();
const { handleSubmit, isSubmitting } = useForm();
const forename = useField("forename", "required");
const save = handleSubmit(() => {
console.log("do save");
});
</script> and the vee-validate plugin setup import { defineRule } from "vee-validate";
import { configure } from "vee-validate";
import { localize, setLocale } from "@vee-validate/i18n";
import en from "@vee-validate/i18n/dist/locale/en.json";
import de from "@vee-validate/i18n/dist/locale/de.json";
import { required } from "@vee-validate/rules";
export function defineValidationRules() {
defineRule("required", required);
configure({
generateMessage: localize({
en: {
...en,
names: {forename: "OVERRIDE IT"}
},
de: {
...de,
},
}),
});
setLocale('en');
}
|
Beta Was this translation helpful? Give feedback.
Answered by
logaretm
Feb 18, 2023
Replies: 1 comment 3 replies
-
You can pass the label in the field options in the third argument of const { t } = useI18n();
const forename = useField("forename", "required", { label: t('forename') });
|
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
1Luc1
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can pass the label in the field options in the third argument of
useField
.<Field />
is just usinguseField
under the hood with some nice behavioral addons, so most options still apply touseField
.