ember-gettext
i18n gettext.js wrapper for Ember controllers and Handlebars templates
Installation
- Retrieve ember-gettext:
bower install ember-gettext --save
- Include it in your project:
or in your Brocfile if you use ember-cli.
- Load your messages
Wherever it suits in your project, load your messages:
EmberI18n;
Your JSON format must be the gettext.js required one
- Set the current locale
You could do it from your dom
or from javascript
i18n;
Usage
In your controllers
- Singular forms:
EmberI18n;EmberI18n;
- Plural forms:
You must use a count
parameter to indicate gettext which plural form to choose
EmberI18n;EmberI18n;
In your templates
- Singular forms:
{{_t "I like apples." }}{{_t "I like {{ fruit }}." fruit="bananas" }}
- Plural forms:
You must use a count
parameter to indicate gettext which plural form to choose
{{_n "There is {{ count }} apple" "There are {{ count }} apples" count=42 }}{{_n "There is {{ count }} apple in the {{ where }}" "There are {{ count }} apples in the {{ where }}" count=12 where="fridge" }}
- Binded values
You could of course use binded values to be interpreted and automatically re-rendered
{{_t "Hello {{ firstname }} firstnameBinding="user.firstname" }}{{_n "There is {{ count }} apple in the {{ where }}" "There are {{ count }} apples in the {{ where }}" countBinding="fruits.count" whereBinding="fruits.container" }}
License
MIT