ember-cli-foreigner
ember-cli-foreigner
is a set of helpers and mixins to interface with the foreigner.js library in Ember.
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
Translating attributes of an Ember helper
Say you want to translate the placeholder
attribute on the input
helper.
Since 1.0.0
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:
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
ember server
- Visit your app at http://localhost:4200.
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.