Closed fredrikvin closed 2 years ago
Yes, you should be able to continue to import ES modules containing your translations instead of JSON files (although I find JSON much more convenient).
You just have to import using the relative path (e.g. ../../locales/en.js
) instead of the "magical folder" $locales
(e.g. $locales/en.js
). That "folder" is what tells the plugin to resolve the file to a JSON file and compile on the fly.
Thanks a lot for the answer! Yeah, I could get it to work using relative paths but as the setup part of the README
uses ES modules as an example and the __layout
import example uses the "magical folder" I thought it would work and that I had messed something up. Then I'll simply put locales under src/lib
so it is accessable via $lib/locales
.
JSON is nice and all but I prefer being able to comment and split files up for bigger projects :)
Good point, being able to use json files is a somewhat new feature and the readme as behind. I'm working on a proper documentation page for the library where I hope I'll clarify things better, but I've updated the readme anyway.
I tend to prefer JSON files because there is good tooling when working with translation teams. Their tools tend to ingest and output json/xml files.
I can't get precompile working with ES modules without modifying svelteIntlPrecompile.load. Unless I'm missing something svelteIntlPrecompile.load seems to only support JSON but the README says otherwise.