Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cibernox/ember-i18n-errors
Extension to ember-i18n for translating error messages within the route hierarchy
https://github.com/cibernox/ember-i18n-errors
Last synced: 3 months ago
JSON representation
Extension to ember-i18n for translating error messages within the route hierarchy
- Host: GitHub
- URL: https://github.com/cibernox/ember-i18n-errors
- Owner: cibernox
- License: mit
- Created: 2015-07-14T09:45:48.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2021-08-25T05:40:51.000Z (over 3 years ago)
- Last Synced: 2024-10-02T09:41:13.495Z (4 months ago)
- Language: JavaScript
- Homepage:
- Size: 18.6 KB
- Stars: 2
- Watchers: 2
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Ember-i18n-errors
This addon leverages [ember-i18n](https://github.com/jamesarosen/ember-i18n) but for the specific
purpose of localize error messages.It adds to your app a handy helper `{{t-error error}}` for translating errors in the context of
the current route, but also takes advantage of Ember's route nesting to lookup translations in fallback on
parent routes.## Installation
This addon requires Ember.js 1.13+ and [ember-i18n](https://github.com/jamesarosen/ember-i18n) 4.1+
* `ember install ember-i18n-errors`
## Usage
This is better explained with an example.
Let's say we have a validation error with the mandatory shape (`{ attribute: 'email', message: 'invalid' }`) and
some nested routes with this structure:```
parent
└── child
└── grandchild
```If within the `grandchild.hbs` template we use the helper `{{t-error error}}` the helper will try to
find the most especific translation key for it based on the route hierarchy.It follows a set of conventions very similar to how [rails-i18n handles ActiveRecord errors](http://guides.rubyonrails.org/i18n.html#error-message-scopes).
The fallback chain for that error will be:
```
parent.child.grandchild.errors.email.invalid
parent.child.grandchild.errors.invalid
parent.child.errors.email.invalid
parent.child.errors.invalid
parent.errors.email.invalid
parent.errors.invalid
errors.email.invalid
errors.invalid
```If none of those keys is defined in your translations the missing translation message will point you to the most
specific translation: `Missing translation: parent.child.grandchild.errors.email.invalid`.