Addon Localization?

We’re currently building an Ember app within our Rails app, but moving toward an independent ember-cli environment. We’re trying to modularize our code with that intention so we’re building lots of small components that we can eventually turn into installable addons.

I’ve seen it’s possible to include CSS in an addon, but is it possible to include localization strings as part of an addon?

Have a look at the Brocfile.js contents and using app.import('/path/to/css') on the fly depending on locale, hopefully that helps.

Hey @jbuckner - did you end up making progress on this? I am embarking on the same journey. It seems like the addon’s locales contents need to be deep merged w/ the consuming app’s locales content and using one of the i18n libraries should ‘just work

Seems reasonable… did you go down this path by any chance?

Hello @jbuckner and @coladarci, Coincidentally I am also now contemplating various options for consuming intl resources from multiple addons into an app. Did either of you identify a manageable approach to this?

Hey @alienspaces - yes - I’m really happy w/ what we’ve put together. Essentially, there are two pieces to it:

  1. inside your addon, we’ve created an en.js file here: app/locales/ember-cli-your-addon-name/en.js. You place all your translations inside there.

  2. also inside the addon, we’ve created an initializer that looks like this:

import Ember from 'ember';
import translations from '../locales/ember-cli-your-addon-name/en';

export function initialize() {
  if(!Ember.I18n.translations){
    Ember.I18n.translations = {};
  }
  Ember.I18n.translations['ember-cli-your-addon-name'] = translations;
  Ember.I18n.locale = 'en';
};

export default {
  name: 'ember-cli-your-addon-name-localizations',
  initialize: initialize
};

Note, with this approach, your translations are available at t 'ember-cli-your-addon-name.foo'

This is obviously a little rough, but hoping it can get you on the right path.

Hello @coladarci, Thanks for the quick response! Your solution definitely provides food for thought.

Just an FYI that this approach doesn’t work w/ the newest (awesome) version of ember-cli-i18n. Our approach has changed a little bit because of this. We are basically, in our parent app, pulling in the translations from the addon and adding them to our own translations (instead of pushing them from the addon, which would be better).