robisim74 / qwik-speak

Translate your Qwik apps into any language
https://robisim74.gitbook.io/qwik-speak/
MIT License
131 stars 15 forks source link

Base, locale directories, q-bundle-graphs and the qwikInline vite plugin #133

Closed intellix closed 1 week ago

intellix commented 1 week ago

We've just updated to qwik 1.8.0 with the new PrefetchWorker and we're using qwik-speak for localisation. When I look at our build directory I can see that we have bundles inside locale folders, and q-bundle-graph JSON files that aren't copied in, like so:

/build
  q-bundle-graph-oym6qj.json
  q-abc123.js
  q-def456.js

  /en-US
    q-abc123.js (en-US locales baked in)
    q-def456.js

  /pt-BR
    q-abc123.js (pt-BR locales baked in)
    q-def456.js

I was looking at network requests and noticed that we're getting a 404 request for q-bundle-graphs, because they're not copied into the locale folders at build time.

A request for /build/en-US/q-bundle-graph-oym6qj.json is made there because of q-base pointing to the locale to load the language specific bundles with the languages pre-baked in:

<html lang="en-US" q:render="ssr" q:route="/" q:container="resumed" q:version="1.8.0" q:base="/build/en-US/" q:locale="en-US" q:manifest-hash="oym6qj" q:instance="r80zuccsb7k">

Forgive me if it's not a qwik-speak specific issue, but could the vite plugin here copy across the q-bundle-graph files into the language specific directories?

I believe the q-bundle-graphs are coming from the new PrefetchWorker

robisim74 commented 1 week ago

@intellix Copying additional files into the locale folders would not be a problem, but in theory this is only necessary for localized chunks (and not for json or css).

PrefetchGraph and PrefetchServiceWorker are APIs still in alpha preview, I haven't studied them yet and I still don't know their features.

From the doc (https://qwik.dev/api/qwik/#prefetchgraph) I see that you can set the base url:

        <PrefetchServiceWorker base={"/build/"} scope="/" />
        <PrefetchGraph base={"/build/"} />

And from what I see, this seems to be enough to avoid the 404 errors.

intellix commented 1 week ago

I can confirm the above works, thanks for pointing it out to me :)