ember-web-app icon indicating copy to clipboard operation
ember-web-app copied to clipboard

Support Localization

Open jonpitch opened this issue 7 years ago • 2 comments

I have an application that requires localization. I'd like to be able to deliver a manifest that changes based on user locale. There's a minimal amount of content in the manifest itself that would require translation (name, short_name, description, maybe icons), but what would be nice is if that content could live in my existing translation workflow and I could populate the manifest at build time.

I think an approach could be something like:

  • detect supported languages
  • generate a manifest for each supported locale
    • use the addon to lookup a translation, something like const name = get(this, 'intl').t('ember-web-app.name');
    • update the manifest values with translations
  • user receives the manifest for their specific locale

What I'm not sure of, if this is something this addon should have as a feature or if there's another addon here that extends this one? I'm open to suggestions or ideas. I also have some cycles coming up that I could work on one or the other.

jonpitch avatar Apr 24 '18 15:04 jonpitch

@jonpitch this is a great idea! I think this would be a really great feature to have. If you want to start working on it, that would be awesome, let me know if I can be of any help.

san650 avatar Apr 25 '18 15:04 san650

Thanks @san650, I spent a little time gathering my thoughts and I have an alternate approach that I wouldn't mind your input on.

ember-i18n and ember-intl are pretty flexible in that you can use various translation file formats, specify different locations within the tree for content, that seems like overkill for ember-web-app. Instead, what I'd like to propose is perhaps ember-web-app knows about a build config, something like:

'ember-web-app': {
  enabled: true,
  locales: [{
    code: 'en-us',
    name: 'English name',
    short_name: 'English short name'
  }, {
    code: 'it-it',
    name: 'Italian Name',
    short_name: 'Italian short name'
  }]
}

ember-web-app would just be responsible for generating a set of manifest files. I think this is the most flexible, so the consumer could add something like this to their ember-cli-build.js:

const fs = require('fs');
const enUsManifestTranslations = JSON.parse(fs.readFileSync('path/to/en-us/translations.json'));

var app = new EmberApp(defaults, {
  'ember-web-app': {
    locales: [{
      locale: 'en-us',
      name: enUsManifestTranslations.name
    }]
  }
}
...

The only thing I'm not sure on is the consumer might need the ability to swap out these files in the <head>, using something like ember-cli-ifa or ember-cli-head. As the consuming app, I don't want to have to know about all the meta tags ember-web-app knows about, but I don't want ember-web-app to have to know about how I want to localize my application. What do you think?

jonpitch avatar Apr 26 '18 19:04 jonpitch