ember-web-app
ember-web-app copied to clipboard
Support Localization
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
- assume a supported addon like ember-intl or ember-i18n
- 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
- use the addon to lookup a translation, something like
- 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 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.
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?