Skip to content

i18n gettext.js wrapper for Ember controllers and Handlebars templates

Notifications You must be signed in to change notification settings

nicolaschenet/ember-gettext

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ember-gettext

Build Status

i18n gettext.js wrapper for Ember controllers and Handlebars templates

Installation

1- Retrieve ember-gettext:

bower install ember-gettext --save

2- Include it in your project:

<script src="./bower_components/gettext.js/dist/gettext.js"></script>
<script src="./bower_components/ember-gettext/lib/ember-gettext.js"></script>

or in your Brocfile if you use ember-cli.

3- Load your messages

Wherever it suits in your project, load your messages:

Ember.I18n.loadJSON({...});

Your JSON format must be the gettext.js required one

4- Set the current locale

You could do it from your dom

<html lang="fr">

or from javascript

Ember.I18n.setLocate('fr');

Usage

In your controllers

  • Singular forms:
Ember.I18n._t("I like apples.");
Ember.I18n._t("I like {{ fruit }}.", {fruit: "bananas"});
  • Plural forms:

You must use a count parameter to indicate gettext which plural form to choose

Ember.I18n._n("There is {{ count }} apple", "There are {{ count }} apples", { count: 42 });
Ember.I18n._n("There is {{ count }} apple in the {{ where }}", "There are {{ count }} apples in the {{ where }}", { count: 12, where: "fridge" });

In your templates

  • Singular forms:
<p>{{_t "I like apples." }}</p>
<p>{{_t "I like {{ fruit }}." fruit="bananas" }}</p>
  • Plural forms:

You must use a count parameter to indicate gettext which plural form to choose

<p>{{_n "There is {{ count }} apple" "There are {{ count }} apples" count=42 }}</p>
<p>{{_n "There is {{ count }} apple in the {{ where }}" "There are {{ count }} apples in the {{ where }}" count=12 where="fridge" }}</p>
  • Binded values

You could of course use binded values to be interpreted and automatically re-rendered

<p>{{_t "Hello {{ firstname }} firstnameBinding="user.firstname" }}</p>
<p>{{_n "There is {{ count }} apple in the {{ where }}" "There are {{ count }} apples in the {{ where }}" countBinding="fruits.count" whereBinding="fruits.container" }}</p>

License

MIT

About

i18n gettext.js wrapper for Ember controllers and Handlebars templates

Resources

Stars

Watchers

Forks

Packages

No packages published