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

plugin does not find locales on windows #23

Closed tillbaks closed 2 years ago

tillbaks commented 2 years ago

Because paths are separated by backslashes on windows. in transform(code, id) the id contains the path with forwardslashes (instead of backslashes) which means id.includes(resolvedPath) will never match anything on windows unless I do const resolvedPath = path.resolve(localesRoot).replace(/\\/g,"/"). Not sure what would be the best way to solve this. Seems strange that there are forwardslashes at all in the path.

Not sure if relevant but I'm not using sveltekit but vite with vite-plugin-svelte node v14.17.6

cibernox commented 2 years ago

Is this still an issue? I've just successfully run this library on an app on windows, so perhaps it's not longer a problem. If there is, please provide a sample repo I can clone for reproduction.

tillbaks commented 2 years ago

Yep, still a problem.

I made a small repo here: https://github.com/tillbaks/svelte-intl-precompile-vite-windows-issue

npm install
npm run build

and check output in dist/assets/en....js

var a={"some.id":"Param x is {x} and param y is {y}!","some.other.id":"Without any params.."};export{a as default};

when expected output is:

import{_ as a}from"./vendor.c12a8071.js";var s={"some.id":(r,e)=>`Param x is ${a(r)} and param y is ${a(e)}!`,"some.other.id":"Without any params.."};export{s as default};
cibernox commented 2 years ago

@tillbaks I made https://github.com/tillbaks/svelte-intl-precompile-vite-windows-issue/pull/1 to your issue repo with a fix. I hope it helps

cibernox commented 2 years ago

@tillbaks Did the changes in 0.8.0 fix your windows issue?

tillbaks commented 2 years ago

@cibernox not sure. looks like sveltekit-plugin.cjs is missing in 0.8.0

tillbaks commented 2 years ago

got it working without cjs and v0.8.0: https://github.com/tillbaks/svelte-intl-precompile-vite-windows-issue/commit/aaf32f9b1bb93c92bb3022fe6a3a287f4c636f17