Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: More in line with Chinese habits #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 44 additions & 45 deletions src/locales/zh.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* language. Feel free to add additional helper methods to libs/formats if it
* assists in creating good validation messages for your locale.
*/
import { sentence as s } from '../libs/formats'

/**
* This is the ISO 639-1 and (optionally) ISO 639-2 language "tag".
Expand Down Expand Up @@ -35,70 +34,70 @@ const localizedValidationMessages = {
/**
* Valid accepted value.
*/
accepted: function ({ name }) {
return `请同意${name}。`
accepted: function ({ vm }) {
return `请同意${vm.context.label}。`
},

/**
* The date is not after.
*/
after: function ({ name, args }) {
after: function ({ vm, args }) {
if (Array.isArray(args) && args.length) {
return `${s(name)} 必须在 ${args[0]} 之后。`
return `${vm.context.label} 必须在 ${args[0]} 之后。`
}
return `${s(name)} 必须是以后的日期。`
return `${vm.context.label} 必须是以后的日期。`
},

/**
* The value is not a letter.
*/
alpha: function ({ name }) {
return `${s(name)} 只能包含字母。`
alpha: function ({ vm }) {
return `${vm.context.label} 只能包含字母。`
},

/**
* Rule: checks if the value is alpha numeric
*/
alphanumeric: function ({ name }) {
return `${s(name)} 只能包含字母或数字。`
alphanumeric: function ({ vm }) {
return `${vm.context.label} 只能包含字母或数字。`
},

/**
* The date is not before.
*/
before: function ({ name, args }) {
before: function ({ vm, args }) {
if (Array.isArray(args) && args.length) {
return `${s(name)} 必须在 ${args[0]} 之前`
return `${vm.context.label} 必须在 ${args[0]} 之前`
}
return `${s(name)} 必须是以前的日期。`
return `${vm.context.label} 必须是以前的日期。`
},

/**
* The value is not between two numbers or lengths
*/
between: function ({ name, value, args }) {
between: function ({ vm, value, args }) {
const force = Array.isArray(args) && args[2] ? args[2] : false
if ((!isNaN(value) && force !== 'length') || force === 'value') {
return `${s(name)} 必须在 ${args[0]} 和 ${args[1]} 之间。`
return `${vm.context.label} 必须在 ${args[0]} 和 ${args[1]} 之间。`
}
return `${s(name)} 必须在 ${args[0]} 和 ${args[1]} 字符长度之间。`
return `${vm.context.label} 必须在 ${args[0]} 和 ${args[1]} 字符长度之间。`
},

/**
* The confirmation field does not match
*/
confirm: function ({ name, args }) {
return `${s(name)} 不匹配。`
confirm: function ({ vm }) {
return `${vm.context.label} 不匹配。`
},

/**
* Is not a valid date.
*/
date: function ({ name, args }) {
date: function ({ vm, args }) {
if (Array.isArray(args) && args.length) {
return `${s(name)} 日期无效,请使用 ${args[0]} 格式。`
return `${vm.context.label} 日期无效,请使用 ${args[0]} 格式。`
}
return `${s(name)} 日期无效。`
return `${vm.context.label} 日期无效。`
},

/**
Expand All @@ -111,7 +110,7 @@ const localizedValidationMessages = {
/**
* Is not a valid email address.
*/
email: function ({ name, value }) {
email: function ({ value }) {
if (!value) {
return '请输入有效的电子邮箱地址。'
}
Expand All @@ -121,7 +120,7 @@ const localizedValidationMessages = {
/**
* Ends with specified value
*/
endsWith: function ({ name, value }) {
endsWith: function ({ value }) {
if (!value) {
return `无效的结尾值。`
}
Expand All @@ -131,80 +130,80 @@ const localizedValidationMessages = {
/**
* Value is an allowed value.
*/
in: function ({ name, value }) {
in: function ({ vm, value }) {
if (typeof value === 'string' && value) {
return `“${s(value)}” 是 ${name} 不允许的值。`
return `“${value}” 是 ${vm.context.label} 不允许的值。`
}
return `${name} 包含不允许的值。`
return `${vm.context.label} 包含不允许的值。`
},

/**
* Value is not a match.
*/
matches: function ({ name }) {
return `${s(name)} 包含不允许的值。`
matches: function ({ vm }) {
return `${vm.context.label} 包含不允许的值。`
},

/**
* The maximum value allowed.
*/
max: function ({ name, value, args }) {
max: function ({ vm, value, args }) {
if (Array.isArray(value)) {
return `您最多可有 ${args[0]} 个 ${name}。`
return `您最多可有 ${args[0]} 个 ${vm.context.label}。`
}
const force = Array.isArray(args) && args[1] ? args[1] : false
if ((!isNaN(value) && force !== 'length') || force === 'value') {
return `${s(name)} 必须小于或等于 ${args[0]}.`
return `${vm.context.label} 必须小于或等于 ${args[0]}.`
}
return `${s(name)} 必须小于或等于 ${args[0]} 字符长度.`
return `${vm.context.label} 必须小于或等于 ${args[0]} 字符长度.`
},

/**
* The (field-level) error message for mime errors.
*/
mime: function ({ name, args }) {
return `${s(name)} 格式必须是: ${args[0] || '无允许文件格式'}`
mime: function ({ vm, args }) {
return `${vm.context.label} 格式必须是: ${args[0] || '无允许文件格式'}`
},

/**
* The maximum value allowed.
*/
min: function ({ name, value, args }) {
min: function ({ vm, value, args }) {
if (Array.isArray(value)) {
return `您需要最少 ${args[0]} 个 ${name}.`
return `您需要最少 ${args[0]} 个 ${vm.context.label}.`
}
const force = Array.isArray(args) && args[1] ? args[1] : false
if ((!isNaN(value) && force !== 'length') || force === 'value') {
return `${s(name)} 最少是 ${args[0]}.`
return `${vm.context.label} 最少是 ${args[0]}.`
}
return `${s(name)} 最少 ${args[0]} 字符长度。`
return `${vm.context.label} 最少 ${args[0]} 字符长度。`
},

/**
* The field is not an allowed value
*/
not: function ({ name, value }) {
return `“${value}” 是 ${name} 不被允许的值。`
not: function ({ vm, value }) {
return `“${value}” 是 ${vm.context.label} 不被允许的值。`
},

/**
* The field is not a number
*/
number: function ({ name }) {
return `${s(name)} 必须是数字。`
number: function ({ vm }) {
return `${vm.context.label} 必须是数字。`
},

/**
* Required field.
*/
required: function ({ name }) {
return `${s(name)} 是必填项。`
required: function ({ vm }) {
return `${vm.context.label} 是必填项。`
},

/**
* Starts with specified value
*/
startsWith: function ({ name, value }) {
startsWith: function ({ value }) {
if (!value) {
return `无效的起始值`
}
Expand Down