@xndrjs/i18n 0.8.1 → 0.8.2-alpha.1
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/README.md +1 -2
- package/dist/cli/audit.js +739 -0
- package/dist/cli/audit.js.map +1 -0
- package/dist/cli/codegen.js +1471 -0
- package/dist/cli/codegen.js.map +1 -0
- package/dist/cli/setup.js +148 -0
- package/dist/cli/setup.js.map +1 -0
- package/dist/codegen/index.js +43 -40
- package/dist/codegen/index.js.map +1 -1
- package/package.json +6 -9
- package/bin/audit.mjs +0 -14
- package/bin/codegen.mjs +0 -17
- package/bin/setup.mjs +0 -14
- package/src/IcuTranslationProviderMulti.test.ts +0 -215
- package/src/IcuTranslationProviderMulti.ts +0 -188
- package/src/audit/audit-dictionaries.test.ts +0 -134
- package/src/audit/audit-dictionaries.ts +0 -178
- package/src/audit/run-audit.test.ts +0 -169
- package/src/audit/run-audit.ts +0 -94
- package/src/builder-load-registry.test.ts +0 -44
- package/src/builder-load-registry.ts +0 -78
- package/src/builder-loaders.ts +0 -15
- package/src/builder-types.test.ts +0 -57
- package/src/builder-types.ts +0 -24
- package/src/builder.test.ts +0 -303
- package/src/builder.ts +0 -15
- package/src/codegen/codegen-config-schema.ts +0 -156
- package/src/codegen/config.test.ts +0 -231
- package/src/codegen/config.ts +0 -42
- package/src/codegen/constants.ts +0 -9
- package/src/codegen/delivery-artifacts.test.ts +0 -167
- package/src/codegen/delivery-artifacts.ts +0 -154
- package/src/codegen/dictionary-spec-contract.test.ts +0 -28
- package/src/codegen/dictionary-spec-contract.ts +0 -138
- package/src/codegen/emit/dictionary-schema-file.ts +0 -113
- package/src/codegen/emit/instance-file.test.ts +0 -71
- package/src/codegen/emit/instance-file.ts +0 -257
- package/src/codegen/emit/namespace-loaders-file.test.ts +0 -251
- package/src/codegen/emit/namespace-loaders-file.ts +0 -229
- package/src/codegen/emit/types-file.test.ts +0 -96
- package/src/codegen/emit/types-file.ts +0 -142
- package/src/codegen/fixtures/billing-namespace.json +0 -6
- package/src/codegen/generate-i18n-types.test.ts +0 -1137
- package/src/codegen/generate-i18n-types.ts +0 -20
- package/src/codegen/icu-analysis.ts +0 -110
- package/src/codegen/locale-fallback.ts +0 -73
- package/src/codegen/locale-policy.test.ts +0 -35
- package/src/codegen/locale-policy.ts +0 -30
- package/src/codegen/paths.ts +0 -44
- package/src/codegen/project-locales-set-namespace.test.ts +0 -134
- package/src/codegen/read-dictionary.test.ts +0 -594
- package/src/codegen/read-dictionary.ts +0 -260
- package/src/codegen/regenerate-namespaces.ts +0 -180
- package/src/codegen/run-codegen.test.ts +0 -230
- package/src/codegen/run-codegen.ts +0 -252
- package/src/codegen/types.ts +0 -10
- package/src/codegen/write-file-if-changed.test.ts +0 -42
- package/src/codegen/write-file-if-changed.ts +0 -20
- package/src/codegen-config/build-config.ts +0 -15
- package/src/codegen-config/codegen-config.test.ts +0 -36
- package/src/codegen-config/index.ts +0 -37
- package/src/codegen-config/type-names.ts +0 -20
- package/src/codegen-config/write-config.ts +0 -8
- package/src/engine.ts +0 -47
- package/src/fetch-artifact.ts +0 -16
- package/src/format-core.ts +0 -91
- package/src/i18n-handle.ts +0 -216
- package/src/icu/extract-variables.test.ts +0 -199
- package/src/icu/extract-variables.ts +0 -227
- package/src/icu/parse-template.ts +0 -31
- package/src/index.ts +0 -63
- package/src/load-state.ts +0 -15
- package/src/project-locales.test.ts +0 -280
- package/src/project-locales.ts +0 -211
- package/src/resolve-locale.test.ts +0 -91
- package/src/resolve-locale.ts +0 -88
- package/src/scope-multi.ts +0 -105
- package/src/scope-types.ts +0 -35
- package/src/scope.test.ts +0 -172
- package/src/serialized-state.test.ts +0 -114
- package/src/serialized-state.ts +0 -28
- package/src/setup/setup-i18n.test.ts +0 -85
- package/src/setup/setup-i18n.ts +0 -156
- package/src/types.ts +0 -65
- package/src/validation/create-args-schema.ts +0 -76
- package/src/validation/create-normalized-schema.ts +0 -52
- package/src/validation/errors.ts +0 -43
- package/src/validation/index.ts +0 -202
- package/src/validation/normalize.ts +0 -299
- package/src/validation/to-dictionary.ts +0 -67
- package/src/validation/types.ts +0 -82
- package/src/validation/validate-normalized.ts +0 -133
- package/src/validation/validation.test.ts +0 -562
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
formatDeliveryArtifactsBlock,
|
|
3
|
-
formatLocaleDeliveryAreaBlock,
|
|
4
|
-
type DeliveryArtifactsMap,
|
|
5
|
-
} from "../delivery-artifacts.js";
|
|
6
|
-
import { formatLocaleFallbackBlock } from "../locale-fallback.js";
|
|
7
|
-
import { GENERATED_FILE_BANNER } from "../paths.js";
|
|
8
|
-
import type { NamespaceEntry } from "../types.js";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Emits lazy-load type aliases. Every namespace is lazy; `InitialSchema` is empty
|
|
12
|
-
* (cold start / hydrate via `resources` only).
|
|
13
|
-
*/
|
|
14
|
-
export function formatLazyTypesBlock(lazyEntries: NamespaceEntry[]): string {
|
|
15
|
-
const lazyUnion =
|
|
16
|
-
lazyEntries.length > 0
|
|
17
|
-
? lazyEntries.map((entry) => `'${entry.namespace}'`).join(" | ")
|
|
18
|
-
: "never";
|
|
19
|
-
|
|
20
|
-
return (
|
|
21
|
-
`export type LazyNamespace = ${lazyUnion};\n` +
|
|
22
|
-
`/** Empty cold-start schema — namespaces arrive via \`namespaceLoaders\`. */\n` +
|
|
23
|
-
`export type InitialSchema = Record<string, never>;\n\n`
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function formatLocaleTemplateType(localeTypeName: string, hasLocaleUnion: boolean): string {
|
|
28
|
-
if (!hasLocaleUnion) {
|
|
29
|
-
return "Partial<Record<string, string>>";
|
|
30
|
-
}
|
|
31
|
-
return `Partial<Record<${localeTypeName}, string>>`;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export interface TypesFileOptions {
|
|
35
|
-
entries: NamespaceEntry[];
|
|
36
|
-
projectRoot: string;
|
|
37
|
-
typesOutputPath: string;
|
|
38
|
-
paramsTypeName: string;
|
|
39
|
-
schemaTypeName: string;
|
|
40
|
-
localeTypeName: string;
|
|
41
|
-
localeFallbackConstName: string;
|
|
42
|
-
localeFallbackTypeName: string;
|
|
43
|
-
localeFallback?: Record<string, string | null> | undefined;
|
|
44
|
-
paramsByNamespace: Record<string, Record<string, string>>;
|
|
45
|
-
/** Sorted request locales — emits `ProjectLocales` const + `ProjectLocale` type. */
|
|
46
|
-
requestLocales: readonly string[];
|
|
47
|
-
deliveryAreaTypeName?: string;
|
|
48
|
-
/** Sorted delivery area names — emits `ProjectDeliveryAreas` const + type. */
|
|
49
|
-
deliveryAreaNames?: readonly string[];
|
|
50
|
-
deliveryArtifacts?: DeliveryArtifactsMap;
|
|
51
|
-
localeDeliveryAreaConstName?: string;
|
|
52
|
-
lazyEntries: NamespaceEntry[];
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function formatTypesFile(options: TypesFileOptions): string {
|
|
56
|
-
const {
|
|
57
|
-
entries,
|
|
58
|
-
paramsTypeName,
|
|
59
|
-
schemaTypeName,
|
|
60
|
-
localeTypeName,
|
|
61
|
-
localeFallbackConstName,
|
|
62
|
-
localeFallbackTypeName,
|
|
63
|
-
localeFallback,
|
|
64
|
-
paramsByNamespace,
|
|
65
|
-
requestLocales,
|
|
66
|
-
deliveryAreaTypeName,
|
|
67
|
-
deliveryAreaNames,
|
|
68
|
-
deliveryArtifacts,
|
|
69
|
-
localeDeliveryAreaConstName = "LOCALE_DELIVERY_AREA",
|
|
70
|
-
lazyEntries,
|
|
71
|
-
} = options;
|
|
72
|
-
|
|
73
|
-
const hasLocaleUnion = requestLocales.length > 0;
|
|
74
|
-
const localeTemplateType = formatLocaleTemplateType(localeTypeName, hasLocaleUnion);
|
|
75
|
-
const localesConstName = `${localeTypeName}s`;
|
|
76
|
-
|
|
77
|
-
const localeBlock = hasLocaleUnion
|
|
78
|
-
? `${localeFallback ? formatLocaleFallbackBlock(localeFallback, localeFallbackConstName, localeFallbackTypeName) : ""}` +
|
|
79
|
-
`export const ${localesConstName} = [${requestLocales.map((locale) => JSON.stringify(locale)).join(", ")}] as const;\n` +
|
|
80
|
-
`export type ${localeTypeName} = (typeof ${localesConstName})[number];\n\n`
|
|
81
|
-
: "";
|
|
82
|
-
|
|
83
|
-
const deliveryAreasConstName = deliveryAreaTypeName ? `${deliveryAreaTypeName}s` : undefined;
|
|
84
|
-
const deliveryAreaBlock =
|
|
85
|
-
deliveryAreaTypeName &&
|
|
86
|
-
deliveryAreasConstName &&
|
|
87
|
-
deliveryAreaNames &&
|
|
88
|
-
deliveryAreaNames.length > 0
|
|
89
|
-
? `export const ${deliveryAreasConstName} = [${deliveryAreaNames.map((area) => JSON.stringify(area)).join(", ")}] as const;\n` +
|
|
90
|
-
`export type ${deliveryAreaTypeName} = (typeof ${deliveryAreasConstName})[number];\n\n` +
|
|
91
|
-
(deliveryArtifacts
|
|
92
|
-
? formatDeliveryArtifactsBlock(
|
|
93
|
-
deliveryArtifacts,
|
|
94
|
-
"DELIVERY_ARTIFACTS",
|
|
95
|
-
localeTypeName,
|
|
96
|
-
deliveryAreaTypeName
|
|
97
|
-
) +
|
|
98
|
-
formatLocaleDeliveryAreaBlock(
|
|
99
|
-
deliveryArtifacts,
|
|
100
|
-
localeDeliveryAreaConstName,
|
|
101
|
-
localeTypeName,
|
|
102
|
-
deliveryAreaTypeName
|
|
103
|
-
)
|
|
104
|
-
: "")
|
|
105
|
-
: "";
|
|
106
|
-
|
|
107
|
-
const namespaceBlocks = entries
|
|
108
|
-
.map((entry) => {
|
|
109
|
-
const keyTypes = paramsByNamespace[entry.namespace] ?? {};
|
|
110
|
-
const lines = Object.entries(keyTypes)
|
|
111
|
-
.map(([key, type]) => ` ${key}: ${type};`)
|
|
112
|
-
.join("\n");
|
|
113
|
-
return ` ${entry.namespace}: {\n${lines}\n };`;
|
|
114
|
-
})
|
|
115
|
-
.join("\n");
|
|
116
|
-
|
|
117
|
-
const paramsBlock = `export type ${paramsTypeName} = {\n${namespaceBlocks}\n};`;
|
|
118
|
-
|
|
119
|
-
const schemaLines = entries
|
|
120
|
-
.map((entry) => {
|
|
121
|
-
const keyTypes = paramsByNamespace[entry.namespace] ?? {};
|
|
122
|
-
const lines = Object.keys(keyTypes)
|
|
123
|
-
.map((key) => ` ${key}: ${localeTemplateType};`)
|
|
124
|
-
.join("\n");
|
|
125
|
-
return ` ${entry.namespace}: {\n${lines}\n };`;
|
|
126
|
-
})
|
|
127
|
-
.join("\n");
|
|
128
|
-
|
|
129
|
-
const schemaBlock = `export type ${schemaTypeName} = {\n${schemaLines}\n};`;
|
|
130
|
-
|
|
131
|
-
const lazyTypesBlock = formatLazyTypesBlock(lazyEntries);
|
|
132
|
-
|
|
133
|
-
return (
|
|
134
|
-
`${GENERATED_FILE_BANNER}` +
|
|
135
|
-
`export const I18N_MODE = 'multi' as const;\n\n` +
|
|
136
|
-
`${localeBlock}` +
|
|
137
|
-
`${deliveryAreaBlock}` +
|
|
138
|
-
`${paramsBlock}\n\n` +
|
|
139
|
-
`${schemaBlock}\n` +
|
|
140
|
-
`${lazyTypesBlock}`
|
|
141
|
-
);
|
|
142
|
-
}
|