Skip to content

cibernox/ember-simple-i18n

Repository files navigation

Ember Simple I18n

Warning: This is still a work in progress!

If you need something that can be used today, check out ember-i18n by James Alexander Rosen.

This library is intended to be minimal. It only provides a helper method for translating strings.

It uses the I18n-js library, which uses the same syntax and conventions that Rails does, but unlike i18n-js, this project is not intended to be used as a gem.

Usage

Pass the key of the translation.

If it is quoted, it will look that property up in the translations object and insert the current value of the property.

{{t "title"}} <!--- "My title" --->

If a key is unquoted, it will be understood as a bound property, and evaluated in the current context, updating the value if it changes.

{{t titleKey}} <!--- "Translation of the value held in 'titleKey'" --->

Interpolations are passed using the options object.

{{t "salute" name="John"}} <!--- "Hi John" --->

Namespaced Translations

There are three ways in which namespaced translations can be expressed:

A) dot notation

{{t "posts.title"}} <!--- "All your posts" --->

B) passing a list of values

{{t "posts" "title"}} <!--- "All your posts" --->

C) passing a key and a scope

{{t "posts" scope="title"}} <!--- "All your posts" --->

In all cases, unquoted values passed to the list are bound to the current context.

Values passed using the options object, such as the scope or the interpolations, are not bound, even if they are unquoted. They are fetched from the current context.

If you want to bind the values in the options, append the suffix 'Binding' to the property name:

{{t "salute" scope=informal nameBinding=user}} <!--- "Hi John!" --->

In this last example, "salute" is just a string, informal is looked up in the current context but is not bound, and nameBinding is bound to the current context.

About

Simple i18n library for ember.js apps

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages