I just converted a form library I wrote into an addon so I could share it between projects. I also wrote my own language pak i18n translation tool that is semi coupled with the addon (eg label’s for the form are passed in as language pak keys). I want consumers of the addon to specify their own translation tool rather than couple it with mine.
Approaches: Make a function called translate
on the form component, and and consumer of the addon has to reopen the form class and implement the translation function.
Have the form library use a translationService with a translate
function and have the consuming app override this service via an initializer (I’m assuming this would work, haven’t tested).
Which really brings me to the crux of my question: how should addon configuration be handled? Using the app config didn’t seem like the easiest approach because I wasn’t sure how to import classes/functions I export default
from the app (is there a syntax to require
these functions from a file like environment.js
). A configuration service object might be an alright approach as well, where the consuming app creates a custom initializer. Anyone with experience doing this, would love to hear from you!