Quoting Axel Hecht (2014-09-22 22:56:39) > That's a lot of data, but I'll cherry pick one. > > Looking at coding patterns in js land, making navigator.mozL10n.ctx > immutable doesn't feel right. It's just to popular to short-hand that, > to the extent that there'll be a > > var _ = navigator.mozL10n.ctx.get.bind(navigator.mozL10n.ctx)
I'm not sure if something.mozL10n.ctx should be our primary API in the HTML bindings. Here's one way I thought this could be laid out: - document.mozL10n is a DocumentBindings object which is available right away. - document.mozL10n instantiates its Env to handle language registration once the manifest data is available. Since this is completely l10n-format agnostic, it makes a good candidate for our first native API; maybe `new navigator.mozLocalization` (to avoid naming conflicts with the current navigator.mozL10n). - document.mozL10n also has its default context (or a default resource bundle) which uses the resources defined in <head>. If contexts are immutable it might be a good idea to make this default context private; in the future we'll want to make it possible to add new resources to <head> declaratively and have document.mozL10n pick them up automatically, which will require recreating the default context. The same goes for language switching on my 'immutable' branch. As you can see, I'd like Env and Context to be a low-level web API which can be used to build bigger abstractions. I think our HTML bindings should be a consumer of those low-level APIs. One more thing that I've been thinking about is this: - document.mozL10n could also have its own get() and format() methods which delegate to the default ctx if it's available or intercept the calls and wait for the Env to be created. I'm not sure if I like this last idea or not. Part of me thinks that we should allow developers to use the document.mozL10n API even before the manifest is fetched and the Env is created. Another part prefers an API design which assumes some knowledge of how browsers parse HTML and relies on the correct use of the defer attribute, a meaningful ordering of <script> tags and maybe a special event called 'languagesregistered'. -stas -- @stas _______________________________________________ tools-l10n mailing list [email protected] https://lists.mozilla.org/listinfo/tools-l10n
