@verbaly/next 0.40.0 → 0.41.0
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/client.js +3 -1
- package/dist/client.js.map +1 -1
- package/package.json +6 -6
package/dist/client.js
CHANGED
|
@@ -28,11 +28,13 @@ function useSwitchLocale() {
|
|
|
28
28
|
const instance = useVerbaly$1();
|
|
29
29
|
const router = useRouter();
|
|
30
30
|
return useCallback(async (locale, options) => {
|
|
31
|
+
const routed = options?.routing !== void 0 && options.routing !== "no-prefix";
|
|
31
32
|
await switchLocale(instance, locale, {
|
|
32
33
|
cookie: requestOptions?.cookie,
|
|
34
|
+
navigate: (path) => router.push(path),
|
|
33
35
|
...options
|
|
34
36
|
});
|
|
35
|
-
router.refresh();
|
|
37
|
+
if (!routed) router.refresh();
|
|
36
38
|
}, [instance, router]);
|
|
37
39
|
}
|
|
38
40
|
//#endregion
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","names":["ReactVerbalyProvider","useVerbaly"],"sources":["../src/client.ts"],"sourcesContent":["'use client';\n\nimport { useRouter } from 'next/navigation';\nimport {\n createElement,\n useCallback,\n useEffect,\n useState,\n type ReactElement,\n type ReactNode,\n} from 'react';\nimport { VerbalyProvider as ReactVerbalyProvider, useVerbaly } from '@verbaly/react';\nimport { switchLocale, type SwitchLocaleOptions } from 'verbaly';\nimport { createInstance, requestOptions, sourceLocale } from 'virtual:verbaly';\nimport type { VerbalyProviderProps as SerializableProps } from './server';\n\nexport { Trans, useLocale, useT, useVerbaly } from '@verbaly/react';\n\n// the serializable props getVerbalyProps() produces, plus the client-side children\nexport interface VerbalyProviderProps extends SerializableProps {\n children?: ReactNode;\n}\n\nexport function VerbalyProvider(props: VerbalyProviderProps): ReactElement {\n const [instance] = useState(() => {\n const created = createInstance({ locale: props.locale });\n if (props.messages && props.locale !== sourceLocale) {\n created.addMessages(props.locale, props.messages);\n }\n return created;\n });\n\n // server changed the locale out-of-band (cookie edit + refresh): follow it\n useEffect(() => {\n if (props.locale === instance.locale) return;\n if (props.messages) {\n instance.addMessages(props.locale, props.messages);\n instance.setLocale(props.locale);\n } else {\n void instance.loadLocale(props.locale).then(() => instance.setLocale(props.locale));\n }\n }, [props.locale, props.messages, instance]);\n\n return createElement(ReactVerbalyProvider, { instance }, props.children);\n}\n\n// core switchLocale
|
|
1
|
+
{"version":3,"file":"client.js","names":["ReactVerbalyProvider","useVerbaly"],"sources":["../src/client.ts"],"sourcesContent":["'use client';\n\nimport { useRouter } from 'next/navigation';\nimport {\n createElement,\n useCallback,\n useEffect,\n useState,\n type ReactElement,\n type ReactNode,\n} from 'react';\nimport { VerbalyProvider as ReactVerbalyProvider, useVerbaly } from '@verbaly/react';\nimport { switchLocale, type SwitchLocaleOptions } from 'verbaly';\nimport { createInstance, requestOptions, sourceLocale } from 'virtual:verbaly';\nimport type { VerbalyProviderProps as SerializableProps } from './server';\n\nexport { Trans, useLocale, useT, useVerbaly } from '@verbaly/react';\n\n// the serializable props getVerbalyProps() produces, plus the client-side children\nexport interface VerbalyProviderProps extends SerializableProps {\n children?: ReactNode;\n}\n\nexport function VerbalyProvider(props: VerbalyProviderProps): ReactElement {\n const [instance] = useState(() => {\n const created = createInstance({ locale: props.locale });\n if (props.messages && props.locale !== sourceLocale) {\n created.addMessages(props.locale, props.messages);\n }\n return created;\n });\n\n // server changed the locale out-of-band (cookie edit + refresh): follow it\n useEffect(() => {\n if (props.locale === instance.locale) return;\n if (props.messages) {\n instance.addMessages(props.locale, props.messages);\n instance.setLocale(props.locale);\n } else {\n void instance.loadLocale(props.locale).then(() => instance.setLocale(props.locale));\n }\n }, [props.locale, props.messages, instance]);\n\n return createElement(ReactVerbalyProvider, { instance }, props.children);\n}\n\n// core switchLocale in whichever mode the app is in, with the app router as the navigation\nexport function useSwitchLocale(): (\n locale: string,\n options?: SwitchLocaleOptions,\n) => Promise<void> {\n const instance = useVerbaly();\n const router = useRouter();\n return useCallback(\n async (locale, options) => {\n const routed = options?.routing !== undefined && options.routing !== 'no-prefix';\n await switchLocale(instance, locale, {\n cookie: requestOptions?.cookie,\n // a full load would throw away the react tree the app router exists to keep\n navigate: (path) => router.push(path),\n ...options,\n });\n // the navigation already re-rendered the tree, so refreshing on top of it is a second render\n if (!routed) router.refresh();\n },\n [instance, router],\n );\n}\n"],"mappings":";;;;;;;AAuBA,SAAgB,gBAAgB,OAA2C;CACzE,MAAM,CAAC,YAAY,eAAe;EAChC,MAAM,UAAU,eAAe,EAAE,QAAQ,MAAM,OAAO,CAAC;EACvD,IAAI,MAAM,YAAY,MAAM,WAAW,cACrC,QAAQ,YAAY,MAAM,QAAQ,MAAM,QAAQ;EAElD,OAAO;CACT,CAAC;CAGD,gBAAgB;EACd,IAAI,MAAM,WAAW,SAAS,QAAQ;EACtC,IAAI,MAAM,UAAU;GAClB,SAAS,YAAY,MAAM,QAAQ,MAAM,QAAQ;GACjD,SAAS,UAAU,MAAM,MAAM;EACjC,OACE,SAAc,WAAW,MAAM,MAAM,CAAC,CAAC,WAAW,SAAS,UAAU,MAAM,MAAM,CAAC;CAEtF,GAAG;EAAC,MAAM;EAAQ,MAAM;EAAU;CAAQ,CAAC;CAE3C,OAAO,cAAcA,mBAAsB,EAAE,SAAS,GAAG,MAAM,QAAQ;AACzE;AAGA,SAAgB,kBAGG;CACjB,MAAM,WAAWC,aAAW;CAC5B,MAAM,SAAS,UAAU;CACzB,OAAO,YACL,OAAO,QAAQ,YAAY;EACzB,MAAM,SAAS,SAAS,YAAY,KAAA,KAAa,QAAQ,YAAY;EACrE,MAAM,aAAa,UAAU,QAAQ;GACnC,QAAQ,gBAAgB;GAExB,WAAW,SAAS,OAAO,KAAK,IAAI;GACpC,GAAG;EACL,CAAC;EAED,IAAI,CAAC,QAAQ,OAAO,QAAQ;CAC9B,GACA,CAAC,UAAU,MAAM,CACnB;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verbaly/next",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.41.0",
|
|
4
4
|
"description": "Next.js integration for Verbaly: App Router/RSC with per-request locale negotiation, Turbopack and webpack support, flash-free hydration.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"i18n",
|
|
@@ -64,13 +64,13 @@
|
|
|
64
64
|
"access": "public"
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@verbaly/compiler": "^0.
|
|
67
|
+
"@verbaly/compiler": "^0.41.0"
|
|
68
68
|
},
|
|
69
69
|
"peerDependencies": {
|
|
70
70
|
"next": "^15.0.0 || ^16.0.0",
|
|
71
71
|
"react": "^18.0.0 || ^19.0.0",
|
|
72
|
-
"@verbaly/react": "^0.
|
|
73
|
-
"verbaly": "^0.
|
|
72
|
+
"@verbaly/react": "^0.41.0",
|
|
73
|
+
"verbaly": "^0.41.0"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
76
|
"@types/react": "^19.2.18",
|
|
@@ -79,8 +79,8 @@
|
|
|
79
79
|
"next": "^16.3.3",
|
|
80
80
|
"react": "^19.2.8",
|
|
81
81
|
"react-dom": "^19.2.8",
|
|
82
|
-
"verbaly": "^0.
|
|
83
|
-
"
|
|
82
|
+
"@verbaly/react": "^0.41.0",
|
|
83
|
+
"verbaly": "^0.41.0"
|
|
84
84
|
},
|
|
85
85
|
"scripts": {
|
|
86
86
|
"build": "tsdown",
|