@koine/i18n 2.0.0-beta.45 → 2.0.0-beta.47
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/action.cjs.js +4 -2
- package/action.d.ts +2 -2
- package/action.esm.js +2 -3
- package/adapter-js/code/routes.d.ts +1 -1
- package/adapter-js/code/routesSlim.d.ts +1 -1
- package/adapter-js/code/tFns.d.ts +1 -1
- package/adapter-js/code/tInterpolateParams.d.ts +1 -1
- package/adapter-js/code/toFns.d.ts +1 -1
- package/adapter-js/code/types.d.ts +1 -1
- package/adapter-next/code/next-redirects.d.ts +1 -3
- package/adapter-next/code/next-rewrites.d.ts +1 -3
- package/adapter-next/plugin-legacy.d.ts +4 -13
- package/adapter-next/plugin.d.ts +10 -3
- package/adapter-next/redirects.d.ts +3 -0
- package/adapter-next/rewrites.d.ts +3 -0
- package/adapter-next/{code/transformPathname.d.ts → transformPathname.d.ts} +1 -1
- package/api.cjs.js +37 -140
- package/api.esm.js +33 -138
- package/compiler/api.d.ts +10 -6
- package/compiler/code/data.d.ts +1 -4
- package/compiler/code/generate.d.ts +1 -1
- package/compiler/code/write.d.ts +1 -7
- package/compiler/config.d.ts +1 -5
- package/compiler/input/data-local.d.ts +9 -0
- package/compiler/input/data-remote.d.ts +10 -3
- package/compiler/input/data.d.ts +6 -9
- package/compiler/input/index.d.ts +2 -1
- package/compiler/input/write.d.ts +2 -2
- package/compiler/summary/index.d.ts +1 -1
- package/compiler/types.d.ts +4 -9
- package/compiler.cjs.js +7 -11
- package/compiler.d.ts +0 -3
- package/compiler.esm.js +3 -2
- package/next.cjs.js +28 -4
- package/next.d.ts +2 -2
- package/next.esm.js +10 -4
- package/package.json +4 -6
- package/write.cjs.js +3 -10
- package/write.esm.js +3 -8
- package/adapter-next/getPathRedirect.d.ts +0 -13
- package/adapter-next/getPathRewrite.d.ts +0 -13
- package/compiler/input/data-fs.d.ts +0 -3
package/action.cjs.js
CHANGED
|
@@ -3,13 +3,15 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var write = require('./write.cjs.js');
|
|
6
|
+
require('next/dist/shared/lib/utils');
|
|
7
|
+
require('node:https');
|
|
8
|
+
require('minimatch');
|
|
6
9
|
require('@koine/utils');
|
|
7
10
|
require('node:path');
|
|
8
11
|
require('@koine/node');
|
|
9
12
|
require('node:fs/promises');
|
|
10
13
|
require('glob');
|
|
11
|
-
require('node:https');
|
|
12
14
|
|
|
13
|
-
let i18nAction=async
|
|
15
|
+
let i18nAction=async p=>{let{cwd:m,source:e=".",url:l,output:{input:a,summaryJson:c,summaryMarkdown:n},...s}=p,f=await write.getInputDataLocal({cwd:m,source:e,...s}),w=[];if(a&&w.push(write.writeInput({cwd:m,output:a},f)),c||n){let t=write.getSummaryData(write.getConfig(f),{sourceUrl:l},f);w.push(write.writeSummary({cwd:m,outputJson:c,outputMarkdown:n,sourceUrl:l},t));}return await Promise.all(w),f};
|
|
14
16
|
|
|
15
17
|
exports.i18nAction = i18nAction;
|
package/action.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { type InputDataOptions } from "./compiler/input";
|
|
1
2
|
import { type SummaryDataOptions } from "./compiler/summary";
|
|
2
|
-
type I18nActionOptions = {
|
|
3
|
-
cwd: string;
|
|
3
|
+
type I18nActionOptions = Partial<InputDataOptions> & {
|
|
4
4
|
url: SummaryDataOptions["sourceUrl"];
|
|
5
5
|
output: {
|
|
6
6
|
input?: string;
|
package/action.esm.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { g as
|
|
1
|
+
import { g as getInputDataLocal, w as writeInput, a as getSummaryData, b as getConfig, c as writeSummary } from './write.esm.js';
|
|
2
2
|
import '@koine/utils';
|
|
3
3
|
import 'node:path';
|
|
4
4
|
import '@koine/node';
|
|
5
5
|
import 'node:fs/promises';
|
|
6
6
|
import 'glob';
|
|
7
|
-
import 'node:https';
|
|
8
7
|
|
|
9
|
-
let i18nAction=async
|
|
8
|
+
let i18nAction=async p=>{let{cwd:m,source:e=".",url:l,output:{input:a,summaryJson:c,summaryMarkdown:n},...s}=p,f=await getInputDataLocal({cwd:m,source:e,...s}),w=[];if(a&&w.push(writeInput({cwd:m,output:a},f)),c||n){let t=getSummaryData(getConfig(f),{sourceUrl:l},f);w.push(writeSummary({cwd:m,outputJson:c,outputMarkdown:n,sourceUrl:l},t));}return await Promise.all(w),f};
|
|
10
9
|
|
|
11
10
|
export { i18nAction };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { I18nCompiler } from "../../compiler";
|
|
2
|
-
declare const _default: ({ config,
|
|
2
|
+
declare const _default: ({ config, input, routes }: I18nCompiler.AdapterArg) => string;
|
|
3
3
|
export default _default;
|
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
import type { I18nCompiler } from "../../compiler";
|
|
2
|
-
|
|
3
|
-
export declare function getRedirects(config: I18nCompiler.Config, routes: I18nCompiler.DataRoutes, localeParam?: string, permanent?: boolean): Redirect[];
|
|
4
|
-
declare const _default: ({ config, data }: I18nCompiler.AdapterArg) => string;
|
|
2
|
+
declare const _default: ({ config, routes }: I18nCompiler.AdapterArg) => string;
|
|
5
3
|
export default _default;
|
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
import type { I18nCompiler } from "../../compiler";
|
|
2
|
-
|
|
3
|
-
export declare function getRewrites(config: I18nCompiler.Config, routes: I18nCompiler.DataRoutes, localeParam?: string): Rewrite[];
|
|
4
|
-
declare const _default: ({ config, data }: I18nCompiler.AdapterArg) => string;
|
|
2
|
+
declare const _default: ({ config, routes }: I18nCompiler.AdapterArg) => string;
|
|
5
3
|
export default _default;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { NextConfig } from "next";
|
|
2
2
|
import type { Redirect as _Redirect, Rewrite as _Rewrite } from "next/dist/lib/load-custom-routes";
|
|
3
|
-
|
|
3
|
+
type Redirect = Omit<_Redirect, "locale"> & {
|
|
4
4
|
locale?: boolean;
|
|
5
5
|
};
|
|
6
|
-
|
|
6
|
+
type Rewrite = Omit<_Rewrite, "locale"> & {
|
|
7
7
|
locale?: boolean;
|
|
8
8
|
};
|
|
9
9
|
type Route = string | {
|
|
@@ -18,22 +18,13 @@ type ConfigI18nOptions = {
|
|
|
18
18
|
hideDefaultLocaleInUrl?: boolean;
|
|
19
19
|
localeParam?: string;
|
|
20
20
|
};
|
|
21
|
-
type
|
|
22
|
-
routes: Routes;
|
|
23
|
-
debug?: boolean;
|
|
24
|
-
permanent?: boolean;
|
|
25
|
-
};
|
|
26
|
-
type GetRedirectsOptions = Options;
|
|
27
|
-
export declare function getRedirects(arg: GetRedirectsOptions): Redirect[];
|
|
28
|
-
type GetRewritesOptions = Options;
|
|
29
|
-
export declare function getRewrites(arg: GetRewritesOptions): Rewrite[];
|
|
30
|
-
export type WithI18nLegacy = {
|
|
21
|
+
export type WithI18nLegacyOptions = {
|
|
31
22
|
routes?: Routes;
|
|
32
23
|
permanent?: boolean;
|
|
33
24
|
debug?: boolean;
|
|
34
25
|
i18n: ConfigI18nOptions;
|
|
35
26
|
};
|
|
36
|
-
export declare let withI18nLegacy: ({ routes, permanent, i18n, debug }?:
|
|
27
|
+
export declare let withI18nLegacy: ({ routes, permanent, i18n, debug }?: WithI18nLegacyOptions) => (customNextConfig: NextConfig) => NextConfig | {
|
|
37
28
|
redirects(): Promise<Redirect[]>;
|
|
38
29
|
rewrites(): Promise<{
|
|
39
30
|
beforeFiles: Rewrite[];
|
package/adapter-next/plugin.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import type { NextConfig } from "next";
|
|
2
|
-
import type
|
|
3
|
-
export type
|
|
4
|
-
|
|
2
|
+
import { type I18nCompilerOptions } from "../compiler";
|
|
3
|
+
export type WithI18nOptions = NextConfig & {
|
|
4
|
+
i18nCompiler?: I18nCompilerOptions & {
|
|
5
|
+
appRouterLocaleParamName?: string;
|
|
6
|
+
permanentRedirects?: boolean;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
type NextConfigFn = (phase: string, context?: any) => Promise<NextConfig> | NextConfig;
|
|
10
|
+
export declare let withI18n: (nextConfig?: WithI18nOptions) => NextConfigFn;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { Redirect as _Redirect } from "next/dist/lib/load-custom-routes";
|
|
2
|
+
import type { I18nCompiler } from "../compiler";
|
|
3
|
+
export declare let getRedirects: (config: I18nCompiler.Config, routes: I18nCompiler.DataRoutes, localeParam?: string, permanent?: boolean) => _Redirect[];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { I18nCompiler } from "
|
|
1
|
+
import type { I18nCompiler } from "../compiler";
|
|
2
2
|
export declare function transformPathname(route: I18nCompiler.DataRoute, rawPathnameOrTemplate: string): string;
|
package/api.cjs.js
CHANGED
|
@@ -3,11 +3,15 @@
|
|
|
3
3
|
var node_fs = require('node:fs');
|
|
4
4
|
var node_path = require('node:path');
|
|
5
5
|
var node = require('@koine/node');
|
|
6
|
-
var utils = require('@koine/utils');
|
|
7
|
-
var formatRoutePathname = require('./formatRoutePathname.cjs.js');
|
|
6
|
+
var utils$1 = require('@koine/utils');
|
|
8
7
|
var t$4 = require('typescript');
|
|
8
|
+
var formatRoutePathname = require('./formatRoutePathname.cjs.js');
|
|
9
9
|
var minimatch = require('minimatch');
|
|
10
10
|
var write = require('./write.cjs.js');
|
|
11
|
+
var utils = require('next/dist/shared/lib/utils');
|
|
12
|
+
var node_https = require('node:https');
|
|
13
|
+
require('node:fs/promises');
|
|
14
|
+
require('glob');
|
|
11
15
|
|
|
12
16
|
function _interopNamespace(e) {
|
|
13
17
|
if (e && e.__esModule) return e;
|
|
@@ -29,7 +33,11 @@ function _interopNamespace(e) {
|
|
|
29
33
|
|
|
30
34
|
var t__namespace = /*#__PURE__*/_interopNamespace(t$4);
|
|
31
35
|
|
|
32
|
-
|
|
36
|
+
let getInputDataRemote=async r=>new Promise((o,a)=>{let{ignore:l=[],source:n}=r,s=n.startsWith("https://raw.githubusercontent.com"),i="",c=node_https.request(n,s?{}:{headers:{Accept:"application/json"}},e=>{e.setEncoding("utf8"),e.on("data",e=>{i+=e;}),e.on("end",()=>{try{let e=s?JSON.parse(i):i;o({...e,localesFolders:l.length?e.localesFolders.filter(e=>l.every(r=>!minimatch.minimatch(e,r))):e.localesFolders,translationFiles:l.length?e.translationFiles.filter(e=>l.every(r=>!minimatch.minimatch(e.path,r))):e.translationFiles});}catch(e){throw Error(`Failed to parse JSON from ${n}`)}});});c.on("error",e=>{console.error(e),a("");}),c.end();});
|
|
37
|
+
|
|
38
|
+
let getInputData=async e=>{let{source:o}=e;return utils.isAbsoluteUrl(o)?await getInputDataRemote(e):await write.getInputDataLocal(e)};
|
|
39
|
+
|
|
40
|
+
var e$3 = (({config:e})=>`
|
|
33
41
|
import { locales } from "./locales";
|
|
34
42
|
import { defaultLocale } from "./defaultLocale";
|
|
35
43
|
|
|
@@ -52,7 +60,7 @@ export const defaultLocale: I18n.Locale = "${e.defaultLocale}";
|
|
|
52
60
|
export default defaultLocale;
|
|
53
61
|
`);
|
|
54
62
|
|
|
55
|
-
var o$
|
|
63
|
+
var o$3 = (()=>`
|
|
56
64
|
import { locales } from "./locales";
|
|
57
65
|
import { to } from "./to";
|
|
58
66
|
import type { I18n } from "./types";
|
|
@@ -139,13 +147,13 @@ export const isLocale = (payload: any): payload is I18n.Locale => locales.includ
|
|
|
139
147
|
export default isLocale;
|
|
140
148
|
`);
|
|
141
149
|
|
|
142
|
-
var m$
|
|
150
|
+
var m$3 = (({config:e})=>{let l=`[${e.locales.map(e=>`"${e}"`).join(", ")}]`;return `
|
|
143
151
|
export const locales = ${l} as const;
|
|
144
152
|
|
|
145
153
|
export default locales;
|
|
146
154
|
`});
|
|
147
155
|
|
|
148
|
-
var a$
|
|
156
|
+
var a$4 = (()=>`
|
|
149
157
|
/**
|
|
150
158
|
* Convert a URL like pathname to a "named route"
|
|
151
159
|
* E.g. it transforms:
|
|
@@ -160,13 +168,13 @@ export const pathnameToRouteId = (pathname: string) =>
|
|
|
160
168
|
export default pathnameToRouteId;
|
|
161
169
|
`);
|
|
162
170
|
|
|
163
|
-
var r$
|
|
171
|
+
var r$2 = (({routes:t})=>{let e=JSON.stringify(Object.fromEntries(Object.entries(t).map(([t,{pathnames:e}])=>[t,e])),null,2);return `
|
|
164
172
|
export const routes = ${e} as const;
|
|
165
173
|
|
|
166
174
|
export default routes;
|
|
167
175
|
`});
|
|
168
176
|
|
|
169
|
-
var i$3 = (({
|
|
177
|
+
var i$3 = (({routes:t})=>{let e=JSON.stringify(Object.fromEntries(Object.entries(t).map(([t,{optimizedPathnames:e,pathnames:r}])=>[t,e||r])),null,2);return `
|
|
170
178
|
export const routesSlim = ${e} as const;
|
|
171
179
|
|
|
172
180
|
export default routesSlim;
|
|
@@ -174,22 +182,22 @@ export default routesSlim;
|
|
|
174
182
|
|
|
175
183
|
let dataParamsToTsInterfaceBody=e=>Object.keys(e).reduce((r,t)=>{let a=e[t],s="";switch(a){case"number":s="number";break;case"string":s="string";break;default:s="string | number";}return r.push(`${t}: ${s};`),r},[]).join(" ");
|
|
176
184
|
|
|
177
|
-
let i$2=e=>utils.isString(e)||utils.isNumber(e)?`"${e}"`:utils.isBoolean(e)?`${e}`:utils.isArray(e)?JSON.stringify(e):`(${JSON.stringify(e)})`,p$1=(t,r)=>utils.areEqual(t,r),m$
|
|
185
|
+
let i$2=e=>utils$1.isString(e)||utils$1.isNumber(e)?`"${e}"`:utils$1.isBoolean(e)?`${e}`:utils$1.isArray(e)?JSON.stringify(e):`(${JSON.stringify(e)})`,p$1=(t,r)=>utils$1.areEqual(t,r),m$2=(e,r)=>{let{defaultLocale:l}=e,o="";return utils$1.forin(r,(e,t)=>{e===l||p$1(t,r[l])||(o+=`locale === "${e}" ? ${i$2(t)} : `);}),o+=i$2(r[l])};var s$4 = (({config:e,options:r,translations:l})=>{let o=`
|
|
178
186
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
179
187
|
/* eslint-disable prefer-const */
|
|
180
188
|
import type { I18n } from "./types";
|
|
181
189
|
import { tInterpolateParams } from "./tInterpolateParams";
|
|
182
190
|
|
|
183
|
-
`;return utils.forin(
|
|
184
|
-
`;}),
|
|
191
|
+
`;return utils$1.forin(l,(t,{values:l,params:n,plural:p})=>{let $=`${r.translations.fnsPrefix}${t}`;n&&p&&(n.count="number");let f=[n?`params: { ${dataParamsToTsInterfaceBody(n)} }`:"","locale?: I18n.Locale"].filter(Boolean).join(", ");o+=`export let ${$} = (${f}) => `;let u="";utils$1.isPrimitive(l)?u+=i$2(l):u+=m$2(e,l),u=n?`tInterpolateParams(${u}, params);`:`${u};`,o+=u+`
|
|
192
|
+
`;}),o});
|
|
185
193
|
|
|
186
|
-
let
|
|
194
|
+
let a$3=a=>a.split("").map(a=>`\\${a}`).join("");var f$1 = (({options:e})=>{let{start:t,end:r}=e.translations.dynamicDelimiters;return `
|
|
187
195
|
export let tInterpolateParams = (
|
|
188
196
|
value: string,
|
|
189
197
|
params?: object,
|
|
190
198
|
) =>
|
|
191
199
|
params ? value.replace(
|
|
192
|
-
/${
|
|
200
|
+
/${a$3(t)}(.*?)${a$3(r)}/g,
|
|
193
201
|
(_, key) =>
|
|
194
202
|
params[key.trim() as keyof typeof params] + "",
|
|
195
203
|
) : value;
|
|
@@ -227,11 +235,11 @@ export function to<TRoute extends I18n.RouteId>(
|
|
|
227
235
|
export default to;
|
|
228
236
|
`);
|
|
229
237
|
|
|
230
|
-
let r$
|
|
238
|
+
let r$1=(t,e)=>{let{defaultLocale:r}=t,l="";return utils$1.forin(e,(t,o)=>{t!==r&&o!==e[r]&&(l+=`locale === "${t}" ? "${o}" : `);}),l+='"'+e[r]+'"'};var d$2 = (({config:l,routes:a})=>{let m=1===l.locales.length,$=`
|
|
231
239
|
import { toFormat } from "./toFormat";
|
|
232
240
|
import type { I18n } from "./types";
|
|
233
241
|
|
|
234
|
-
`;return utils.forin(a
|
|
242
|
+
`;return utils$1.forin(a,(o,{pathnames:a,params:n})=>{let p=`to_${utils$1.changeCaseCamel(o)}`,i=`I18n.RouteParams["${o}"]`,s=[n?`params: ${i}`:"",m?"":"locale?: I18n.Locale"].filter(Boolean).join(", "),c=m?'""':"locale",f=n?", params":"";$+=`export let ${p} = (${s}) => `,utils$1.isString(a)?$+=`toFormat(${c}, "${a}"${f});`:$+=`toFormat(${c}, ${r$1(l,a)}${f});`,$+=`
|
|
235
243
|
`;}),$});
|
|
236
244
|
|
|
237
245
|
var p = (({config:a})=>`
|
|
@@ -291,9 +299,9 @@ export function toFormat(
|
|
|
291
299
|
export default toFormat;
|
|
292
300
|
`);
|
|
293
301
|
|
|
294
|
-
let s$3=["zero","one","two","few","many","other"],a$2="other";let isPluralSuffix=e=>s$3.includes(e)||utils.isNumericLiteral(e);let removePluralSuffix=e=>{let[l]=utils.splitReverse(e,"_");return l?e.replace(`_${l}`,""):e};let isPluralKey=e=>{let[l]=utils.splitReverse(e,"_");return isPluralSuffix(l)};let i$1=e=>{let l={};return e.forEach(e=>{let[r]=utils.split(e,"_");l[r]=l[r]||[],l[r].push(e);}),l};let transformKeysForPlurals=l=>{let r=l.filter(isPluralKey);if(r.length){let t=[...l];return utils.forin(i$1(r),(e,r)=>{l.includes(e)||t.push(e),r.forEach(e=>{l.includes(e)&&(t=t.filter(l=>l!==e));});}),t}return l};let hasPlurals=e=>Object.keys(e).includes(a$2);let hasOnlyPluralKeys=e=>!!hasPlurals(e)&&0===pickNonPluralKeys(e).length;let pickNonPluralKeys=e=>Object.keys(e).filter(e=>!isPluralSuffix(e));let pickNonPluralValue=e=>hasPlurals(e)?utils.objectPick(e,pickNonPluralKeys(e)):e;
|
|
302
|
+
let s$3=["zero","one","two","few","many","other"],a$2="other";let isPluralSuffix=e=>s$3.includes(e)||utils$1.isNumericLiteral(e);let removePluralSuffix=e=>{let[l]=utils$1.splitReverse(e,"_");return l?e.replace(`_${l}`,""):e};let isPluralKey=e=>{let[l]=utils$1.splitReverse(e,"_");return isPluralSuffix(l)};let i$1=e=>{let l={};return e.forEach(e=>{let[r]=utils$1.split(e,"_");l[r]=l[r]||[],l[r].push(e);}),l};let transformKeysForPlurals=l=>{let r=l.filter(isPluralKey);if(r.length){let t=[...l];return utils$1.forin(i$1(r),(e,r)=>{l.includes(e)||t.push(e),r.forEach(e=>{l.includes(e)&&(t=t.filter(l=>l!==e));});}),t}return l};let hasPlurals=e=>Object.keys(e).includes(a$2);let hasOnlyPluralKeys=e=>!!hasPlurals(e)&&0===pickNonPluralKeys(e).length;let pickNonPluralKeys=e=>Object.keys(e).filter(e=>!isPluralSuffix(e));let pickNonPluralValue=e=>hasPlurals(e)?utils$1.objectPick(e,pickNonPluralKeys(e)):e;
|
|
295
303
|
|
|
296
|
-
let c$1=(e,a)=>{if(!utils.isArray(a)&&utils.isObject(a)){if(hasOnlyPluralKeys(a))return `"${e}": string;`;if(hasPlurals(a))return `"${e}": string | ${h(pickNonPluralValue(a))}`}return `"${e}": ${h(a)}`},h=e=>{let r="",i="";if(utils.isBoolean(e)?i="boolean":utils.isString(e)&&(i="string"),i)r+=i+";";else if(e){if(utils.isArray(e)){let t=e[0];r+=`${h(t)}[];`;}else if(utils.isObject(e)){r+="{";let t=transformKeysForPlurals(Object.keys(e));for(let a=0;a<t.length;a++){let n=t[a],s=e[n]||"";r+=c$1(n,s);}r+="};";}}else r+="";return (r=r.replace(/;\[\];/g,"[];")).replace(/;+/g,";")},T=(e,t)=>{let{translationFiles:a}=t,{defaultLocale:n}=e,s=a.filter(e=>e.locale===n),r=[];for(let e=0;e<s.length;e++){let{path:t,data:a}=s[e],n=t.replace(".json","");r.push(`"${n}": ${h(a)}`);}return r},u$1=t=>{let a=[];return utils.forin(t,(e,{params:t})=>{t&&a.push(`"${e}": { ${dataParamsToTsInterfaceBody(t)} };`);}),a},d$1=(e,t)=>Object.keys(e).filter(a=>t(a,e[a])).sort().map(e=>`"${e}"`).join(" | ");var l$1 = (({config:e,
|
|
304
|
+
let c$1=(e,a)=>{if(!utils$1.isArray(a)&&utils$1.isObject(a)){if(hasOnlyPluralKeys(a))return `"${e}": string;`;if(hasPlurals(a))return `"${e}": string | ${h(pickNonPluralValue(a))}`}return `"${e}": ${h(a)}`},h=e=>{let r="",i="";if(utils$1.isBoolean(e)?i="boolean":utils$1.isString(e)&&(i="string"),i)r+=i+";";else if(e){if(utils$1.isArray(e)){let t=e[0];r+=`${h(t)}[];`;}else if(utils$1.isObject(e)){r+="{";let t=transformKeysForPlurals(Object.keys(e));for(let a=0;a<t.length;a++){let n=t[a],s=e[n]||"";r+=c$1(n,s);}r+="};";}}else r+="";return (r=r.replace(/;\[\];/g,"[];")).replace(/;+/g,";")},T=(e,t)=>{let{translationFiles:a}=t,{defaultLocale:n}=e,s=a.filter(e=>e.locale===n),r=[];for(let e=0;e<s.length;e++){let{path:t,data:a}=s[e],n=t.replace(".json","");r.push(`"${n}": ${h(a)}`);}return r},u$1=t=>{let a=[];return utils$1.forin(t,(e,{params:t})=>{t&&a.push(`"${e}": { ${dataParamsToTsInterfaceBody(t)} };`);}),a},d$1=(e,t)=>Object.keys(e).filter(a=>t(a,e[a])).sort().map(e=>`"${e}"`).join(" | ");var l$1 = (({config:e,input:t,routes:a})=>{let n=d$1(a,(e,{params:t})=>!t),s=d$1(a,(e,{params:t})=>!!t);return `
|
|
297
305
|
/* eslint-disable @typescript-eslint/no-namespace */
|
|
298
306
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
299
307
|
/* eslint-disable @typescript-eslint/ban-types */
|
|
@@ -538,7 +546,7 @@ export namespace I18n {
|
|
|
538
546
|
}
|
|
539
547
|
`});
|
|
540
548
|
|
|
541
|
-
var e$2 = (()=>({files:[{name:"config",fn:e$
|
|
549
|
+
var e$2 = (()=>({files:[{name:"config",fn:e$3,ext:"ts",index:!0},{name:"defaultLocale",fn:t$3,ext:"ts",index:!0},{name:"deriveLocalisedPathnames",fn:o$3,ext:"ts",index:!0},{name:"isLocale",fn:n$4,ext:"ts",index:!0},{name:"locales",fn:m$3,ext:"ts",index:!0},{name:"pathnameToRouteId",fn:a$4,ext:"ts",index:!0},{name:"routes",fn:r$2,ext:"ts",index:!0},{name:"routesSlim",fn:i$3,ext:"ts",index:!0},{name:"tFns",fn:s$4,ext:"ts"},{name:"tInterpolateParams",fn:f$1,ext:"ts",index:!1},{name:"to",fn:x,ext:"ts",index:!0},{name:"toFns",fn:d$2,ext:"ts",index:!0},{name:"toFormat",fn:p,ext:"ts",index:!0},{name:"types",fn:l$1,ext:"ts",index:!0}]}));
|
|
542
550
|
|
|
543
551
|
var e$1 = (()=>`
|
|
544
552
|
"use client";
|
|
@@ -592,7 +600,7 @@ export const TransText = _TransText;
|
|
|
592
600
|
export default TransText;
|
|
593
601
|
`);
|
|
594
602
|
|
|
595
|
-
var m$
|
|
603
|
+
var m$1 = (()=>`
|
|
596
604
|
import _getT from "next-translate/getT";
|
|
597
605
|
import type { I18n } from "./types";
|
|
598
606
|
|
|
@@ -672,19 +680,9 @@ export const useT = <TNamespace extends I18n.TranslateNamespace>(namespace: TNam
|
|
|
672
680
|
export default useT;
|
|
673
681
|
`);
|
|
674
682
|
|
|
675
|
-
var t$1 = (()=>({dependsOn:["next"],needsTranslationsFiles:!0,files:[{name:"DynamicNamespaces",fn:e$1,ext:"tsx",index:!0},{name:"getT",fn:m$
|
|
676
|
-
|
|
677
|
-
function getPathRedirect(e){let{localeSource:r,localeDestination:n,template:i,pathname:o,permanent:c}=e,f=formatRoutePathname.formatRoutePathname((r?`${r}/`:"")+i),m=formatRoutePathname.formatRoutePathname((n?`${n}/`:"")+o);if(f!==m)return {source:f,destination:m,permanent:!!c}}
|
|
678
|
-
|
|
679
|
-
function transformPathname(n,e){return "/"+e.split("/").filter(Boolean).map(n=>n.startsWith("[")?`:${encodeURIComponent(n.slice(1,-1))}`:`${encodeURIComponent(n)}`).join("/")+(n.wildcard?"/:wildcard*":"")}
|
|
680
|
-
|
|
681
|
-
function getRedirects(l,r,i="",a=!1){let{defaultLocale:n,hideDefaultLocaleInUrl:s}=l,c=[];for(let e in r){let l=r[e],u=r[e].pathnames;for(let r in u){let p=u[r],f=transformPathname(l,e.replace(/\./g,"/")),m=transformPathname(l,p);if(l.inWildcard)break;let h=r===n&&!s,d=r===n&&s;i?h?c.push(getPathRedirect({localeDestination:r,permanent:a,template:f,pathname:m})):d?c.push(getPathRedirect({localeSource:r,permanent:a,template:f,pathname:m})):r!==n?c.push(getPathRedirect({localeSource:r,localeDestination:r,permanent:a,template:f,pathname:m})):c.push(getPathRedirect({permanent:a,template:f,pathname:m})):m!==f&&(h?c.push(getPathRedirect({localeDestination:r,permanent:a,template:f,pathname:m})):r!==n?c.push(getPathRedirect({localeSource:r,localeDestination:r,permanent:a,template:f,pathname:m})):c.push(getPathRedirect({permanent:a,template:f,pathname:m})));}}return utils.arrayUniqueByProperties(c.filter(Boolean),["source","destination"]).map(e=>i?e:{...e,locale:!1})}var e = (({config:e,data:t})=>{let o=JSON.stringify(getRedirects(e,t.code.routes),null,2);return `module.exports = ${o}`});
|
|
682
|
-
|
|
683
|
-
function getPathRewrite(e){let{localeSource:r,localeDestination:i,localeParam:l,template:n,pathname:o}=e,$="";r?$=`/${r}`:l&&($=`/:${l}`);let f=formatRoutePathname.formatRoutePathname($+o),c="";i?c=`/${i}`:l&&(c=`/:${l}`);let m=formatRoutePathname.formatRoutePathname(c+n);if(f!==m)return {source:f,destination:m}}
|
|
683
|
+
var t$1 = (()=>({dependsOn:["next"],needsTranslationsFiles:!0,files:[{name:"DynamicNamespaces",fn:e$1,ext:"tsx",index:!0},{name:"getT",fn:m$1,ext:"ts",index:!0},{name:"nextTranslateI18n",fn:s$2,ext:"js"},{name:"T",fn:n$3,ext:"tsx",index:!0},{name:"TransText",fn:t$2,ext:"tsx",index:!0},{name:"useT",fn:a$1,ext:"ts",index:!0}]}));
|
|
684
684
|
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
var n$2 = (()=>`
|
|
685
|
+
var e = (()=>`
|
|
688
686
|
"use client";
|
|
689
687
|
|
|
690
688
|
import { useEffect, useState } from "react";
|
|
@@ -705,7 +703,7 @@ export function useCurrentLocalisedPathnames() {
|
|
|
705
703
|
export default useCurrentLocalisedPathnames;
|
|
706
704
|
`);
|
|
707
705
|
|
|
708
|
-
var
|
|
706
|
+
var t = (({config:e})=>`
|
|
709
707
|
import { useRouter } from "next/router";
|
|
710
708
|
import type { I18n } from "./types";
|
|
711
709
|
|
|
@@ -725,7 +723,7 @@ export const useRouteId = () =>
|
|
|
725
723
|
export default useRouteId;
|
|
726
724
|
`);
|
|
727
725
|
|
|
728
|
-
var
|
|
726
|
+
var n$2 = (()=>`
|
|
729
727
|
"use client";
|
|
730
728
|
|
|
731
729
|
import { to } from "./to";
|
|
@@ -753,123 +751,22 @@ export const useTo = () => {
|
|
|
753
751
|
export default useTo;
|
|
754
752
|
`);
|
|
755
753
|
|
|
756
|
-
var
|
|
757
|
-
const withTranslate = require("next-translate-plugin");
|
|
758
|
-
const webpack = require("webpack");
|
|
759
|
-
const defaultRedirects = require("./next-redirects");
|
|
760
|
-
const defaultRewrites = require("./next-rewrites");
|
|
761
|
-
|
|
762
|
-
/**
|
|
763
|
-
* @typedef {import("next").NextConfig} NextConfig
|
|
764
|
-
*
|
|
765
|
-
* @typedef {object} WithI18nOptions
|
|
766
|
-
* @property {boolean} [permanent] Whether the routes redirecting should be permanent. Switch this on once you go live and the routes structure is stable.
|
|
767
|
-
* @property {string} [localeParam]
|
|
768
|
-
*/
|
|
769
|
-
|
|
770
|
-
/**
|
|
771
|
-
* Get Next.js config with some basic opinionated defaults
|
|
772
|
-
*
|
|
773
|
-
* @param {WithI18nOptions} options
|
|
774
|
-
*/
|
|
775
|
-
const withI18n = ({ permanent, localeParam } = {}) =>
|
|
776
|
-
/**
|
|
777
|
-
* @param {Omit<NextConfig, "i18n">} nextConfig
|
|
778
|
-
* @returns {Omit<NextConfig, "i18n"> & { i18n: Required<NextConfig["i18n"]> }
|
|
779
|
-
*/
|
|
780
|
-
(nextConfig) => {
|
|
781
|
-
const locales = [${t.map(e=>`"${e}"`).join(", ")}];
|
|
782
|
-
const defaultLocale = "${n}";
|
|
783
|
-
// const hideDefaultLocaleInUrl = ${i?"true":"false"};
|
|
784
|
-
|
|
785
|
-
if (localeParam) {
|
|
786
|
-
// app router:
|
|
787
|
-
// NOTE: after thousands attempts turns out that passing the i18n settings
|
|
788
|
-
// to the app router messes up everything, just rely on our internal i18n
|
|
789
|
-
// mechanisms
|
|
790
|
-
delete nextConfig.i18n;
|
|
791
|
-
} else {
|
|
792
|
-
// pages routes:
|
|
793
|
-
nextConfig.i18n = nextConfig.i18n || {};
|
|
794
|
-
nextConfig.i18n.locales = locales;
|
|
795
|
-
nextConfig.i18n.defaultLocale = defaultLocale;
|
|
796
|
-
}
|
|
797
|
-
|
|
798
|
-
const newNextConfig = {
|
|
799
|
-
...nextConfig,
|
|
800
|
-
async redirects() {
|
|
801
|
-
if (nextConfig.redirects) {
|
|
802
|
-
const custom = await nextConfig.redirects();
|
|
803
|
-
return [...defaultRedirects, ...custom];
|
|
804
|
-
}
|
|
805
|
-
return defaultRedirects;
|
|
806
|
-
},
|
|
807
|
-
async rewrites() {
|
|
808
|
-
if (nextConfig.rewrites) {
|
|
809
|
-
const custom = await nextConfig.rewrites();
|
|
810
|
-
|
|
811
|
-
if (Array.isArray(custom)) {
|
|
812
|
-
return {
|
|
813
|
-
beforeFiles: defaultRewrites,
|
|
814
|
-
afterFiles: custom,
|
|
815
|
-
fallback: [],
|
|
816
|
-
};
|
|
817
|
-
}
|
|
818
|
-
|
|
819
|
-
return {
|
|
820
|
-
...custom,
|
|
821
|
-
beforeFiles: [...defaultRewrites, ...(custom.beforeFiles || [])],
|
|
822
|
-
};
|
|
823
|
-
}
|
|
824
|
-
return {
|
|
825
|
-
beforeFiles: defaultRewrites,
|
|
826
|
-
afterFiles: [],
|
|
827
|
-
fallback: [],
|
|
828
|
-
};
|
|
829
|
-
},
|
|
830
|
-
};
|
|
831
|
-
|
|
832
|
-
nextConfig.webpack = (config, options) => {
|
|
833
|
-
const webpackConfig =
|
|
834
|
-
typeof nextConfig.webpack === "function"
|
|
835
|
-
? nextConfig.webpack(config, options)
|
|
836
|
-
: config;
|
|
837
|
-
|
|
838
|
-
// @see https://github.com/date-fns/date-fns/blob/main/docs/webpack.md#removing-unused-languages-from-dynamic-import
|
|
839
|
-
webpackConfig.plugins.push(
|
|
840
|
-
new webpack.ContextReplacementPlugin(
|
|
841
|
-
/^date-fns[/\\\\]locale$/,
|
|
842
|
-
/\\.[/\\\\](${t.join("|")})[/\\\\]index\\.js$/
|
|
843
|
-
// new RegExp(\`\\\\.[/\\\\\\\\](${t.join("|")})[/\\\\\\\\]index\\\\.js$\`)
|
|
844
|
-
)
|
|
845
|
-
);
|
|
846
|
-
|
|
847
|
-
return webpackConfig;
|
|
848
|
-
};
|
|
849
|
-
|
|
850
|
-
// TODO: move to next-translate adapter
|
|
851
|
-
return withTranslate(newNextConfig);
|
|
852
|
-
}
|
|
853
|
-
|
|
854
|
-
module.exports = { withI18n };
|
|
855
|
-
`});
|
|
856
|
-
|
|
857
|
-
var n$1 = (()=>({dependsOn:["js"],files:[{name:"next-redirects",fn:e,ext:"js"},{name:"next-rewrites",fn:t,ext:"js"},{name:"useCurrentLocalisedPathnames",fn:n$2,ext:"ts",index:!0},{name:"useLocale",fn:r$1,ext:"ts",index:!0},{name:"useRouteId",fn:s$1,ext:"ts",index:!0},{name:"useTo",fn:m$1,ext:"ts",index:!0},{name:"withI18n",fn:o$3,ext:"js"}]}));
|
|
754
|
+
var n$1 = (()=>({dependsOn:["js"],files:[{name:"useCurrentLocalisedPathnames",fn:e,ext:"ts",index:!0},{name:"useLocale",fn:t,ext:"ts",index:!0},{name:"useRouteId",fn:s$1,ext:"ts",index:!0},{name:"useTo",fn:n$2,ext:"ts",index:!0}]}));
|
|
858
755
|
|
|
859
756
|
let a={js:e$2,next:n$1,"next-translate":t$1},r=e=>{let t="";return e.filter(e=>e.index).sort((e,t)=>e.name.localeCompare(t.name)).forEach(e=>{t+=`export * from "./${e.name}";
|
|
860
757
|
`;}),t},o$2=async(e,t,n=[])=>{let r=(0, a[t])(e);return n=n.concat(r),r.dependsOn&&await Promise.all(r.dependsOn.map(async t=>{n=n.concat(await o$2(e,t));})),n};async function generateCode(e,t){let{adapter:n,outputFiles:a}=t,s=await o$2(e,n),l=s.reduce((e,t)=>[...e,...t.files],[]).map(t=>{let{fn:n,...r}=t,o=a?.[r.name]||r.name;return {...r,name:o,content:n(e)}});return r(l)&&l.push({name:"index",ext:"ts",content:r(l)}),{files:l,needsTranslationsFiles:s.some(e=>e.needsTranslationsFiles)}}
|
|
861
758
|
|
|
862
759
|
let tsCompile=(o,i,s,r)=>{let l=Array.from(s).filter(e=>e.endsWith(".ts")||e.endsWith(".tsx")).map(t=>node_path.join(o,i,t)),n={noEmitOnError:!0,noImplicitAny:!0,declaration:!0,target:t__namespace.ScriptTarget.ESNext,module:t__namespace.ModuleKind.ESNext,moduleResolution:t__namespace.ModuleResolutionKind.Bundler,resolveJsonModule:!0,allowJs:!1,esModuleInterop:!0,jsx:t__namespace.JsxEmit.ReactJSX,outDir:node_path.join(o,i),skipLibCheck:!0,noEmitHelpers:!0,importHelpers:!0,...r||{}},a=t__namespace.createProgram(l,n),m=a.emit();return t__namespace.getPreEmitDiagnostics(a).concat(m.diagnostics).forEach(e=>{if(e.file){let{line:o,character:i}=t__namespace.getLineAndCharacterOfPosition(e.file,e.start),s=t__namespace.flattenDiagnosticMessageText(e.messageText,"\n");console.log(`${e.file.fileName} (${o+1},${i+1}): ${s}`);}else console.log(t__namespace.flattenDiagnosticMessageText(e.messageText,"\n"));}),m};
|
|
863
760
|
|
|
864
|
-
let writeCode=async(n,s
|
|
761
|
+
let writeCode=async(n,s)=>{let{cwd:d=process.cwd(),output:m,skipTsCompile:f,skipGitignore:l,skipTranslations:p,...w}=n,{files:c,needsTranslationsFiles:y}=await generateCode(s,w),h=new Set,S=new Set,$=new Set;if(await Promise.all(c.map(async({name:t,ext:r,content:i})=>{let o=`${t}.${r}`,n=node_path.join(d,m,o);await node.fsWrite(n,i),S.add(o),h.add(n);})),!f){let a=Array.from(S).filter(t=>t.endsWith(".ts")||t.endsWith(".tsx"));await tsCompile(d,m,a),a.forEach(a=>{S.add(a.replace(/\.tsx?$/,".js")),S.add(a.replace(/\.tsx?$/,".d.ts")),S.delete(a),node_fs.rmSync(node_path.join(d,m,a),{force:!0});});}y&&!p&&(await o$1(d,m,s.input)).forEach(t=>{$.add(t);}),l||await node.fsWrite(node_path.join(d,m,".gitignore"),Array.from(new Set([...$,...S])).sort().map(t=>`/${t}`).join(`
|
|
865
762
|
`));};async function o$1(t,r,{translationFiles:i}){return await Promise.all(i.map(async({data:i,locale:o,path:n})=>{let s=node_path.join("translations",o);return await node.fsWrite(node_path.join(t,r,s,n),JSON.stringify(i)),s}))}
|
|
866
763
|
|
|
867
|
-
let n=e=>e.replace(/\.index$/,""),i=e=>formatRoutePathname.formatRoutePathname(e.replace(/\*/g,"").replace(/[[{]{1,2}(.*?)[\]}]{1,2}/g,(e,t)=>`[${t.trim()}]`)),l=(e,t,r,a)=>{let n=t[a].pathnames[r];if(n.startsWith(`/${e.tokens.parentReference}`)){let i=RegExp(`^\\/\\${e.tokens.parentReference}`);n=n.replace(i,"");let s=a.split(".").slice(0,-1).join(".");if(s)n=l(e,t,r,s)+n;else throw Error("Used a parent route token reference without a matching parent route")}return n},s=(t,r)=>{utils.forin(r,(a,n)=>{utils.forin(n.pathnames,e=>{r[a].pathnames[e]=l(t,r,e,a);});});},o=e=>{let t=e.match(/\[.*?\]/g);if(t)return t.map(e=>e.slice(1,-1).trim()).reduce((e,t)=>(e[t]="stringOrNumber",e),{})},m=(e,t)=>{let{defaultLocale:a,locales:n}=e;for(let e in t){let i=t[e].pathnames,l=i[a],s={};for(let e in i){let t=i[e];t!==l&&(s[e]=t);}Object.keys(s).length===n.length-1||(Object.keys(s).length>=1?(s[a]=l,t[e].optimizedPathnames=utils.objectSortByKeysMatching(s,a)):t[e].optimizedPathnames=l);}};let getCodeDataRoutes=(e,a,{translationFiles:l})=>{let{defaultLocale:p}=e,h=[],c={};for(let e=0;e<l.length;e++){let{path:s,locale:m,data:f}=l[e];if(s===a.translationJsonFileName){let e=utils.objectFlat(f,a.tokens.idDelimiter);for(let t in e){let l=e[t],s=n(t);if(!c[s]){c[s]=c[s]||{};let e=o(s),t=l.includes(a.tokens.pathnameWildcard);c[s].id=s,e&&(c[s].params=e),t&&(c[s].wildcard=!0,h.push(s));}c[s].pathnames=c[s].pathnames||{},c[s].pathnames[m]=i(l),c[s].pathnames=utils.objectSortByKeysMatching(c[s].pathnames,p);}}}if(s(a,c),m(e,c),h.length)for(let e in c)h.some(t=>e.startsWith(t)&&t!==e)&&(c[e].inWildcard=!0);return Object.fromEntries(Object.entries(c).sort())};
|
|
764
|
+
let n=e=>e.replace(/\.index$/,""),i=e=>formatRoutePathname.formatRoutePathname(e.replace(/\*/g,"").replace(/[[{]{1,2}(.*?)[\]}]{1,2}/g,(e,t)=>`[${t.trim()}]`)),l=(e,t,r,a)=>{let n=t[a].pathnames[r];if(n.startsWith(`/${e.tokens.parentReference}`)){let i=RegExp(`^\\/\\${e.tokens.parentReference}`);n=n.replace(i,"");let s=a.split(".").slice(0,-1).join(".");if(s)n=l(e,t,r,s)+n;else throw Error("Used a parent route token reference without a matching parent route")}return n},s=(t,r)=>{utils$1.forin(r,(a,n)=>{utils$1.forin(n.pathnames,e=>{r[a].pathnames[e]=l(t,r,e,a);});});},o=e=>{let t=e.match(/\[.*?\]/g);if(t)return t.map(e=>e.slice(1,-1).trim()).reduce((e,t)=>(e[t]="stringOrNumber",e),{})},m=(e,t)=>{let{defaultLocale:a,locales:n}=e;for(let e in t){let i=t[e].pathnames,l=i[a],s={};for(let e in i){let t=i[e];t!==l&&(s[e]=t);}Object.keys(s).length===n.length-1||(Object.keys(s).length>=1?(s[a]=l,t[e].optimizedPathnames=utils$1.objectSortByKeysMatching(s,a)):t[e].optimizedPathnames=l);}};let getCodeDataRoutes=(e,a,{translationFiles:l})=>{let{defaultLocale:p}=e,h=[],c={};for(let e=0;e<l.length;e++){let{path:s,locale:m,data:f}=l[e];if(s===a.translationJsonFileName){let e=utils$1.objectFlat(f,a.tokens.idDelimiter);for(let t in e){let l=e[t],s=n(t);if(!c[s]){c[s]=c[s]||{};let e=o(s),t=l.includes(a.tokens.pathnameWildcard);c[s].id=s,e&&(c[s].params=e),t&&(c[s].wildcard=!0,h.push(s));}c[s].pathnames=c[s].pathnames||{},c[s].pathnames[m]=i(l),c[s].pathnames=utils$1.objectSortByKeysMatching(c[s].pathnames,p);}}}if(s(a,c),m(e,c),h.length)for(let e in c)h.some(t=>e.startsWith(t)&&t!==e)&&(c[e].inWildcard=!0);return Object.fromEntries(Object.entries(c).sort())};
|
|
868
765
|
|
|
869
|
-
let f=RegExp(node_path.sep,"g"),u=e=>{let t=e.replace(/~/g,"$").replace(/-/g,"_").replace(f,"_").replace(/_+/g,"_").replace(/[^a-zA-Z0-9_$]/gi,"");return /^[0-9]/.test(t)?"$"+t:t},c=(e,t)=>{if(utils.isString(t)){let{start:r,end:a}=e.dynamicDelimiters,l=RegExp(`${r}(.*?)${a}`,"gm"),i=t.match(l);if(i)return i.map(e=>e.replace(r,"").replace(a,"").trim()).reduce((e,t)=>(e[t]="stringOrNumber",e),{})}},g=(e,t)=>(Object.keys(t).filter(isPluralKey).forEach(e=>{let r=removePluralSuffix(e);t[r]&&(t[r].plural=!0),delete t[e];}),t),d=(e,t,r,a,l)=>{if(utils.isPrimitive(a)){let i=c(e,a);l[t]=l[t]||{},l[t].values=l[t].values||{},l[t].values[r]=a,l[t].typeValue="Primitive",i&&(l[t].params=i);}else {if(e.fnsAsDataCodes){let e=utils.isArray(a)?"Array":"Object";l[t]=l[t]||{},l[t].values=l[t].values||{},l[t].values[r]=a,l[t].typeValue=e;}if(utils.isArray(a)){if(e.createArrayIndexBasedFns)for(let i=0;i<a.length;i++)d(e,t+"_"+i,r,a[i],l);}else for(let i in a)d(e,t+"_"+u(i),r,a[i],l);}return l},v=(l,i,s)=>{let{locale:n,path:o}=i,p=node_path.join(node_path.dirname(o),node_path.basename(o,node_path.extname(o)));for(let e in i.data){let t=i.data[e];d(l,u(p+(e?"_"+e:"")),n,t,s);}return s};let getCodeDataTranslations=(e,t,{translationFiles:r})=>{let{ignorePaths:a}=t,l={};for(let e=0;e<r.length;e++)(!a||a&&a.every(t=>!minimatch.minimatch(r[e].path,t)))&&v(t,r[e],l);return Object.fromEntries(Object.entries(l=g(t,l)).sort())};
|
|
766
|
+
let f=RegExp(node_path.sep,"g"),u=e=>{let t=e.replace(/~/g,"$").replace(/-/g,"_").replace(f,"_").replace(/_+/g,"_").replace(/[^a-zA-Z0-9_$]/gi,"");return /^[0-9]/.test(t)?"$"+t:t},c=(e,t)=>{if(utils$1.isString(t)){let{start:r,end:a}=e.dynamicDelimiters,l=RegExp(`${r}(.*?)${a}`,"gm"),i=t.match(l);if(i)return i.map(e=>e.replace(r,"").replace(a,"").trim()).reduce((e,t)=>(e[t]="stringOrNumber",e),{})}},g=(e,t)=>(Object.keys(t).filter(isPluralKey).forEach(e=>{let r=removePluralSuffix(e);t[r]&&(t[r].plural=!0),delete t[e];}),t),d=(e,t,r,a,l)=>{if(utils$1.isPrimitive(a)){let i=c(e,a);l[t]=l[t]||{},l[t].values=l[t].values||{},l[t].values[r]=a,l[t].typeValue="Primitive",i&&(l[t].params=i);}else {if(e.fnsAsDataCodes){let e=utils$1.isArray(a)?"Array":"Object";l[t]=l[t]||{},l[t].values=l[t].values||{},l[t].values[r]=a,l[t].typeValue=e;}if(utils$1.isArray(a)){if(e.createArrayIndexBasedFns)for(let i=0;i<a.length;i++)d(e,t+"_"+i,r,a[i],l);}else for(let i in a)d(e,t+"_"+u(i),r,a[i],l);}return l},v=(l,i,s)=>{let{locale:n,path:o}=i,p=node_path.join(node_path.dirname(o),node_path.basename(o,node_path.extname(o)));for(let e in i.data){let t=i.data[e];d(l,u(p+(e?"_"+e:"")),n,t,s);}return s};let getCodeDataTranslations=(e,t,{translationFiles:r})=>{let{ignorePaths:a}=t,l={};for(let e=0;e<r.length;e++)(!a||a&&a.every(t=>!minimatch.minimatch(r[e].path,t)))&&v(t,r[e],l);return Object.fromEntries(Object.entries(l=g(t,l)).sort())};
|
|
870
767
|
|
|
871
|
-
const codeDataRoutesOptions={translationJsonFileName:"~.json",tokens:{parentReference:"^",idDelimiter:".",pathnameWildcard:"*"}};const codeDataTranslationsOptions={ignorePaths:[],dynamicDelimiters:{start:"{{",end:"}}"},fnsAsDataCodes:!0,fnsPrefix:"",createArrayIndexBasedFns:!1};const codeDataOptions={routes:codeDataRoutesOptions,translations:codeDataTranslationsOptions};let getCodeData=(e,
|
|
768
|
+
const codeDataRoutesOptions={translationJsonFileName:"~.json",tokens:{parentReference:"^",idDelimiter:".",pathnameWildcard:"*"}};const codeDataTranslationsOptions={ignorePaths:[],dynamicDelimiters:{start:"{{",end:"}}"},fnsAsDataCodes:!0,fnsPrefix:"",createArrayIndexBasedFns:!1};const codeDataOptions={routes:codeDataRoutesOptions,translations:codeDataTranslationsOptions};let getCodeData=(s,e,n)=>{let r=utils$1.objectMergeWithDefaults(codeDataOptions,e);return r.translations.ignorePaths.push(r.routes.translationJsonFileName),{config:s,options:r,input:n,routes:getCodeDataRoutes(s,r.routes,n),translations:getCodeDataTranslations(s,r.translations,n)}};
|
|
872
769
|
|
|
873
|
-
let i18nCompiler=async
|
|
770
|
+
let i18nCompiler=async p=>{let{input:w,code:u,summary:s,...f}=p,l=[],n=await getInputData(w),c=write.getConfig(n,f),h=await getCodeData(c,u,n);if(w?.write&&l.push(write.writeInput(w.write,n)),u?.write&&l.push(writeCode({...u,...u.write},h)),s?.write){let i=await write.getSummaryData(c,s,n);l.push(write.writeSummary({...s,...s.write},i));}return await Promise.all(l),{config:c,input:n,code:h}};
|
|
874
771
|
|
|
875
772
|
exports.i18nCompiler = i18nCompiler;
|