Read local i18n json files
I have a worker running a Discord bot and want to start building up i18n for it. I have structure set up, but need a way to load the json lang files. If anything I may just fall back to a basic
include and change up the files slightly.
TIL this isn't Node.js, but "workerd". So fs.readFileSync isn't available.
I tried reading over this blog post but it along with my messed up sleep is making my brain hurt. It's not making any sense. not sure if it's even relatable or not.
https://blog.cloudflare.com/more-npm-packages-on-cloudflare-workers-combining-polyfills-and-native-code/
I have files at:
- ./src/api/i18n/en-US.json
- ./src/api/i18n/es-ES.json
- ./src/api/i18n/it.json
- etc.
Main entry is at ./src/api/server.js so it just refers to ./i18n/{lang}.jsonThe Cloudflare Blog
More NPM packages on Cloudflare Workers: Combining polyfills and na...
Workers now supports more NPM packages and Node.js APIs using an overhauled hybrid compatibility layer.
3 Replies
Don't know if I'm looking at this correctly, but it seems like it's just a 'here's how you can make a function match the module so the "function doesn't exist" error goes away' but does nothing for actually making it do what it should lol
Is there a reason why importing them doesn’t work?
Wasn't planning on it that way and I didn't want to deal with mapping it all out and whatnot tbh lol
I'll probably swap it over to that but was curious if there was a tweak that could be done to get it working, unless it's not as efficient that way or something.