-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(frontend): Add all translate options for yup schema validation, …
…improve imports for i18n
- Loading branch information
1 parent
adbf843
commit 8694668
Showing
6 changed files
with
157 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,4 +27,5 @@ i18n | |
loadPath: '/i18n-{{lng}}.json', | ||
}, | ||
}); | ||
|
||
export default i18n; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import * as yup from 'yup'; | ||
|
||
yup.setLocale({ | ||
mixed: { | ||
default: () => ({ key: 'common.fieldValidationError.default' }), | ||
required: () => ({ key: 'common.fieldValidationError.required' }), | ||
defined: () => ({ key: 'common.fieldValidationError.defined' }), | ||
notOneOf: ({ values }) => ({ key: 'common.fieldValidationError.notOneOf', values: { values } }), | ||
oneOf: ({ values }) => ({ key: 'common.fieldValidationError.oneOf', values: { values } }), | ||
}, | ||
array: { | ||
length: ({ length }) => ({ key: 'common.fieldValidationError.array.length', values: { length } }), | ||
max: ({ max }) => ({ key: 'common.fieldValidationError.array.max', values: { max } }), | ||
min: ({ min }) => ({ key: 'common.fieldValidationError.array.min', values: { min } }), | ||
}, | ||
boolean: { | ||
isValue: () => ({ key: 'common.fieldValidationError.boolean.isValue' }), | ||
}, | ||
date: { | ||
max: ({ max }) => ({ key: 'common.fieldValidationError.date.max', values: { max } }), | ||
min: ({ min }) => ({ key: 'common.fieldValidationError.date.min', values: { min } }), | ||
}, | ||
object: { | ||
noUnknown: () => ({ key: 'common.fieldValidationError.object.noUnknown' }), | ||
}, | ||
string: { | ||
email: () => ({ key: 'common.fieldValidationError.string.email' }), | ||
length: ({ length }) => ({ key: 'common.fieldValidationError.string.length', values: { length } }), | ||
max: ({ max }) => ({ key: 'common.fieldValidationError.string.max', values: { max } }), | ||
min: ({ min }) => ({ key: 'common.fieldValidationError.string.min', values: { min } }), | ||
lowercase: () => ({ key: 'common.fieldValidationError.string.lowercase' }), | ||
uppercase: () => ({ key: 'common.fieldValidationError.string.lowercase' }), | ||
matches: ({ regex }) => ({ key: 'common.fieldValidationError.string.matches', values: { regex } }), | ||
trim: () => ({ key: 'common.fieldValidationError.string.trim' }), | ||
uuid: () => ({ key: 'common.fieldValidationError.string.uuid' }), | ||
url: () => ({ key: 'common.fieldValidationError.string.url' }), | ||
}, | ||
number: { | ||
max: ({ max }) => ({ key: 'common.fieldValidationError.number.max', values: { max } }), | ||
min: ({ min }) => ({ key: 'common.fieldValidationError.number.min', values: { min } }), | ||
integer: () => ({ key: 'common.fieldValidationError.number.integer' }), | ||
positive: () => ({ key: 'common.fieldValidationError.number.positive' }), | ||
negative: () => ({ key: 'common.fieldValidationError.number.negative' }), | ||
lessThan: ({ less }) => ({ key: 'common.fieldValidationError.number.lessThan', values: { less } }), | ||
moreThan: ({ more }) => ({ key: 'common.fieldValidationError.number.moreThan', values: { more } }), | ||
}, | ||
}); | ||
|
||
// now use Yup schemas AFTER you defined your custom dictionary | ||
const schema = yup.object().shape({ | ||
name: yup.string().required(), | ||
name2: yup.string().required(), | ||
d: yup.bool().isTrue(), | ||
}); | ||
|
||
schema.validate({ name: 'jimmy', age: 11 }).catch((err) => { | ||
console.log(err); | ||
console.log(err.message.key); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters