Closed cupcakearmy closed 2 years ago
I'd love to support JSON files. It was my initial idea but I couldn't find a way with svelte/vite of making the plugin run after vite:json
but before svelte-kit preprocesses all import statements.
It's almost surely something workable, but I don't know enough about the build pipeline.
Thanks! Yeah i have 0 expertise in bundler pipelines. Feel free to close it, i'll probably look to generate the files then :)
As soon as I have time I'm going to give it another go. I'm sure there must be a way.
That would be awesome of course :)
I'm use locale.json for dictionaries on esbuild bundler 🤷🏻‍♂️
import en from "@lang/en.json";
addMessages("en", en);
// or
register("en", () => import("@lang/en.json"));
@Valexr could you explain more? I didn't even know that svelte could do that.
Sure @cibernox 🤓 It’s not svelte, it’s esbuild can imports .json files to bundle by default🤷🏻‍♂️ But I’m not sure about i18n logic operators… don’t use it.
Simple starter for testing https://github.com/AlexxNB/svelte-esbuild-starter just try it. & update esbuild to 0.11.* minor please.
+1 I'd love to see the support for .json
files. It would make it easier to use the library in conjunction with tools such as Lokalise.
Indeed, it's probably the thing I miss the most myself when using it. My sveltekit (or Vite really) skills might not be sharp enough to do that without help, as it's a bit tricky. You want to import a js file that doesn't exist and have it resolved to a generated-on-the-fly JS file from a JSON source.
I'll check if someone with more experience can help with that.
@cibernox tried to implement this in #16
Released this feature in 0.4.0. The version bump wasn't really necessary as this is backwards compatible but it's there just to signal a significant feature.
I now recommend people define it's translations in json files, there is no reason to use javascript/typescript anymore.
Hey, saw your talk at Svelte Summit and i love it. Makes so much sense! A question about usage: i tried using json instead of js files but it don't work, probably because bable only applies to js. Now my question is: is there a way to make it work with json files? most platforms like lokalise do not support js files, also most of the i18n extensions also require json files. Unfortunately, using js files makes it quite impossible in bigger projects. Do you know any way around this?
Thanks!