This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

ember-cli-foreigner

1.1.0 • Public • Published

ember-cli-foreigner

ember-cli-foreigner is a set of helpers and mixins to interface with the foreigner.js library in Ember.

Node package version Travis-CI status Code Climate

Setup

npm install ember-cli-foreigner --save-dev
ember g ember-cli-foreigner

Adding a locale

ember g locale <locale>

In your app’s config/environment.js, set the default locale:

var ENV = {
  APP: {
    defaultLocale: '<locale>'
  }
};

Changing the locales folder

You can change the folder where the translations are put by setting the locale prefix:

var ENV = {
  modulePrefix: 'your-app',
  localePrefix: 'your-app/localizations'
};

The path is relative to modulePrefix and is set to locales by default.

Usage

To see how to write your locale file, see the foreigner.js README

Translating text content

{{!-- Simple translation --}}
<h1>{{t 'hello_world'}}</h1>

{{!-- Bound interpolated values --}}
<p>{{t 'you_have_x_message' messageCount=messages.length}}</p>

Translating attributes of an Ember helper

Say you want to translate the placeholder attribute on the input helper.

Since 1.0.0

{{input placeholder=(t 'form.input_placeholder')}}

Versions prior to 1.0.0

First, you have to include the translateable-attributes mixin on the Ember.TextField class:

import TranslateableAttributes from 'ember-cli-foreigner/translateable-attributes';

Ember.TextField.reopen(TranslateableAttributes);

And then you can define your placeholder like this:

{{input placeholderTranslation='form.input_placeholder'}}

Changing the locale

The locale property is set on your app’s instance, so to change it you could do something like this in your routes/application.js:

export default Ember.Route.extend({
  actions: {
    changeLocale: function(locale) {
      var application = this.container.lookup('application:main');
      application.set('locale', locale);

      // Transitioning to any other route from here should render
      // your templates with the new locale’s translations
    }
  }
});

Contributing

Installation

  • git clone this repository
  • npm install
  • bower install

Running

Running Tests

  • ember test
  • ember test --server

Building

  • ember build

For more information on using ember-cli, visit http://www.ember-cli.com/.

License

ember-cli-foreigner is © 2014-2015 Mirego and may be freely distributed under the New BSD license. See the LICENSE.md file.

About Mirego

Mirego is a team of passionate people who believe that work is a place where you can innovate and have fun. We're a team of talented people who imagine and build beautiful Web and mobile applications. We come together to share ideas and change the world.

We also love open-source software and we try to give back to the community as much as we can.

Package Sidebar

Install

npm i ember-cli-foreigner

Weekly Downloads

2

Version

1.1.0

License

BSD 3-Clause

Last publish

Collaborators

  • charles_demers