{"id":15535122,"url":"https://github.com/jasonmit/ember-i18n-cp-validations","last_synced_at":"2025-04-23T13:43:21.484Z","repository":{"id":57223883,"uuid":"43113753","full_name":"jasonmit/ember-i18n-cp-validations","owner":"jasonmit","description":"ember-i18n support for ember-cp-validations","archived":false,"fork":false,"pushed_at":"2018-03-13T18:07:20.000Z","size":170,"stargazers_count":21,"open_issues_count":2,"forks_count":16,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-13T07:17:14.356Z","etag":null,"topics":["ember","ember-addon","ember-cp-validations","ember-i18n","ember-intl","i18n","internationalization"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jasonmit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-09-25T06:33:56.000Z","updated_at":"2024-05-30T02:53:13.000Z","dependencies_parsed_at":"2022-08-30T02:10:21.815Z","dependency_job_id":null,"html_url":"https://github.com/jasonmit/ember-i18n-cp-validations","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasonmit%2Fember-i18n-cp-validations","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasonmit%2Fember-i18n-cp-validations/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasonmit%2Fember-i18n-cp-validations/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasonmit%2Fember-i18n-cp-validations/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jasonmit","download_url":"https://codeload.github.com/jasonmit/ember-i18n-cp-validations/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250441364,"owners_count":21431162,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ember","ember-addon","ember-cp-validations","ember-i18n","ember-intl","i18n","internationalization"],"created_at":"2024-10-02T11:44:34.158Z","updated_at":"2025-04-23T13:43:21.466Z","avatar_url":"https://github.com/jasonmit.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ember-i18n-cp-validations\n\n[![npm Version][npm-badge]][npm]\n[![Build Status][travis-badge]][travis]\n[![Ember Observer Score](http://emberobserver.com/badges/ember-i18n-cp-validations.svg)](http://emberobserver.com/addons/ember-i18n-cp-validations)\n[![Ember badge][ember-badge]][embadge]\n\nAdds support for ember-i18n in ember-cp-validations\n\nUsing ember-intl?  See: [jasonmit/ember-intl-cp-validations](https://github.com/jasonmit/ember-intl-cp-validations)\n\n## Installation\n\n* `ember install ember-i18n-cp-validations`\n\n## Breaking changes between 2.x and 3.x for ember-i18n-cp-validations\n\n1. If your application implements it's own `app/validators/messages.js` you'll want to change the import reference from: `ember-cp-validations/validators/messages` to `ember-i18n-cp-validations/validators/message`\n2. Instantiating the initializer is no longer necessary for testing\n\n## Configuring\n\nImplement the following validation messages across your translations:\n\n```js\n// app/locales/en/translations.js\n\nexport default {\n  errors: {\n    description: \"This field\",\n    inclusion: \"{{description}} is not included in the list\",\n    exclusion: \"{{description}} is reserved\",\n    invalid: \"{{description}} is invalid\",\n    confirmation: \"{{description}} doesn't match {{on}}\",\n    accepted: \"{{description}} must be accepted\",\n    empty: \"{{description}} can't be empty\",\n    blank: \"{{description}} can't be blank\",\n    present: \"{{description}} must be blank\",\n    collection: \"{{description}} must be a collection\",\n    singular: \"{{description}} can't be a collection\",\n    tooLong: \"{{description}} is too long (maximum is {{max}} characters)\",\n    tooShort: \"{{description}} is too short (minimum is {{min}} characters)\",\n    before: \"{{description}} must be before {{before}}\",\n    after: \"{{description}} must be after {{after}}\",\n    wrongDateFormat: \"{{description}} must be in the format of {{format}}\",\n    wrongLength: \"{{description}} is the wrong length (should be {{is}} characters)\",\n    notANumber: \"{{description}} must be a number\",\n    notAnInteger: \"{{description}} must be an integer\",\n    greaterThan: \"{{description}} must be greater than {{gt}}\",\n    greaterThanOrEqualTo: \"{{description}} must be greater than or equal to {{gte}}\",\n    equalTo: \"{{description}} must be equal to {{is}}\",\n    lessThan: \"{{description}} must be less than {{lt}}\",\n    lessThanOrEqualTo: \"{{description}} must be less than or equal to {{lte}}\",\n    otherThan: \"{{description}} must be other than {{value}}\",\n    odd: \"{{description}} must be odd\",\n    even: \"{{description}} must be even\",\n    positive: \"{{description}} must be positive\",\n    date: \"{{description}} must be a valid date\",\n    onOrAfter: '{{description}} must be on or after {{onOrAfter}}',\n    onOrBefore: '{{description}} must be on or before {{onOrBefore}}',\n    email: \"{{description}} must be a valid email address\",\n    phone: \"{{description}} must be a valid phone number\",\n    url: \"{{description}} must be a valid url\"\n  }\n};\n```\n\n### Customizing the prefix\n\nTo change the errors prefix key from `errors` to any other key, such as `validationErrors` you simply add the following to `app/validators/messages.js`.  Now just amend your translation files to be nested under the `validationErrors` object instead of `errors`.\n\n```js\n// app/validators/messages.js\n\nimport ValidatorsMessages from 'ember-i18n-cp-validations/validators/messages';\n\nexport default ValidatorsMessages.extend({\n  prefix: 'validationErrors'\n});\n```\n\n### Translating Validator description\n\nTo translate the description of a Validator specify the `descriptionKey` to match a key in your translations.\n\n```js\n// app/models/user.js\n\nimport { validator, buildValidations } from 'ember-cp-validations';\n\nconst Validations = buildValidations({\n  username: validator('presence', {\n    presence: true,\n    descriptionKey: 'key.for.username'\n  })\n});\n```\n\n```js\n// app/locales/en/translations.js\n\nexport default {\n  key: {\n    for: {\n      username: 'Username'\n    }\n  }\n}\n\n// app/locales/sv/translations.js\n\nexport default {\n  key: {\n    for: {\n      username: 'Användarnamn'\n    }\n  }\n}\n```\n\n### Overriding default translation key\n\nBy default, translations will be resolved to `validatorPrefix.validatorType`.  If you need to override this functionality entirely and specify your own message key, you can do so with `messageKey` on the validator object.\n\n```js\n// app/models/user.js\n\nimport { validator, buildValidations } from 'ember-cp-validations';\n\nconst Validations = buildValidations({\n  username: validator('presence', {\n    presence: true,\n    messageKey: 'username.missing'\n  })\n});\n```\n\n### Passing attributes into translation\n\nPassing attributes into your translation is supported.\n\nSimilar to passing attributes via through to the `t` method: i.e., `i18n.t('errors.blank', { placeholder: i18n.t('age') })` you can also do this with your validator definition.\n\n```js\nvalidator('presence', {\n  presence: true,\n  placeholder: Ember.computed('model.age', 'model.i18n.locale', {\n    // inject i18n into your model, optional..\n    return get(model, 'i18n').t('age');\n  })\n})\n```\n\n```js\nerrors: {\n  blank: '{{placeholder}} cannot be blank!'\n}\n```\n\n### Disabling Missing Translation Warnings\n\nTo suppress console warnings for missing translations, you can do so by setting `i18n.suppressWarnings` in `config/environment`;\n\n```js\n// config/environment.js\nmodule.exports = function(environment) {\n  const ENV = {};\n\n  if (environment === 'test') {\n    ENV.i18n = ENV.i18n || {};\n    ENV.i18n.suppressWarnings = true;\n  }\n\n  return ENV;\n}\n```\n\n## Questions?\n\nPlease open a GitHub an [issue](https://www.github.com/jasonmit/ember-i18n-cp-validations/issues).\n\n## Running\n\n* `ember server`\n* Visit your app at http://localhost:4200.\n\n## Running Tests\n\n* `ember test`\n* `ember test --server`\n\n## Building\n\n* `ember build`\n\nFor more information on using ember-cli, visit [http://www.ember-cli.com/](http://www.ember-cli.com/).\n\n[npm]: https://www.npmjs.org/package/ember-i18n-cp-validations\n[npm-badge]: https://img.shields.io/npm/v/ember-i18n-cp-validations.svg?style=flat-square\n[travis]: https://travis-ci.org/jasonmit/ember-i18n-cp-validations\n[travis-badge]: https://img.shields.io/travis/jasonmit/ember-i18n-cp-validations/master.svg?style=flat-square\n[embadge]: http://embadge.io/\n[ember-badge]: http://embadge.io/v1/badge.svg?start=1.13.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjasonmit%2Fember-i18n-cp-validations","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjasonmit%2Fember-i18n-cp-validations","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjasonmit%2Fember-i18n-cp-validations/lists"}