@qwik.dev/core 2.0.0-beta.18 → 2.0.0-beta.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/backpatch/package.json +1 -1
- package/dist/build/package.json +1 -1
- package/dist/cli.mjs +2 -2
- package/dist/core-internal.d.ts +10 -3
- package/dist/core.min.mjs +1 -1
- package/dist/core.mjs +107 -91
- package/dist/core.mjs.map +1 -1
- package/dist/core.prod.mjs +64 -61
- package/dist/loader/package.json +1 -1
- package/dist/optimizer.mjs +889 -884
- package/dist/server.mjs +4 -3
- package/dist/starters/adapters/cloudflare-workers/README.md +52 -0
- package/dist/starters/adapters/cloudflare-workers/adapters/cloudflare-workers/vite.config.ts +15 -0
- package/dist/starters/adapters/cloudflare-workers/gitignore +3 -0
- package/dist/starters/adapters/cloudflare-workers/package.json +31 -0
- package/dist/starters/adapters/cloudflare-workers/public/.assetsignore +4 -0
- package/dist/starters/adapters/cloudflare-workers/public/_headers +11 -0
- package/dist/starters/adapters/cloudflare-workers/public/_redirects +1 -0
- package/dist/starters/adapters/cloudflare-workers/src/entry.cloudflare-pages.tsx +23 -0
- package/dist/starters/adapters/cloudflare-workers/worker-configuration.d.ts +5 -0
- package/dist/starters/adapters/cloudflare-workers/wrangler.jsonc +41 -0
- package/dist/starters/adapters/express/package.json +1 -1
- package/dist/starters/features/compiled-i18n/package.json +37 -0
- package/dist/starters/features/compiled-i18n/src/components/locale-selector/locale-selector.tsx +30 -0
- package/dist/starters/features/{localize → compiled-i18n}/src/entry.ssr.tsx +7 -2
- package/dist/starters/features/compiled-i18n/src/routes/plugin@compiled-i18n.ts +28 -0
- package/dist/starters/features/cypress/src/actions/example.action.ts +5 -0
- package/dist/starters/features/cypress/src/components/example/example.cy.tsx +50 -8
- package/dist/starters/features/cypress/src/components/example/example.tsx +13 -3
- package/dist/starters/features/cypress/src/loaders/example.loader.ts +5 -0
- package/dist/testing/index.mjs +71 -44
- package/dist/testing/package.json +1 -1
- package/package.json +2 -2
- package/dist/starters/features/localize/package.json +0 -37
- package/dist/starters/features/localize/src/locales/message.en.json +0 -8
- package/dist/starters/features/localize/src/locales/message.it.json +0 -8
- package/dist/starters/features/localize/src/routes/[locale]/i18n-utils.ts +0 -94
- package/dist/starters/features/localize/src/routes/[locale]/index.tsx +0 -52
- package/dist/starters/features/localize/src/routes/[locale]/layout.tsx +0 -12
package/dist/testing/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* @qwik.dev/core/testing 2.0.0-beta.
|
|
3
|
+
* @qwik.dev/core/testing 2.0.0-beta.19-dev+0d046fb
|
|
4
4
|
* Copyright QwikDev. All Rights Reserved.
|
|
5
5
|
* Use of this source code is governed by an MIT-style license that can be
|
|
6
6
|
* found in the LICENSE file at https://github.com/QwikDev/qwik/blob/main/LICENSE
|
|
@@ -24103,23 +24103,8 @@ function retryOnPromise(fn, retryCount = 0) {
|
|
|
24103
24103
|
}
|
|
24104
24104
|
}
|
|
24105
24105
|
|
|
24106
|
-
// packages/qwik/src/core/use/use-
|
|
24107
|
-
import {
|
|
24108
|
-
var _locale = void 0;
|
|
24109
|
-
var localAsyncStore;
|
|
24110
|
-
if (isServer3) {
|
|
24111
|
-
import("node:async_hooks").then((module) => {
|
|
24112
|
-
localAsyncStore = new module.AsyncLocalStorage();
|
|
24113
|
-
}).catch(() => {
|
|
24114
|
-
});
|
|
24115
|
-
}
|
|
24116
|
-
function setLocale(locale) {
|
|
24117
|
-
if (localAsyncStore) {
|
|
24118
|
-
localAsyncStore.enterWith(locale);
|
|
24119
|
-
return;
|
|
24120
|
-
}
|
|
24121
|
-
_locale = locale;
|
|
24122
|
-
}
|
|
24106
|
+
// packages/qwik/src/core/use/use-core.ts
|
|
24107
|
+
import { isDev as isDev21 } from "@qwik.dev/core/build";
|
|
24123
24108
|
|
|
24124
24109
|
// packages/qwik/src/core/use/use-sequential-scope.ts
|
|
24125
24110
|
var useSequentialScope = () => {
|
|
@@ -24590,10 +24575,10 @@ var cleanupDestroyable = (destroyable) => {
|
|
|
24590
24575
|
};
|
|
24591
24576
|
|
|
24592
24577
|
// packages/qwik/src/core/reactive-primitives/subscriber.ts
|
|
24593
|
-
import { isServer as
|
|
24578
|
+
import { isServer as isServer3 } from "@qwik.dev/core/build";
|
|
24594
24579
|
function getSubscriber(effect, prop, data) {
|
|
24595
24580
|
if (!effect[_EFFECT_BACK_REF]) {
|
|
24596
|
-
if (
|
|
24581
|
+
if (isServer3 && isSsrNode(effect)) {
|
|
24597
24582
|
effect.setProp(QBackRefs, /* @__PURE__ */ new Map());
|
|
24598
24583
|
} else {
|
|
24599
24584
|
effect[_EFFECT_BACK_REF] = /* @__PURE__ */ new Map();
|
|
@@ -24664,7 +24649,7 @@ var cleanupFn = (target, handleError) => {
|
|
|
24664
24649
|
};
|
|
24665
24650
|
|
|
24666
24651
|
// packages/qwik/src/core/reactive-primitives/impl/signal-impl.ts
|
|
24667
|
-
import { isDev as isDev7, isServer as
|
|
24652
|
+
import { isDev as isDev7, isServer as isServer4 } from "@qwik.dev/core/build";
|
|
24668
24653
|
var DEBUG = false;
|
|
24669
24654
|
var log = (...args) => console.log("SIGNAL", ...args.map(qwikDebugToString));
|
|
24670
24655
|
var SignalImpl = class {
|
|
@@ -24712,7 +24697,7 @@ var SignalImpl = class {
|
|
|
24712
24697
|
if (effectSubscriber) {
|
|
24713
24698
|
ensureContainsSubscription(this.$effects$ || (this.$effects$ = /* @__PURE__ */ new Set()), effectSubscriber);
|
|
24714
24699
|
ensureContainsBackRef(effectSubscriber, this);
|
|
24715
|
-
(import.meta.env.TEST ? !isDomContainer(this.$container$) :
|
|
24700
|
+
(import.meta.env.TEST ? !isDomContainer(this.$container$) : isServer4) && addQrlToSerializationCtx(effectSubscriber, this.$container$);
|
|
24716
24701
|
DEBUG && log("read->sub", pad("\n" + this.toString(), " "));
|
|
24717
24702
|
}
|
|
24718
24703
|
return this.untrackedValue;
|
|
@@ -24790,10 +24775,10 @@ function clearEffectSubscription(container, effect) {
|
|
|
24790
24775
|
return;
|
|
24791
24776
|
}
|
|
24792
24777
|
for (const producer of backRefs) {
|
|
24793
|
-
if (producer instanceof
|
|
24794
|
-
clearSignal(container, producer, effect);
|
|
24795
|
-
} else if (producer instanceof AsyncComputedSignalImpl) {
|
|
24778
|
+
if (producer instanceof AsyncComputedSignalImpl) {
|
|
24796
24779
|
clearAsyncComputedSignal(producer, effect);
|
|
24780
|
+
} else if (producer instanceof SignalImpl) {
|
|
24781
|
+
clearSignal(container, producer, effect);
|
|
24797
24782
|
} else if (isPropsProxy(producer)) {
|
|
24798
24783
|
const propsHandler = producer[_PROPS_HANDLER];
|
|
24799
24784
|
clearStoreOrProps(propsHandler, effect);
|
|
@@ -24810,7 +24795,7 @@ function clearSignal(container, producer, effect) {
|
|
|
24810
24795
|
if (effects && effects.has(effect)) {
|
|
24811
24796
|
effects.delete(effect);
|
|
24812
24797
|
}
|
|
24813
|
-
if (producer instanceof WrappedSignalImpl) {
|
|
24798
|
+
if (producer instanceof WrappedSignalImpl && !effects?.size) {
|
|
24814
24799
|
producer.$hostElement$ = void 0;
|
|
24815
24800
|
clearAllEffects(container, producer);
|
|
24816
24801
|
}
|
|
@@ -25137,7 +25122,7 @@ var createSerializer$ = implicit$FirstArg(
|
|
|
25137
25122
|
var getValueProp = (p0) => p0.value;
|
|
25138
25123
|
|
|
25139
25124
|
// packages/qwik/src/core/shared/vnode/vnode-dirty.ts
|
|
25140
|
-
import { isServer as
|
|
25125
|
+
import { isServer as isServer7 } from "@qwik.dev/core/build";
|
|
25141
25126
|
|
|
25142
25127
|
// packages/qwik/src/core/shared/cursor/cursor-queue.ts
|
|
25143
25128
|
var globalCursorQueue = [];
|
|
@@ -25265,7 +25250,7 @@ var SubscriptionData = class {
|
|
|
25265
25250
|
};
|
|
25266
25251
|
|
|
25267
25252
|
// packages/qwik/src/core/shared/component-execution.ts
|
|
25268
|
-
import { isDev as isDev14, isServer as
|
|
25253
|
+
import { isDev as isDev14, isServer as isServer5 } from "@qwik.dev/core/build";
|
|
25269
25254
|
|
|
25270
25255
|
// packages/qwik/src/core/client/run-qrl.ts
|
|
25271
25256
|
function callQrl(container, host, qrl, event, element, useGetObjectById) {
|
|
@@ -26683,7 +26668,7 @@ var executeComponent = (container, renderHost, subscriptionHost, componentQRL, p
|
|
|
26683
26668
|
const inlineComponent = componentQRL;
|
|
26684
26669
|
componentFn = () => invokeApply(iCtx, inlineComponent, [props || EMPTY_OBJ]);
|
|
26685
26670
|
}
|
|
26686
|
-
const isSsr = import.meta.env.TEST ? isServerPlatform() :
|
|
26671
|
+
const isSsr = import.meta.env.TEST ? isServerPlatform() : isServer5;
|
|
26687
26672
|
const executeComponentWithPromiseExceptionRetry = (retryCount = 0) => safeCall(
|
|
26688
26673
|
() => {
|
|
26689
26674
|
if (!isInlineComponent) {
|
|
@@ -29170,7 +29155,7 @@ var createMacroTask = (fn) => {
|
|
|
29170
29155
|
};
|
|
29171
29156
|
|
|
29172
29157
|
// packages/qwik/src/core/shared/cursor/cursor-walker.ts
|
|
29173
|
-
import { isDev as isDev17, isServer as
|
|
29158
|
+
import { isDev as isDev17, isServer as isServer6 } from "@qwik.dev/core/build";
|
|
29174
29159
|
var DEBUG6 = false;
|
|
29175
29160
|
var nextMicroTask = createMicroTask(processCursorQueue);
|
|
29176
29161
|
var nextMacroTask = createMacroTask(processCursorQueue);
|
|
@@ -29199,7 +29184,7 @@ function processCursorQueue(options = {
|
|
|
29199
29184
|
}
|
|
29200
29185
|
function walkCursor(cursor, options) {
|
|
29201
29186
|
const { timeBudget } = options;
|
|
29202
|
-
const isRunningOnServer = import.meta.env.TEST ? isServerPlatform() :
|
|
29187
|
+
const isRunningOnServer = import.meta.env.TEST ? isServerPlatform() : isServer6;
|
|
29203
29188
|
const startTime = performance.now();
|
|
29204
29189
|
const cursorData = getCursorData(cursor);
|
|
29205
29190
|
const blockingPromise = cursorData.promise;
|
|
@@ -29457,7 +29442,7 @@ function findAndPropagateToBlockingCursor(vNode) {
|
|
|
29457
29442
|
return false;
|
|
29458
29443
|
}
|
|
29459
29444
|
function isSsrNodeGuard(_vNode) {
|
|
29460
|
-
return import.meta.env.TEST ? isServerPlatform() :
|
|
29445
|
+
return import.meta.env.TEST ? isServerPlatform() : isServer7;
|
|
29461
29446
|
}
|
|
29462
29447
|
function markVNodeDirty(container, vNode, bits, cursorRoot = null) {
|
|
29463
29448
|
const prevDirty = vNode.dirty;
|
|
@@ -31021,8 +31006,43 @@ var DomContainer = class extends _SharedContainer {
|
|
|
31021
31006
|
}
|
|
31022
31007
|
};
|
|
31023
31008
|
|
|
31009
|
+
// packages/qwik/src/core/use/use-locale.ts
|
|
31010
|
+
import { isServer as isServer8 } from "@qwik.dev/core/build";
|
|
31011
|
+
var _locale = void 0;
|
|
31012
|
+
var localAsyncStore;
|
|
31013
|
+
if (isServer8) {
|
|
31014
|
+
import("node:async_hooks").then((module) => {
|
|
31015
|
+
localAsyncStore = new module.AsyncLocalStorage();
|
|
31016
|
+
}).catch(() => {
|
|
31017
|
+
});
|
|
31018
|
+
}
|
|
31019
|
+
function setLocale(locale) {
|
|
31020
|
+
if (localAsyncStore) {
|
|
31021
|
+
localAsyncStore.enterWith(locale);
|
|
31022
|
+
return;
|
|
31023
|
+
}
|
|
31024
|
+
_locale = locale;
|
|
31025
|
+
}
|
|
31026
|
+
|
|
31027
|
+
// packages/qwik/src/core/index.ts
|
|
31028
|
+
if (globalThis.__qwik) {
|
|
31029
|
+
console.error(
|
|
31030
|
+
`==============================================
|
|
31031
|
+
Qwik version ${globalThis.__qwik} already imported while importing ${version}.
|
|
31032
|
+
This can lead to issues due to duplicated shared structures.
|
|
31033
|
+
Verify that the Qwik libraries you're using are in "resolve.noExternal[]" and in "optimizeDeps.exclude".
|
|
31034
|
+
==============================================
|
|
31035
|
+
`
|
|
31036
|
+
);
|
|
31037
|
+
}
|
|
31038
|
+
globalThis.__qwik = version;
|
|
31039
|
+
if (import.meta.hot) {
|
|
31040
|
+
import.meta.hot.dispose(() => {
|
|
31041
|
+
globalThis.__qwik = void 0;
|
|
31042
|
+
});
|
|
31043
|
+
}
|
|
31044
|
+
|
|
31024
31045
|
// packages/qwik/src/core/use/use-core.ts
|
|
31025
|
-
import { isDev as isDev21 } from "@qwik.dev/core/build";
|
|
31026
31046
|
var _context;
|
|
31027
31047
|
var tryGetInvokeContext = () => {
|
|
31028
31048
|
if (!_context) {
|
|
@@ -31102,18 +31122,24 @@ function newInvokeContext(locale, hostElement, event, url) {
|
|
|
31102
31122
|
seal(ctx);
|
|
31103
31123
|
return ctx;
|
|
31104
31124
|
}
|
|
31105
|
-
var untrack = (
|
|
31106
|
-
if (
|
|
31107
|
-
|
|
31108
|
-
|
|
31109
|
-
|
|
31110
|
-
|
|
31111
|
-
|
|
31112
|
-
|
|
31125
|
+
var untrack = (expr, ...args) => {
|
|
31126
|
+
if (typeof expr === "function") {
|
|
31127
|
+
if (_context) {
|
|
31128
|
+
const sub = _context.$effectSubscriber$;
|
|
31129
|
+
try {
|
|
31130
|
+
_context.$effectSubscriber$ = void 0;
|
|
31131
|
+
return expr(...args);
|
|
31132
|
+
} finally {
|
|
31133
|
+
_context.$effectSubscriber$ = sub;
|
|
31134
|
+
}
|
|
31135
|
+
} else {
|
|
31136
|
+
return expr(...args);
|
|
31113
31137
|
}
|
|
31114
|
-
} else {
|
|
31115
|
-
return fn();
|
|
31116
31138
|
}
|
|
31139
|
+
if (isSignal(expr)) {
|
|
31140
|
+
return expr.untrackedValue;
|
|
31141
|
+
}
|
|
31142
|
+
return unwrapStore(expr);
|
|
31117
31143
|
};
|
|
31118
31144
|
var trackInvocation = /* @__PURE__ */ newRenderInvokeContext(void 0, void 0, void 0);
|
|
31119
31145
|
var trackSignal = (fn, subscriber, property, container, data) => {
|
|
@@ -34793,7 +34819,7 @@ function flattenPrefetchResources(prefetchResources) {
|
|
|
34793
34819
|
// packages/qwik/src/server/preload-strategy.ts
|
|
34794
34820
|
var getBundles = (qrls) => {
|
|
34795
34821
|
const platform = getPlatform2();
|
|
34796
|
-
|
|
34822
|
+
const bundles2 = qrls?.map((qrl) => {
|
|
34797
34823
|
const symbol = qrl.$symbol$;
|
|
34798
34824
|
const chunk = qrl.$chunk$;
|
|
34799
34825
|
const result2 = platform.chunkForSymbol(symbol, chunk, qrl.dev?.file);
|
|
@@ -34802,6 +34828,7 @@ var getBundles = (qrls) => {
|
|
|
34802
34828
|
}
|
|
34803
34829
|
return chunk;
|
|
34804
34830
|
}).filter(Boolean);
|
|
34831
|
+
return [...new Set(bundles2)];
|
|
34805
34832
|
};
|
|
34806
34833
|
function getPreloadPaths(qrls, opts, resolvedManifest) {
|
|
34807
34834
|
const prefetchStrategy = opts.prefetchStrategy;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qwik.dev/core",
|
|
3
3
|
"description": "An open source framework for building instant loading web apps at any scale, without the extra effort.",
|
|
4
|
-
"version": "2.0.0-beta.
|
|
4
|
+
"version": "2.0.0-beta.19",
|
|
5
5
|
"author": "Qwik Team",
|
|
6
6
|
"bin": {
|
|
7
7
|
"qwik": "./qwik-cli.mjs"
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"kleur": "4.1.5",
|
|
22
22
|
"prettier": "3.7.4",
|
|
23
23
|
"vitest": "4.0.16",
|
|
24
|
-
"@qwik.dev/core": "2.0.0-beta.
|
|
24
|
+
"@qwik.dev/core": "2.0.0-beta.19",
|
|
25
25
|
"@qwik.dev/dom": "2.1.19"
|
|
26
26
|
},
|
|
27
27
|
"engines": {
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"description": "Add i18n $localize in your Qwik app",
|
|
3
|
-
"__qwik__": {
|
|
4
|
-
"displayName": "Integration: i18n $localize (compile time translations)",
|
|
5
|
-
"priority": -10,
|
|
6
|
-
"viteConfig": {},
|
|
7
|
-
"docs": [
|
|
8
|
-
"https://qwik.dev/docs/integrations/i18n/#localize",
|
|
9
|
-
"https://github.com/mhevery/qwik-i18n",
|
|
10
|
-
"https://angular.io/api/localize/init/$localize"
|
|
11
|
-
],
|
|
12
|
-
"nextSteps": {
|
|
13
|
-
"title": "Next Steps",
|
|
14
|
-
"lines": [
|
|
15
|
-
" - /src/routes/[locale]: New public route showcasing i18n $localize integration",
|
|
16
|
-
"",
|
|
17
|
-
" Check out the i18n $localize docs for more info:",
|
|
18
|
-
" - https://qwik.dev/docs/integrations/i18n/#localize",
|
|
19
|
-
" - https://github.com/mhevery/qwik-i18n",
|
|
20
|
-
" - https://angular.io/api/localize/init/$localize"
|
|
21
|
-
]
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
"dependencies": {
|
|
25
|
-
"@angular/localize": "^18.2.13"
|
|
26
|
-
},
|
|
27
|
-
"devDependencies": {
|
|
28
|
-
"@angular/compiler": "^18.2.13",
|
|
29
|
-
"@angular/compiler-cli": "^18.2.13"
|
|
30
|
-
},
|
|
31
|
-
"scripts": {
|
|
32
|
-
"build.client": "vite build && npm run i18n-translate",
|
|
33
|
-
"prei18n-extract": "vite build",
|
|
34
|
-
"i18n-extract": "node_modules/.bin/localize-extract -s \"dist/build/*.js\" -f json -o src/locales/message.en.json",
|
|
35
|
-
"i18n-translate": "node_modules/.bin/localize-translate -s \"*.js\" -t src/locales/message.*.json -o dist/build/{{LOCALE}} -r ./dist/build"
|
|
36
|
-
}
|
|
37
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"locale": "en",
|
|
3
|
-
"translations": {
|
|
4
|
-
"1573294495032945047": "Hello from {$PH}!",
|
|
5
|
-
"8569626659814641312": "Use the following links to change the translation.",
|
|
6
|
-
"6563882999249543998": "Translation is performed as part of the build step so translated strings are inlined into the application, there is no need to load or look them up at runtime. However, these advantages mean that the user cannot change the language without refreshing the page."
|
|
7
|
-
}
|
|
8
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"locale": "it",
|
|
3
|
-
"translations": {
|
|
4
|
-
"1573294495032945047": "Un saluto da {$PH}!",
|
|
5
|
-
"8569626659814641312": "Usa i seguenti link per cambiare la traduzione.",
|
|
6
|
-
"6563882999249543998": "La traduzione viene eseguita come parte della fase di build e le stringhe tradotte vengono integrate nell'applicazione, non è necessario caricarle o cercarle in fase di runtime.\nTuttavia, questi vantaggi significano che l'utente non può cambiare la lingua senza ricaricare la pagina."
|
|
7
|
-
}
|
|
8
|
-
}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { loadTranslations } from "@angular/localize";
|
|
2
|
-
import "@angular/localize/init";
|
|
3
|
-
import { $, getLocale, useOnDocument, withLocale } from "@qwik.dev/core";
|
|
4
|
-
import type { RenderOptions } from "@qwik.dev/core/server";
|
|
5
|
-
|
|
6
|
-
// You must declare all your locales here
|
|
7
|
-
import EN from "../../locales/message.en.json";
|
|
8
|
-
import IT from "../../locales/message.it.json";
|
|
9
|
-
|
|
10
|
-
// Make sure it's obvious when the default locale was selected
|
|
11
|
-
const DEFAULT_LOCALE = "en";
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* This file is left for the developer to customize to get the behavior they want for localization.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/// Declare location where extra types will be stored.
|
|
18
|
-
const $localizeFn = $localize as any as {
|
|
19
|
-
TRANSLATIONS: Record<string, any>;
|
|
20
|
-
TRANSLATION_BY_LOCALE: Map<string, Record<string, any>>;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* This solution uses the `@angular/localize` package for translations, however out of the box
|
|
25
|
-
* `$localize` works with a single translation only. This code adds support for multiple locales
|
|
26
|
-
* concurrently. It does this by intercepting the `TRANSLATIONS` property read and returning
|
|
27
|
-
* appropriate translation based on the current locale which is store in the `usEnvDate('local')`.
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
if (!$localizeFn.TRANSLATION_BY_LOCALE) {
|
|
31
|
-
$localizeFn.TRANSLATION_BY_LOCALE = new Map([["", {}]]);
|
|
32
|
-
Object.defineProperty($localize, "TRANSLATIONS", {
|
|
33
|
-
get: function () {
|
|
34
|
-
const locale = getLocale(DEFAULT_LOCALE);
|
|
35
|
-
let translations = $localizeFn.TRANSLATION_BY_LOCALE.get(locale);
|
|
36
|
-
if (!translations) {
|
|
37
|
-
$localizeFn.TRANSLATION_BY_LOCALE.set(locale, (translations = {}));
|
|
38
|
-
}
|
|
39
|
-
return translations;
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Function used to load all translations variants.
|
|
46
|
-
*/
|
|
47
|
-
export function initTranslations() {
|
|
48
|
-
[EN, IT].forEach(({ translations, locale }) => {
|
|
49
|
-
withLocale(locale, () => loadTranslations(translations));
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Function used to examine the request and determine the locale to use.
|
|
55
|
-
*
|
|
56
|
-
* This function is meant to be used with `RenderOptions.locale` property
|
|
57
|
-
*
|
|
58
|
-
* @returns The locale to use which will be stored in the `useEnvData('locale')`.
|
|
59
|
-
*/
|
|
60
|
-
export function extractLang(locale: string): string {
|
|
61
|
-
return locale && $localizeFn.TRANSLATION_BY_LOCALE.has(locale)
|
|
62
|
-
? locale
|
|
63
|
-
: DEFAULT_LOCALE;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Function used to determine the base URL to use for loading the chunks in the browser.
|
|
68
|
-
*
|
|
69
|
-
* The function returns `/build` in dev mode or `/build/<locale>` in prod mode.
|
|
70
|
-
*
|
|
71
|
-
* This function is meant to be used with `RenderOptions.base` property
|
|
72
|
-
*
|
|
73
|
-
* @returns The base URL to use for loading the chunks in the browser.
|
|
74
|
-
*/
|
|
75
|
-
export function extractBase({ serverData }: RenderOptions): string {
|
|
76
|
-
if (import.meta.env.DEV) {
|
|
77
|
-
return `${import.meta.env.BASE_URL}build`;
|
|
78
|
-
} else {
|
|
79
|
-
return `${import.meta.env.BASE_URL}build/` + serverData!.locale;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export function useI18n() {
|
|
84
|
-
if (import.meta.env.DEV) {
|
|
85
|
-
// During development only, load all translations in memory when the app starts on the client.
|
|
86
|
-
|
|
87
|
-
useOnDocument("qinit", $(initTranslations));
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// We always need the translations on the server
|
|
92
|
-
if (import.meta.env.SSR) {
|
|
93
|
-
initTranslations();
|
|
94
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { component$, useStylesScoped$ } from "@qwik.dev/core";
|
|
2
|
-
|
|
3
|
-
export default component$(() => {
|
|
4
|
-
useStylesScoped$(`
|
|
5
|
-
.card {
|
|
6
|
-
width: 300px;
|
|
7
|
-
border-radius: .5rem;
|
|
8
|
-
border: 1px black solid;
|
|
9
|
-
background-color: white;
|
|
10
|
-
color: black;
|
|
11
|
-
margin: auto;
|
|
12
|
-
text-align:center;
|
|
13
|
-
padding: 2rem;
|
|
14
|
-
margin-top: 4rem;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
.links {
|
|
18
|
-
display: flex;
|
|
19
|
-
justify-content: space-evenly;
|
|
20
|
-
padding: 1.25rem 0;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
.link {
|
|
24
|
-
font-weight: 500;
|
|
25
|
-
color: rgb(63 131 248/1);
|
|
26
|
-
}
|
|
27
|
-
`);
|
|
28
|
-
const name = "Qwik";
|
|
29
|
-
return (
|
|
30
|
-
<div class="card">
|
|
31
|
-
<div style="padding-bottom: 1.25rem;">
|
|
32
|
-
<div style="font-weight: 700; font-size: 1.5rem;">{$localize`Hello from ${name}!`}</div>
|
|
33
|
-
</div>
|
|
34
|
-
<div style="padding-bottom: 1.25rem;">
|
|
35
|
-
<div style="font-weight: 700; font-size: 1.0rem;">
|
|
36
|
-
{$localize`Use the following links to change the translation.`}
|
|
37
|
-
<div class="links">
|
|
38
|
-
<a class="link" href="/en/">
|
|
39
|
-
English
|
|
40
|
-
</a>
|
|
41
|
-
<a class="link" href="/it/">
|
|
42
|
-
Italiano
|
|
43
|
-
</a>
|
|
44
|
-
</div>
|
|
45
|
-
<div style="font-size: 1.0rem;">
|
|
46
|
-
{$localize`Translation is performed as part of the build step so translated strings are inlined into the application, there is no need to load or look them up at runtime. However, these advantages mean that the user cannot change the language without refreshing the page.`}
|
|
47
|
-
</div>
|
|
48
|
-
</div>
|
|
49
|
-
</div>
|
|
50
|
-
</div>
|
|
51
|
-
);
|
|
52
|
-
});
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { RequestHandler } from "@qwik.dev/router";
|
|
2
|
-
import { component$, Slot } from "@qwik.dev/core";
|
|
3
|
-
import { extractLang, useI18n } from "~/routes/[locale]/i18n-utils";
|
|
4
|
-
|
|
5
|
-
export const onRequest: RequestHandler = ({ locale, params }) => {
|
|
6
|
-
locale(extractLang(params.locale));
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export default component$(() => {
|
|
10
|
-
useI18n();
|
|
11
|
-
return <Slot />;
|
|
12
|
-
});
|