drilkmops – 15-59 Aug 19
This is gonna be a really dumb question I should know the answer to.
I’m building a localization library. I have a big list of locale data that I only need to load a portion of each time. I dont want my end users to need any additional setup.
Is there a way for a static website to like “lazy load” the extra locale data when they’re needed only? So when someone visits the static page they only get
en
, but if something for fr
is used, it “fetches” that data somehow? I’d like to not require additional fetches to other endpoints, but CDN is likely fine I suppose.26 Replies
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
Ours is a bit more abstract since I’m writing some Rust that convert into wasm and typescript methods to call the wasm.
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
More context, I work at a big company and we can be a bit opinionated.
We’re wrapping icu4x
https://github.com/unicode-org/icu4x
GitHub
GitHub - unicode-org/icu4x: Solving i18n for client-side and resour...
Solving i18n for client-side and resource-constrained environments. - unicode-org/icu4x
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
Tbf it does make sense if we step back haha. We want a single localization solution across all our stacks. We can compile this into whatever language.
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
That’s good feedback regardless tbh.
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
Where would the assets be loaded from? Like would vite be packaging all of that and load it dynamically? Or would I do a cdn route? Cuz we got like 1.5mb and growing of locale data. I know we can reduce it, but trying to think of cleaner ways now.
Previously it required an external cal to convert their data. And they don’t want that.
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
I’m sure we have a way to do a CDN just fine at work to. Honestly that might be the move. Just fetch the locale blob we need from a cdn and bundle whatever data they need
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
CDN will be fast af anyway
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
It’s basically just displaying the strings to the end user. Formatting from a standard to specific with a locale
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
afaik this is how most i18n libraries I've used have worked, they tap into the compilation/build step and work to make resources available that way. But, that's meant that they have e.g. babel transforms and webpack plugins, which locks them into specific build tools
I wonder what it would look like to think about this from the web platform, rather than the build tool ecosystem? e.g. webpack is managing a tree of dependencies to ensure
<script>
tags get added to the dom and are ready to execute as user code expects — I wonder if it'd be feasible to do something similar for i18n?Cook a little more on that last paragraph. I think I half understand there
I guess I'm suggesting re-implementing some of the chunking and script/resource loading logic that would otherwise be done by something like webpack, as a means of avoiding tool lock-in. I'm not sure what that would look like in practice tho, it might be too big.
I guess, the hardest part here to me seems like it's understanding which source strings are in what code and ensuring that a minimal set of strings gets loaded
Ahh, I think I get what you’re saying. It’s not too hard for me to split up the locales and generate them individually.
But getting smaller than that down to the individual string level might get a bit wonky
Ah yeah I think I had assumed you were already splitting on locale
Even the wasm itself is quite large without any data. Like 400kb. Gonna talk to some coworkers who are more in the realm of rust/wasm.
It’s hard to not see that and be all “alarm bells” even though I know the size is only a portion.
yea 400kb for a i18n runtime is :sus:
This thread hasn’t had any activity in 36 hours, so it’s now locked.
Threads are closed automatically after 36 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/1275122025668677737