Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve docs #2

Open
shwoodard opened this issue Sep 16, 2014 · 1 comment
Open

Improve docs #2

shwoodard opened this issue Sep 16, 2014 · 1 comment

Comments

@shwoodard
Copy link

Given that I know the locale, e.g. "en", "fr ", how do instruct my ember cli app which compiled handlebars templates to use?

@tdegrunt
Copy link
Owner

Did you take a look here?
Aside from that I use the following initialiser:

export default {
  name: "locale",
  //after: "store",

  initialize: function(container, application) {
    application.register('locale:main', application.locale, { instantiate: false, singleton: true });

    container.typeInjection('controller', 'locale', 'locale:main');
    container.typeInjection('route', 'locale', 'locale:main');
    container.typeInjection('component', 'locale', 'locale:main');
    container.typeInjection('model', 'locale', 'locale:main');

    Ember.Component.reopen(Ember.I18n.TranslateableAttributes);
    Ember.View.reopen(Ember.I18n.TranslateableAttributes);
  }
};

My application.locale is as follows:

import Locale from './utils/locale';
Locale.set();

.
.
.

var App = Ember.Application.extend({
  locale: Locale
});

Then lastly my utils/locale is as follows:

import Translations from 'boxture/translations';
import moment from 'boxture/utils/shims/moment';
//import numeral from 'boxture/utils/shims/numeral';

export default {
  default: 'en',
  current: null,
  set: function(app,locale) {
    // TODO or userLocale from localStorage
    locale = window.navigator.userLanguage || window.navigator.language;
    if (locale) {
      locale = locale.split('-')[0];
    }

    locale = locale || this.default;
    this.current = locale;

    moment.lang(locale);
//    numeral.language(locale);
//    CLDR.defaultLanguage = locale;

    this.setTranslations(locale);
  },
  setTranslations: function(locale) {
    Em.I18n.translations = Translations[locale];
  }
};

Now what is left out is how to load the JSON files into a hash you can actually use in the setTranslations (here it is Translations) but that should just be a little ajax.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants