Closed xdev1 closed 2 years ago
Frankly, I cannot see why the dependency on Lit is necessary for Localize.
It's not necessary. In fact, it's no longer a dependency. Lit is only a dev dependency for the purpose of typings.
I find the Reactive Controller pattern to be superior to the previous approach this library took, which relied on decorators and directives. With ~726 bytes (minified/gzipped), you get a complete component-level localization solution with zero dependencies.
The only requirement is whatever authoring library you use must support the Reactive Controller pattern — or you can shim it. There's already interest in the community to make this sort of a "standard" so it can more easily work with components built with other libraries as well.
The controversial statement in the previous paragraph is:
whatever authoring library you use must support the Reactive Controller pattern
I don't care if this means nobody else supports it today. This is an emerging pattern that I believe will become ubiquitous as more controllers are open sourced. It's a chicken/egg problem and a bet I'm willing to take.
It also satisfies my need for Shoelace very well, which is the main reason this library exists.
Also, I think the name updateLocalizedTerms is not a very good choice
Agree. I've renamed it to update
in 7be109847d3b89277f84ee1087b353c5c6ad6d18.
Please see the components sl-format-bytes, sl-format-date, sl-format-number, sl-relative-time in branch localize in the @shoelace-style/shoelace project. They are not yet based on Localize but sooner or later they will
They are now. https://github.com/shoelace-style/shoelace/commit/f87cb8d940e447a9ae0a2419a628015644856875
Closing since the dependency has been gotten rid of.
Many thanks :smiley::+1:
Frankly, I cannot see why the dependency on Lit is necessary for
Localize
.Localize
could easily be a dependency-free library. The main problem is that the constructor of classLocalizeController
is of typeconstructor(host: ReactiveControllerHost & HTMLElement)
which is way to complicated (=> unnecessarily complicated). If a third-party SL component developer does NOT useLitElement
(like me for example) it gets really ugly to useLocalize
(for example, if someone uses a hooks-based web component library - again: like me - and wants to implement auseLocalize
hook based onLocalizeController
).It would be much easier for everybody to define an interface like the following (which is a super type of
LitElement
)and use this as first argument of the
LocalizeController
constructor (LocalizableHost
is a much less complicated type thanReactiveControllerHost & HTMLElement
).Also, I think the name
updateLocalizedTerms
is not a very good choice as this function does more than just updating terms. MaybeupdateLocalization
or whatever would be a better choice. If it's not clear what I mean: Please see the componentssl-format-bytes
,sl-format-date
,sl-format-number
,sl-relative-time
in branchlocalize
in the@shoelace-style/shoelace
project. They are not yet based onLocalize
but sooner or later they will, as this is surely the standard SL way that they will properly be auto-updated on document language changes, and it's also useful from a software design POV, proper abstraction and consistency reasons. Then, those components will be auto-updated by implicitupdateLocalizeTerms
invocations, but as the mentioned components do not even haveterms
, so the nameupdateLocalizeTerms
does not really always make sense. Q.E.D.The following code has not been tested but I guess something like that should basically work (and produce smaller JavaScript code as the original version).
```typescript export interface LocalizableHost { addController(controller: { hostConnected(): void; hostDisconnected(): void }): void; requestUpdate(): void; lang: string; } export type FunctionParams