-
Notifications
You must be signed in to change notification settings - Fork 184
RFC: support for translations in addons #255
Comments
@bcardarella I know you support i18n in ember-validations. Do you have any thoughts on this RFC? |
@jamesarosen I like the proposal, it seems like a really clean way for addons to define its own translations. It beats having to create an |
@jamesarosen - The proposal looks good to me. We can also work on making |
Has anyone given pod-vs-not-pod any thought? Do I have to care or will the resolver handle that for me? I remember seeing a few bugs around that in v4.0, but I may have already ironed them all out. |
I believe that the resolver should do the heavy lifting here. |
That would be great! Where do you think that would go? On My plan is code something like findTranslations(container, locale) {
const result = {};
let allLocaleFactories = null;
if (container.knownForType) {
allLocaleFactories = container.knownForType('locale')
} else {
allLocaleFactories = container._registry.knownForType('locale');
}
// do some filtering on locale here
Object.keys(allLocaleFactories).sort().forEach(function(key) {
if (/\/config$/.test(key)) { return; }
Ember.merge(result, allLocaleFactories[key]);
});
return result;
} |
And |
|
Hey look at that! It sure is :) That still doesn't cover the full compatibility for this library. But maybe this feature could be 1.13+. |
You shouldn't need this if/else, |
Nevermind, I'm crazy |
Hi there, just wanted to keep this discussion going... There were some arguments exchanged regarding this topic over here: jasonmit/ember-i18n-cp-validations#14 Some of the thoughts there:
I just wanted to move this over here, so we have a chance to develop a consistent strategy for all addons out there, for a) the current state of ember-i18n, b) the time when the proposal above lands in ember-i18n (is this being worked on?), and c) for a smooth transition between a) and b) from the perspective of an addon's author. |
jamesarosen/ember-i18n has been deprecated in favor of ember-intl. |
In the discussion below, I will use two hypothetical addons, ember-paginate and ember-select.
Problem
Currently, if an addon wants to provide default translations that the app can consume and optionally override, there are two options:
Require App to Manage
Each addon has an
addon/locales/en/translations.js
file and similar files for all locales it supports. The app must import these in its own translations files:That's a lot of boilerplate, especially since it needs to be repeated for every locale.
Addon Injects Translations
The addon could inject translations at runtime with an instance-initializer:
That's far better from an app-developer standpoint, but worse for addon authors.
Goal
The goal of this RFC is to make it so easy for both addon- and app developers to support i18n that they do by default.
Proposal
The key to this implementation is to loosen the restriction on the names of translation files. ember-paginate would have
ember-paginate/app/locales/en/ember-paginate.js
. ember-select might haveember-select/app/locales/en/ember-select.js
.It would then be the responsibility of ember-i18n's
Locale
to merge translations from all of the various packages. The new logic to get the collected translations for localeab-CDE
would belocale:ab-CDE/*
, excludinglocale:ab-CDE/config
ab
and repeatemberjs/ember.js#11393 introduced a new private API,
knownForType
, that would be useful for enumerating these packages.Ancillary Benefits
This change would also mean that app authors (or even addon authors) could break up their translations into multiple files. That would aid organization. I have not yet evaluated how that might work with pods.
Complications
There is potential for name collision across addons. It would thus be strongly recommended that addons define translations in
my-addon/app/:locale/my-addon.js
.This change would mean there no longer necessarily be a
locale:ab-CDE/translations
. That means thataddTranslations("ab-CDE", {...})
wouldn't have an obvious place to register its translations. We would want translations added throughaddTranslations
to override anything from the lookup path. Thus, I proposeaddTranslations
looks up or createslocale:ab-CDE/_runtime
with highest precedence in the merging.This change also suggests a change to the generator. One option would be to have the
locale
generator accept an optional secondpackage
argument, with the defaulttranslations
. Alternatively, there could be a secondlocale-package
ortranslations
generator that requires apackage
argument./cc @jkarsrud @rwjblue
The text was updated successfully, but these errors were encountered: