@koine/i18n 2.0.0-beta.179 → 2.0.0-beta.180
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/adapter-js/generators/setLocale.cjs.js +3 -3
- package/adapter-js/generators/setLocale.esm.js +3 -3
- package/adapter-js/generators/t.cjs.js +1 -1
- package/adapter-js/generators/t.esm.js +1 -1
- package/adapter-js/generators/to.cjs.js +1 -1
- package/adapter-js/generators/to.esm.js +1 -1
- package/adapter-next/generators/router-app/I18nLayout.cjs.js +2 -2
- package/adapter-next/generators/router-app/I18nLayout.esm.js +2 -2
- package/adapter-next/generators/router-app/I18nPage.cjs.js +1 -1
- package/adapter-next/generators/router-app/I18nPage.esm.js +1 -1
- package/adapter-next/generators/router-pages/I18nApp.cjs.js +1 -1
- package/adapter-next/generators/router-pages/I18nApp.esm.js +1 -1
- package/adapter-next/generators/webpack-define.cjs.js +3 -3
- package/adapter-next/generators/webpack-define.esm.js +3 -3
- package/adapter-react/generators/I18nLocaleContext.cjs.js +1 -1
- package/adapter-react/generators/I18nLocaleContext.esm.js +1 -1
- package/adapter-react/generators/I18nTranslate.cjs.js +6 -7
- package/adapter-react/generators/I18nTranslate.d.ts +1 -2
- package/adapter-react/generators/I18nTranslate.esm.js +6 -7
- package/package.json +3 -3
|
@@ -19,14 +19,14 @@ const setGlobalLocale = (e)=>new functions.FunctionsCompiler({
|
|
|
19
19
|
optional: !1
|
|
20
20
|
}
|
|
21
21
|
],
|
|
22
|
-
before: ({ format: e })=>"ts" === e ? `declare
|
|
22
|
+
before: ({ format: e })=>"ts" === e ? `declare globalThis {
|
|
23
23
|
var ${helpers.GLOBAL_I18N_IDENTIFIER}: I18n.Locale;
|
|
24
24
|
}
|
|
25
25
|
` : "",
|
|
26
26
|
comment: {
|
|
27
27
|
internal: !0
|
|
28
28
|
},
|
|
29
|
-
body: `
|
|
29
|
+
body: `globalThis.${helpers.GLOBAL_I18N_IDENTIFIER} = value`,
|
|
30
30
|
implicitReturn: !0
|
|
31
31
|
});
|
|
32
32
|
var c = createAdapter.createGenerator("js", (o)=>({
|
|
@@ -36,7 +36,7 @@ var c = createAdapter.createGenerator("js", (o)=>({
|
|
|
36
36
|
ext: "d.ts",
|
|
37
37
|
index: !1,
|
|
38
38
|
content: ()=>`
|
|
39
|
-
declare
|
|
39
|
+
declare globalThis {
|
|
40
40
|
var ${helpers.GLOBAL_I18N_IDENTIFIER}: import("../types").I18n.Locale;
|
|
41
41
|
}
|
|
42
42
|
`
|
|
@@ -15,14 +15,14 @@ const setGlobalLocale = (e)=>new FunctionsCompiler({
|
|
|
15
15
|
optional: !1
|
|
16
16
|
}
|
|
17
17
|
],
|
|
18
|
-
before: ({ format: e })=>"ts" === e ? `declare
|
|
18
|
+
before: ({ format: e })=>"ts" === e ? `declare globalThis {
|
|
19
19
|
var ${GLOBAL_I18N_IDENTIFIER}: I18n.Locale;
|
|
20
20
|
}
|
|
21
21
|
` : "",
|
|
22
22
|
comment: {
|
|
23
23
|
internal: !0
|
|
24
24
|
},
|
|
25
|
-
body: `
|
|
25
|
+
body: `globalThis.${GLOBAL_I18N_IDENTIFIER} = value`,
|
|
26
26
|
implicitReturn: !0
|
|
27
27
|
});
|
|
28
28
|
var c = createGenerator("js", (o)=>({
|
|
@@ -32,7 +32,7 @@ var c = createGenerator("js", (o)=>({
|
|
|
32
32
|
ext: "d.ts",
|
|
33
33
|
index: !1,
|
|
34
34
|
content: ()=>`
|
|
35
|
-
declare
|
|
35
|
+
declare globalThis {
|
|
36
36
|
var ${GLOBAL_I18N_IDENTIFIER}: import("../types").I18n.Locale;
|
|
37
37
|
}
|
|
38
38
|
`
|
|
@@ -18,7 +18,7 @@ function getTFunction(t, n) {
|
|
|
18
18
|
return i && h.push(d.i18nPluralise), o && ("Primitive" === l ? h.push(d.i18nInterpolateParams) : ("Array" === l || "Object" === l) && h.push(d.i18nInterpolateParamsDeep)), {
|
|
19
19
|
imports: h,
|
|
20
20
|
body: (t)=>{
|
|
21
|
-
let n = y ? "locale = locale ||
|
|
21
|
+
let n = y ? "locale = locale || globalThis." + helpers.GLOBAL_I18N_IDENTIFIER + "; " : "";
|
|
22
22
|
n += "return ";
|
|
23
23
|
let p = "";
|
|
24
24
|
return utils.isPrimitive(r) ? p += f(r, t) : p += function(t, n, r, a) {
|
|
@@ -14,7 +14,7 @@ function getTFunction(t, n) {
|
|
|
14
14
|
return i && h.push(d.i18nPluralise), o && ("Primitive" === l ? h.push(d.i18nInterpolateParams) : ("Array" === l || "Object" === l) && h.push(d.i18nInterpolateParamsDeep)), {
|
|
15
15
|
imports: h,
|
|
16
16
|
body: (t)=>{
|
|
17
|
-
let n = y ? "locale = locale ||
|
|
17
|
+
let n = y ? "locale = locale || globalThis." + GLOBAL_I18N_IDENTIFIER + "; " : "";
|
|
18
18
|
n += "return ";
|
|
19
19
|
let p = "";
|
|
20
20
|
return isPrimitive(r) ? p += f(r, t) : p += function(t, n, r, a) {
|
|
@@ -13,7 +13,7 @@ function getToFunction(e, o) {
|
|
|
13
13
|
let { id: r, params: n } = e, l = function(e, o) {
|
|
14
14
|
let { params: r, pathnames: n, equalValues: l } = e, { defaultLocale: s, single: i } = o, u = !i && !l, d = i ? '""' : "locale", m = r ? ", params" : "";
|
|
15
15
|
return (e)=>{
|
|
16
|
-
let o = u ? "locale = locale ||
|
|
16
|
+
let o = u ? "locale = locale || globalThis." + helpers.GLOBAL_I18N_IDENTIFIER + "; " : "";
|
|
17
17
|
o += "return ";
|
|
18
18
|
let r = "";
|
|
19
19
|
return utils.isString(n) ? r += `formatTo(${d}, "${n}"${m})` : r += `formatTo(${d}, ${function(t, e, { format: o }) {
|
|
@@ -9,7 +9,7 @@ function getToFunction(e, o) {
|
|
|
9
9
|
let { id: r, params: n } = e, l = function(e, o) {
|
|
10
10
|
let { params: r, pathnames: n, equalValues: l } = e, { defaultLocale: s, single: i } = o, u = !i && !l, d = i ? '""' : "locale", m = r ? ", params" : "";
|
|
11
11
|
return (e)=>{
|
|
12
|
-
let o = u ? "locale = locale ||
|
|
12
|
+
let o = u ? "locale = locale || globalThis." + GLOBAL_I18N_IDENTIFIER + "; " : "";
|
|
13
13
|
o += "return ";
|
|
14
14
|
let r = "";
|
|
15
15
|
return isString(n) ? r += `formatTo(${d}, "${n}"${m})` : r += `formatTo(${d}, ${function(t, e, { format: o }) {
|
|
@@ -16,7 +16,7 @@ import React from "react";
|
|
|
16
16
|
import type { Metadata } from "next/types";
|
|
17
17
|
import { i18nRtlLocales } from "@koine/i18n";
|
|
18
18
|
import { getI18nDictionaries } from "../internal/getI18nDictionaries";
|
|
19
|
-
import { I18nTranslateProvider } from "../
|
|
19
|
+
import { I18nTranslateProvider } from "../I18nTranslateProvider";
|
|
20
20
|
import { defaultLocale } from "../defaultLocale";
|
|
21
21
|
import { locales } from "../locales";
|
|
22
22
|
import type { I18n } from "../types";
|
|
@@ -204,7 +204,7 @@ export const createI18nLayout = <
|
|
|
204
204
|
const dir = i18nRtlLocales.includes(locale) ? "rtl" : "ltr";
|
|
205
205
|
const i18nHtmlAttrs = { lang: locale, dir };
|
|
206
206
|
const I18nScript = (
|
|
207
|
-
<script dangerouslySetInnerHTML={{ __html: \`
|
|
207
|
+
<script dangerouslySetInnerHTML={{ __html: \`globalThis.${helpers.GLOBAL_I18N_IDENTIFIER} = "\${locale}";\`}}></script>
|
|
208
208
|
);
|
|
209
209
|
const render = await impl({
|
|
210
210
|
locale,
|
|
@@ -14,7 +14,7 @@ import React from "react";
|
|
|
14
14
|
import type { Metadata } from "next/types";
|
|
15
15
|
import { i18nRtlLocales } from "@koine/i18n";
|
|
16
16
|
import { getI18nDictionaries } from "../internal/getI18nDictionaries";
|
|
17
|
-
import { I18nTranslateProvider } from "../
|
|
17
|
+
import { I18nTranslateProvider } from "../I18nTranslateProvider";
|
|
18
18
|
import { defaultLocale } from "../defaultLocale";
|
|
19
19
|
import { locales } from "../locales";
|
|
20
20
|
import type { I18n } from "../types";
|
|
@@ -202,7 +202,7 @@ export const createI18nLayout = <
|
|
|
202
202
|
const dir = i18nRtlLocales.includes(locale) ? "rtl" : "ltr";
|
|
203
203
|
const i18nHtmlAttrs = { lang: locale, dir };
|
|
204
204
|
const I18nScript = (
|
|
205
|
-
<script dangerouslySetInnerHTML={{ __html: \`
|
|
205
|
+
<script dangerouslySetInnerHTML={{ __html: \`globalThis.${GLOBAL_I18N_IDENTIFIER} = "\${locale}";\`}}></script>
|
|
206
206
|
);
|
|
207
207
|
const render = await impl({
|
|
208
208
|
locale,
|
|
@@ -15,6 +15,7 @@ import React from "react";
|
|
|
15
15
|
import { notFound } from "next/navigation";
|
|
16
16
|
import type { Metadata } from "next/types";
|
|
17
17
|
import { defaultLocale } from "../defaultLocale";
|
|
18
|
+
import { I18nTranslateProvider } from "../I18nTranslateProvider";
|
|
18
19
|
import { isLocale } from "../isLocale";
|
|
19
20
|
import { locales } from "../locales";
|
|
20
21
|
import type { I18n } from "../types";
|
|
@@ -22,7 +23,6 @@ import { getI18nDictionaries } from "../internal/getI18nDictionaries";
|
|
|
22
23
|
import { getI18nMetadata } from "../internal/getI18nMetadata";
|
|
23
24
|
import { I18nMetadataSetter } from "../internal/I18nMetadataSetter";
|
|
24
25
|
import { I18nRouteSetter } from "../internal/I18nRouteSetter";
|
|
25
|
-
import { I18nTranslateProvider } from "../internal/I18nTranslateProvider";
|
|
26
26
|
import { getLocale } from "./getLocale";
|
|
27
27
|
import { I18nLocaleContext } from "./I18nLocaleContext";
|
|
28
28
|
|
|
@@ -13,6 +13,7 @@ import React from "react";
|
|
|
13
13
|
import { notFound } from "next/navigation";
|
|
14
14
|
import type { Metadata } from "next/types";
|
|
15
15
|
import { defaultLocale } from "../defaultLocale";
|
|
16
|
+
import { I18nTranslateProvider } from "../I18nTranslateProvider";
|
|
16
17
|
import { isLocale } from "../isLocale";
|
|
17
18
|
import { locales } from "../locales";
|
|
18
19
|
import type { I18n } from "../types";
|
|
@@ -20,7 +21,6 @@ import { getI18nDictionaries } from "../internal/getI18nDictionaries";
|
|
|
20
21
|
import { getI18nMetadata } from "../internal/getI18nMetadata";
|
|
21
22
|
import { I18nMetadataSetter } from "../internal/I18nMetadataSetter";
|
|
22
23
|
import { I18nRouteSetter } from "../internal/I18nRouteSetter";
|
|
23
|
-
import { I18nTranslateProvider } from "../internal/I18nTranslateProvider";
|
|
24
24
|
import { getLocale } from "./getLocale";
|
|
25
25
|
import { I18nLocaleContext } from "./I18nLocaleContext";
|
|
26
26
|
|
|
@@ -15,7 +15,7 @@ import type { AppProps } from "next/app";
|
|
|
15
15
|
import { type I18nUtils, i18nDefaultMetadata } from "@koine/i18n";
|
|
16
16
|
import { I18nHead } from "./internal/I18nHead";
|
|
17
17
|
import { I18nMetadataProvider } from "./internal/I18nMetadataProvider";
|
|
18
|
-
import { I18nTranslateProvider } from "./
|
|
18
|
+
import { I18nTranslateProvider } from "./I18nTranslateProvider";
|
|
19
19
|
import { defaultLocale } from "./defaultLocale";
|
|
20
20
|
import { I18nEffects } from "./I18nEffects";
|
|
21
21
|
import type { I18n } from "./types";
|
|
@@ -13,7 +13,7 @@ import type { AppProps } from "next/app";
|
|
|
13
13
|
import { type I18nUtils, i18nDefaultMetadata } from "@koine/i18n";
|
|
14
14
|
import { I18nHead } from "./internal/I18nHead";
|
|
15
15
|
import { I18nMetadataProvider } from "./internal/I18nMetadataProvider";
|
|
16
|
-
import { I18nTranslateProvider } from "./
|
|
16
|
+
import { I18nTranslateProvider } from "./I18nTranslateProvider";
|
|
17
17
|
import { defaultLocale } from "./defaultLocale";
|
|
18
18
|
import { I18nEffects } from "./I18nEffects";
|
|
19
19
|
import type { I18n } from "./types";
|
|
@@ -133,7 +133,7 @@ declare global {
|
|
|
133
133
|
var ${k.prefix}: {
|
|
134
134
|
t: GlobalT;
|
|
135
135
|
to: GlobalTo;
|
|
136
|
-
}
|
|
136
|
+
};
|
|
137
137
|
}
|
|
138
138
|
`;
|
|
139
139
|
}
|
|
@@ -154,7 +154,7 @@ module.exports = {
|
|
|
154
154
|
${"internal" === f ? 'console.log("[@koine/i18n]:webpack-define:ctx.module", _ctx.module);' : ""};
|
|
155
155
|
return {
|
|
156
156
|
to: \`(function(routeId, params) {
|
|
157
|
-
const locale =
|
|
157
|
+
const locale = globalThis.${helpers.GLOBAL_I18N_IDENTIFIER};
|
|
158
158
|
${"internal" === f ? 'console.log("[@koine/i18n]:webpack-define-compact:to", { locale });' : ""}
|
|
159
159
|
|
|
160
160
|
const defaultLocale = "${d.defaultLocale}";
|
|
@@ -180,7 +180,7 @@ module.exports = {
|
|
|
180
180
|
return "missing: " + routeId;
|
|
181
181
|
})\`,
|
|
182
182
|
t: \`(function(trace, params) {
|
|
183
|
-
const locale =
|
|
183
|
+
const locale = globalThis.${helpers.GLOBAL_I18N_IDENTIFIER};
|
|
184
184
|
${"internal" === f ? 'console.log("[@koine/i18n]:webpack-define-compact:t", { locale });' : ""}
|
|
185
185
|
|
|
186
186
|
${tPluralise.tPluralise().$outInline()}
|
|
@@ -131,7 +131,7 @@ declare global {
|
|
|
131
131
|
var ${k.prefix}: {
|
|
132
132
|
t: GlobalT;
|
|
133
133
|
to: GlobalTo;
|
|
134
|
-
}
|
|
134
|
+
};
|
|
135
135
|
}
|
|
136
136
|
`;
|
|
137
137
|
}
|
|
@@ -152,7 +152,7 @@ module.exports = {
|
|
|
152
152
|
${"internal" === f ? 'console.log("[@koine/i18n]:webpack-define:ctx.module", _ctx.module);' : ""};
|
|
153
153
|
return {
|
|
154
154
|
to: \`(function(routeId, params) {
|
|
155
|
-
const locale =
|
|
155
|
+
const locale = globalThis.${GLOBAL_I18N_IDENTIFIER};
|
|
156
156
|
${"internal" === f ? 'console.log("[@koine/i18n]:webpack-define-compact:to", { locale });' : ""}
|
|
157
157
|
|
|
158
158
|
const defaultLocale = "${d.defaultLocale}";
|
|
@@ -178,7 +178,7 @@ module.exports = {
|
|
|
178
178
|
return "missing: " + routeId;
|
|
179
179
|
})\`,
|
|
180
180
|
t: \`(function(trace, params) {
|
|
181
|
-
const locale =
|
|
181
|
+
const locale = globalThis.${GLOBAL_I18N_IDENTIFIER};
|
|
182
182
|
${"internal" === f ? 'console.log("[@koine/i18n]:webpack-define-compact:t", { locale });' : ""}
|
|
183
183
|
|
|
184
184
|
${tPluralise().$outInline()}
|
|
@@ -52,7 +52,7 @@ function createServerContext() {
|
|
|
52
52
|
current = value;
|
|
53
53
|
return current;
|
|
54
54
|
},
|
|
55
|
-
get: () =>
|
|
55
|
+
get: () => globalThis.${helpers.GLOBAL_I18N_IDENTIFIER} || current || storage.getStore() || defaultLocale,
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
58
|
|
|
@@ -50,7 +50,7 @@ function createServerContext() {
|
|
|
50
50
|
current = value;
|
|
51
51
|
return current;
|
|
52
52
|
},
|
|
53
|
-
get: () =>
|
|
53
|
+
get: () => globalThis.${GLOBAL_I18N_IDENTIFIER} || current || storage.getStore() || defaultLocale,
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
56
|
|
|
@@ -36,19 +36,18 @@ export const I18nTranslateContext = createContext<I18nTranslateContextValue>({
|
|
|
36
36
|
`
|
|
37
37
|
},
|
|
38
38
|
I18nTranslateProvider: {
|
|
39
|
-
dir: createAdapter.createGenerator.dirs.internal,
|
|
40
39
|
name: "I18nTranslateProvider",
|
|
41
40
|
ext: "tsx",
|
|
42
|
-
index: !
|
|
41
|
+
index: !0,
|
|
43
42
|
content: ()=>`
|
|
44
43
|
"use client";
|
|
45
44
|
|
|
46
45
|
import React, { useContext } from "react";
|
|
47
|
-
import {
|
|
48
|
-
import {
|
|
49
|
-
import
|
|
50
|
-
import {
|
|
51
|
-
import {
|
|
46
|
+
import { I18nTranslateContext } from "./internal/I18nTranslateContext";
|
|
47
|
+
import { setGlobalLocale } from "./internal/setGlobalLocale";
|
|
48
|
+
import { createT } from "./createT";
|
|
49
|
+
import { defaultLocale } from "./defaultLocale";
|
|
50
|
+
import type { I18n } from "./types";
|
|
52
51
|
|
|
53
52
|
export type I18nTranslateProviderProps = React.PropsWithChildren<{
|
|
54
53
|
locale?: I18n.Locale;
|
|
@@ -7,10 +7,9 @@ declare const _default: (data: import("../../compiler").I18nCompiler.DataCode<"r
|
|
|
7
7
|
content: () => string;
|
|
8
8
|
};
|
|
9
9
|
I18nTranslateProvider: {
|
|
10
|
-
dir: string;
|
|
11
10
|
name: string;
|
|
12
11
|
ext: "tsx";
|
|
13
|
-
index:
|
|
12
|
+
index: true;
|
|
14
13
|
content: () => string;
|
|
15
14
|
};
|
|
16
15
|
useLocale: {
|
|
@@ -34,19 +34,18 @@ export const I18nTranslateContext = createContext<I18nTranslateContextValue>({
|
|
|
34
34
|
`
|
|
35
35
|
},
|
|
36
36
|
I18nTranslateProvider: {
|
|
37
|
-
dir: createGenerator.dirs.internal,
|
|
38
37
|
name: "I18nTranslateProvider",
|
|
39
38
|
ext: "tsx",
|
|
40
|
-
index: !
|
|
39
|
+
index: !0,
|
|
41
40
|
content: ()=>`
|
|
42
41
|
"use client";
|
|
43
42
|
|
|
44
43
|
import React, { useContext } from "react";
|
|
45
|
-
import {
|
|
46
|
-
import {
|
|
47
|
-
import
|
|
48
|
-
import {
|
|
49
|
-
import {
|
|
44
|
+
import { I18nTranslateContext } from "./internal/I18nTranslateContext";
|
|
45
|
+
import { setGlobalLocale } from "./internal/setGlobalLocale";
|
|
46
|
+
import { createT } from "./createT";
|
|
47
|
+
import { defaultLocale } from "./defaultLocale";
|
|
48
|
+
import type { I18n } from "./types";
|
|
50
49
|
|
|
51
50
|
export type I18nTranslateProviderProps = React.PropsWithChildren<{
|
|
52
51
|
locale?: I18n.Locale;
|
package/package.json
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
"node": "^14.18.0 || >=16.0.0"
|
|
6
6
|
},
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@koine/node": "2.0.0-beta.
|
|
9
|
-
"@koine/utils": "2.0.0-beta.
|
|
8
|
+
"@koine/node": "2.0.0-beta.180",
|
|
9
|
+
"@koine/utils": "2.0.0-beta.180",
|
|
10
10
|
"comment-json": "^4.2.4",
|
|
11
11
|
"consola": "^3.2.3",
|
|
12
12
|
"glob": "^11.0.0",
|
|
@@ -110,5 +110,5 @@
|
|
|
110
110
|
"module": "./index.esm.js",
|
|
111
111
|
"main": "./index.cjs.js",
|
|
112
112
|
"types": "./index.esm.d.ts",
|
|
113
|
-
"version": "2.0.0-beta.
|
|
113
|
+
"version": "2.0.0-beta.180"
|
|
114
114
|
}
|