{"action":"created","issue":{"url":"https://api.github.com/repos/node-modules/parameter/issues/12","labels_url":"https://api.github.com/repos/node-modules/parameter/issues/12/labels{/name}","comments_url":"https://api.github.com/repos/node-modules/parameter/issues/12/comments","events_url":"https://api.github.com/repos/node-modules/parameter/issues/12/events","html_url":"https://github.com/node-modules/parameter/pull/12","id":107158081,"number":12,"title":"从 Validation 结果的 message 里面去掉 field 的部分","user":{"login":"huacnlee","id":5518,"avatar_url":"https://avatars.githubusercontent.com/u/5518?v=3","gravatar_id":"","url":"https://api.github.com/users/huacnlee","html_url":"https://github.com/huacnlee","followers_url":"https://api.github.com/users/huacnlee/followers","following_url":"https://api.github.com/users/huacnlee/following{/other_user}","gists_url":"https://api.github.com/users/huacnlee/gists{/gist_id}","starred_url":"https://api.github.com/users/huacnlee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/huacnlee/subscriptions","organizations_url":"https://api.github.com/users/huacnlee/orgs","repos_url":"https://api.github.com/users/huacnlee/repos","events_url":"https://api.github.com/users/huacnlee/events{/privacy}","received_events_url":"https://api.github.com/users/huacnlee/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/node-modules/parameter/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":{"login":"hotoo","id":143572,"avatar_url":"https://avatars.githubusercontent.com/u/143572?v=3","gravatar_id":"","url":"https://api.github.com/users/hotoo","html_url":"https://github.com/hotoo","followers_url":"https://api.github.com/users/hotoo/followers","following_url":"https://api.github.com/users/hotoo/following{/other_user}","gists_url":"https://api.github.com/users/hotoo/gists{/gist_id}","starred_url":"https://api.github.com/users/hotoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hotoo/subscriptions","organizations_url":"https://api.github.com/users/hotoo/orgs","repos_url":"https://api.github.com/users/hotoo/repos","events_url":"https://api.github.com/users/hotoo/events{/privacy}","received_events_url":"https://api.github.com/users/hotoo/received_events","type":"User","site_admin":false},"milestone":null,"comments":14,"created_at":"2015-09-18T08:44:13Z","updated_at":"2015-09-21T03:27:59Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/node-modules/parameter/pulls/12","html_url":"https://github.com/node-modules/parameter/pull/12","diff_url":"https://github.com/node-modules/parameter/pull/12.diff","patch_url":"https://github.com/node-modules/parameter/pull/12.patch"},"body":"原因：\r\n\r\n如果你尝试 I18n 处理 Validation message 的时候，你会发现，你必须也只能写成这样：\r\n\r\n> 因为我们覆盖 validation.translate 函数的时候，无法知道传过来的参数是什么类型，只能一起处理了\r\n\r\n  ```yml\r\nerrors:\r\n  \"%s required\": '%s 是必填项\"\r\n  \"name\": \"姓名\"\r\n  \"age\": \"年龄\"\r\n```\r\n\r\n比如是这样的实现：\r\n\r\n```js\r\nvalidate.translate = function() {\r\n  return I18n.t('errors.' + args[0]);\r\n};\r\n```\r\n\r\n但实际的项目设计中，我们一般会按类别才分 I18n 信息，类似这样：\r\n\r\n```yml\r\nmodel:\r\n  user:\r\n    name: \"姓名\"\r\n    age: \"年龄\"\r\n  category:\r\n    name: \"分类名称\"\r\n  errors:\r\n     \"required\": \"是必填项\"\r\n```\r\n\r\n```js\r\nvalidate.translate = function() {\r\n  return I18n.t('model.errors.' + args[0]);\r\n};\r\n```\r\n\r\n而缺少的 field 信息，可以另外处理，做拼接在显示在界面上。"},"comment":{"url":"https://api.github.com/repos/node-modules/parameter/issues/comments/141867452","html_url":"https://github.com/node-modules/parameter/pull/12#issuecomment-141867452","issue_url":"https://api.github.com/repos/node-modules/parameter/issues/12","id":141867452,"user":{"login":"huacnlee","id":5518,"avatar_url":"https://avatars.githubusercontent.com/u/5518?v=3","gravatar_id":"","url":"https://api.github.com/users/huacnlee","html_url":"https://github.com/huacnlee","followers_url":"https://api.github.com/users/huacnlee/followers","following_url":"https://api.github.com/users/huacnlee/following{/other_user}","gists_url":"https://api.github.com/users/huacnlee/gists{/gist_id}","starred_url":"https://api.github.com/users/huacnlee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/huacnlee/subscriptions","organizations_url":"https://api.github.com/users/huacnlee/orgs","repos_url":"https://api.github.com/users/huacnlee/repos","events_url":"https://api.github.com/users/huacnlee/events{/privacy}","received_events_url":"https://api.github.com/users/huacnlee/received_events","type":"User","site_admin":false},"created_at":"2015-09-21T03:27:59Z","updated_at":"2015-09-21T03:27:59Z","body":"name limit 10\r\npassword limit 30\r\nnick limit 20\r\n\r\n然后我就得写 3 段一模一样的话\r\n\r\n```\r\nlength should smaller than 10\r\nlength should smaller than 20\r\nlength should smaller than 30\r\n```\r\n\r\n本来只需要写一遍的:\r\n\r\n```js\r\nform: {\r\n  errors: {\r\n    'missing_field': '缺少必要字段',\r\n    'invalid': '无效格式',\r\n    'required': '要求是必填字段',\r\n    'should be an integer': '要求是数字',\r\n    'should be an email': '要求是 Email 格式',\r\n    'should not be empty': '不能为空',\r\n    'should be a string': '要求是字符串',\r\n    'should match %s': '要求匹配格式 %s',\r\n    'should equal to %s': '要求等于 %s',\r\n    'should be a url': '要求是一个 URL 地址',\r\n    'should be an object': '要求是一个对象',\r\n    'should be an array': '要求是一个数组',\r\n    'should be a boolean': '要求是 true 或 false',\r\n    'should be one of %s': '要求是 %s 其中的一个',\r\n    'length should smaller than %s': '长度要求小于 %s',\r\n    'length should bigger than %s': '长度要求大于 %s'\r\n  }\r\n}\r\n```"}}