Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Commit

Permalink
improve docs, CLDR is optional
Browse files Browse the repository at this point in the history
If CLDR.pluralForm is not defined, Em.I18n will not inflect based on
count.
  • Loading branch information
James A. Rosen committed Feb 14, 2012
1 parent f5b29cf commit 656415d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ Internationalization for Ember

### Requirements

The [CLDR.js pluralization library](https://github.com/jamesarosen/CLDR.js).
Set `Em.I18n.translations` to an object containing your translation
information. If you want to support inflection based on `count`, you will
also need to include the
[CLDR.js pluralization library](https://github.com/jamesarosen/CLDR.js)
and set `CLDR.defaultLocale` to the current locale code (e.g. "de").

### Examples

Given

I18n.translations = {
Em.I18n.translations = {
'user.edit.title': 'Edit User',
'user.followers.title.one': 'One Follower',
'user.followers.title.other': 'All {{count}} Followers',
Expand Down
4 changes: 2 additions & 2 deletions lib/i18n.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ getPath = Ember.Handlebars.getPath || Ember.getPath

pluralForm = CLDR.pluralForm if CLDR?

ember_assert("Could not find CLDR.pluralForm. You can find it at https://github.com/jamesarosen/CLDR.js", pluralForm?)
Ember.Logger.warn "CLDR.pluralForm not found. Em.I18n will not support count-based inflection." unless pluralForm?

findTemplate = (key, setOnMissing) ->
ember_assert("You must provide a translation key string, not %@".fmt(key), typeof key is 'string')
Expand All @@ -23,7 +23,7 @@ I18n = {
translations: {}

template: (key, count) ->
if count?
if count? && pluralForm?
suffix = pluralForm count
interpolatedKey = "%@.%@".fmt key, suffix
result = findTemplate(interpolatedKey, false)
Expand Down

0 comments on commit 656415d

Please sign in to comment.