cibernox / svelte-intl-precompile

I18n library for Svelte.js that analyzes your keys at build time for max performance and minimal footprint
https://svelte-intl-precompile.com
ISC License
274 stars 13 forks source link

JSON support? #5

Closed cupcakearmy closed 2 years ago

cupcakearmy commented 3 years ago

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!

cibernox commented 3 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.

cupcakearmy commented 3 years ago

Thanks! Yeah i have 0 expertise in bundler pipelines. Feel free to close it, i'll probably look to generate the files then :)

cibernox commented 3 years ago

As soon as I have time I'm going to give it another go. I'm sure there must be a way.

cupcakearmy commented 3 years ago

That would be awesome of course :)

Valexr commented 3 years ago

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"));
cibernox commented 3 years ago

@Valexr could you explain more? I didn't even know that svelte could do that.

Valexr commented 3 years ago

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.

lorenzosignoretti commented 2 years ago

+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.

cibernox commented 2 years ago

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.

uside commented 2 years ago

@cibernox tried to implement this in #16

cibernox commented 2 years ago

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.

cibernox commented 2 years ago

I now recommend people define it's translations in json files, there is no reason to use javascript/typescript anymore.