@xndrjs/i18n 0.7.0 → 0.8.0-alpha.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/README.md +67 -872
- package/dist/codegen/index.d.ts +117 -51
- package/dist/codegen/index.js +1585 -93
- package/dist/codegen/index.js.map +1 -1
- package/dist/index.d.ts +100 -234
- package/dist/index.js +74 -638
- package/dist/index.js.map +1 -1
- package/dist/validation/index.d.ts +5 -0
- package/dist/validation/index.js.map +1 -1
- package/package.json +2 -2
- package/src/IcuTranslationProviderMulti.test.ts +18 -40
- package/src/IcuTranslationProviderMulti.ts +27 -37
- package/src/audit/audit-dictionaries.ts +1 -1
- package/src/audit/run-audit.test.ts +6 -7
- package/src/builder-load-registry.ts +26 -5
- package/src/builder-loaders.ts +8 -11
- package/src/builder-types.test.ts +11 -42
- package/src/builder.test.ts +82 -243
- package/src/builder.ts +8 -110
- package/src/codegen/codegen-config-schema.ts +82 -77
- package/src/codegen/config.test.ts +55 -143
- package/src/codegen/config.ts +10 -67
- package/src/codegen/dictionary-spec-contract.test.ts +28 -0
- package/src/codegen/dictionary-spec-contract.ts +138 -0
- package/src/codegen/emit/dictionary-schema-file.ts +7 -43
- package/src/codegen/emit/instance-file.test.ts +35 -52
- package/src/codegen/emit/instance-file.ts +170 -268
- package/src/codegen/emit/namespace-loaders-file.test.ts +72 -74
- package/src/codegen/emit/namespace-loaders-file.ts +147 -90
- package/src/codegen/emit/types-file.test.ts +20 -41
- package/src/codegen/emit/types-file.ts +48 -74
- package/src/codegen/generate-i18n-types.test.ts +163 -492
- package/src/codegen/generate-i18n-types.ts +7 -269
- package/src/codegen/paths.ts +0 -14
- package/src/codegen/project-locales-set-namespace.test.ts +44 -86
- package/src/codegen/read-dictionary.test.ts +27 -9
- package/src/codegen/read-dictionary.ts +18 -40
- package/src/codegen/regenerate-namespaces.ts +180 -0
- package/src/codegen/run-codegen.test.ts +230 -0
- package/src/codegen/run-codegen.ts +252 -0
- package/src/codegen/types.ts +0 -6
- package/src/codegen-config/build-config.ts +4 -23
- package/src/codegen-config/codegen-config.test.ts +10 -6
- package/src/codegen-config/index.ts +18 -3
- package/src/engine.ts +3 -27
- package/src/fetch-artifact.ts +16 -0
- package/src/i18n-handle.ts +202 -0
- package/src/index.ts +15 -34
- package/src/project-locales.ts +2 -2
- package/src/scope-multi.ts +1 -20
- package/src/scope-types.ts +14 -6
- package/src/scope.test.ts +3 -312
- package/src/serialized-state.test.ts +114 -0
- package/src/serialized-state.ts +28 -0
- package/src/setup/setup-i18n.test.ts +22 -33
- package/src/setup/setup-i18n.ts +22 -27
- package/src/types.ts +3 -3
- package/src/validation/index.ts +4 -0
- package/src/IcuTranslationProviderSingle.test.ts +0 -177
- package/src/IcuTranslationProviderSingle.ts +0 -114
- package/src/builder-multi.ts +0 -481
- package/src/codegen/emit/dictionary-file.test.ts +0 -215
- package/src/codegen/emit/dictionary-file.ts +0 -244
- package/src/deep-freeze.test.ts +0 -40
- package/src/deep-freeze.ts +0 -22
- package/src/patch-key.test.ts +0 -186
- package/src/patch-key.ts +0 -140
- package/src/scope-single.ts +0 -85
- package/src/single-builder.ts +0 -153
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
import { GENERATED_FILE_BANNER, toModuleBasename, toRelativeModuleImport } from "../paths.js";
|
|
2
|
-
import type { DeliveryMode } from "../codegen-config-schema.js";
|
|
2
|
+
import type { DeliveryMode, LoaderStrategy } from "../codegen-config-schema.js";
|
|
3
3
|
import type { ImportExtension } from "../types.js";
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* Emits the generated instance module: `createI18n` factory wrapping the ICU provider
|
|
7
|
-
* plus runtime projection helpers (`projectDictionaryLocales`, etc.).
|
|
8
|
-
*/
|
|
5
|
+
/** Emits the generated instance module: `createI18n` factory wrapping the ICU provider. */
|
|
9
6
|
export interface InstanceFileOptions {
|
|
10
|
-
isSingle: boolean;
|
|
11
|
-
hasLazy: boolean;
|
|
12
7
|
typesOutputPath: string;
|
|
13
|
-
namespaceLoadersOutputPath
|
|
8
|
+
namespaceLoadersOutputPath: string;
|
|
14
9
|
paramsTypeName: string;
|
|
15
10
|
schemaTypeName: string;
|
|
16
11
|
localeTypeName: string;
|
|
@@ -18,17 +13,16 @@ export interface InstanceFileOptions {
|
|
|
18
13
|
factoryName: string;
|
|
19
14
|
hasLocaleFallback: boolean;
|
|
20
15
|
hasLocaleType: boolean;
|
|
21
|
-
namespaceNames: string[];
|
|
22
16
|
importExtension: ImportExtension;
|
|
23
17
|
delivery: DeliveryMode;
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
localeDeliveryAreaConstName?: string;
|
|
19
|
+
loaderStrategy?: LoaderStrategy;
|
|
26
20
|
}
|
|
27
21
|
|
|
22
|
+
const STATE_TYPE = `{ dictionary: InitialSchema; resources?: readonly (readonly [string, string])[] }`;
|
|
23
|
+
|
|
28
24
|
export function formatInstanceFile(options: InstanceFileOptions): string {
|
|
29
25
|
const {
|
|
30
|
-
isSingle,
|
|
31
|
-
hasLazy,
|
|
32
26
|
typesOutputPath,
|
|
33
27
|
namespaceLoadersOutputPath,
|
|
34
28
|
paramsTypeName,
|
|
@@ -38,82 +32,44 @@ export function formatInstanceFile(options: InstanceFileOptions): string {
|
|
|
38
32
|
factoryName,
|
|
39
33
|
hasLocaleFallback,
|
|
40
34
|
hasLocaleType,
|
|
41
|
-
namespaceNames,
|
|
42
35
|
importExtension,
|
|
43
36
|
delivery,
|
|
44
|
-
|
|
45
|
-
|
|
37
|
+
localeDeliveryAreaConstName = "LOCALE_DELIVERY_AREA",
|
|
38
|
+
loaderStrategy = "import",
|
|
46
39
|
} = options;
|
|
47
40
|
|
|
48
|
-
const
|
|
49
|
-
const providerClass = isSingle ? "IcuTranslationProviderSingle" : "IcuTranslationProviderMulti";
|
|
41
|
+
const providerClass = "IcuTranslationProviderMulti";
|
|
50
42
|
const typesModule = toModuleBasename(typesOutputPath);
|
|
51
43
|
const typesImport = toRelativeModuleImport(typesModule, importExtension);
|
|
52
|
-
const loadersModule = namespaceLoadersOutputPath
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const providerOptions = hasLocaleFallback
|
|
70
|
-
? `, {\n localeFallback: ${localeFallbackConstName},\n ...options,\n }`
|
|
71
|
-
: `, options`;
|
|
72
|
-
const typesImportLine = hasLocaleType
|
|
73
|
-
? hasLocaleFallback
|
|
74
|
-
? `import { ${localeFallbackConstName}, type ${localeTypeName} } from '${typesImport}';\n`
|
|
75
|
-
: `import type { ${localeTypeName} } from '${typesImport}';\n`
|
|
76
|
-
: "";
|
|
77
|
-
const localesParamType = hasLocaleType ? `readonly ${localeTypeName}[]` : "readonly string[]";
|
|
78
|
-
const fallbackArg = hasLocaleFallback ? `, ${localeFallbackConstName}` : "";
|
|
79
|
-
const packageImports = formatPackageImports(
|
|
80
|
-
providerClass,
|
|
81
|
-
isSingle,
|
|
82
|
-
hasLazy,
|
|
83
|
-
emitDeliveryAreaHelpers
|
|
84
|
-
);
|
|
85
|
-
const projectionBlock = isSingle
|
|
86
|
-
? formatSingleProjectionBlock(
|
|
87
|
-
schemaTypeName,
|
|
88
|
-
localesParamType,
|
|
89
|
-
fallbackArg,
|
|
90
|
-
emitDeliveryAreaHelpers
|
|
91
|
-
)
|
|
92
|
-
: formatMultiProjectionBlock(
|
|
93
|
-
schemaTypeName,
|
|
94
|
-
namespaceNames,
|
|
95
|
-
localesParamType,
|
|
96
|
-
fallbackArg,
|
|
97
|
-
emitDeliveryAreaHelpers
|
|
98
|
-
);
|
|
44
|
+
const loadersModule = toModuleBasename(namespaceLoadersOutputPath);
|
|
45
|
+
const loadersImport = toRelativeModuleImport(loadersModule, importExtension);
|
|
46
|
+
const schemaTypesImport = `import type { ${paramsTypeName}, ${schemaTypeName}, InitialSchema } from '${typesImport}';\n`;
|
|
47
|
+
const typesImportLine = formatTypesValueImport({
|
|
48
|
+
hasLocaleType,
|
|
49
|
+
hasLocaleFallback,
|
|
50
|
+
localeTypeName,
|
|
51
|
+
localeFallbackConstName,
|
|
52
|
+
localeDeliveryAreaConstName,
|
|
53
|
+
delivery,
|
|
54
|
+
typesImport,
|
|
55
|
+
});
|
|
56
|
+
const packageImports = formatPackageImports(providerClass, loaderStrategy);
|
|
57
|
+
const loadersImportLine =
|
|
58
|
+
loaderStrategy === "fetch"
|
|
59
|
+
? `import { createNamespaceLoaders } from '${loadersImport}';\n`
|
|
60
|
+
: `import { namespaceLoaders } from '${loadersImport}';\n`;
|
|
99
61
|
|
|
100
62
|
const createFactoryBlock = formatCreateI18nFactory({
|
|
101
|
-
isSingle,
|
|
102
|
-
hasLazy,
|
|
103
|
-
hasLocaleFallback,
|
|
104
63
|
providerClass,
|
|
105
|
-
providerTypeArgs,
|
|
106
|
-
providerOptions,
|
|
107
|
-
factoryName,
|
|
108
|
-
dictionaryParamType,
|
|
109
64
|
schemaTypeName,
|
|
110
65
|
paramsTypeName,
|
|
111
66
|
localeTypeName,
|
|
112
|
-
|
|
113
|
-
|
|
67
|
+
localeFallbackConstName,
|
|
68
|
+
factoryName,
|
|
69
|
+
hasLocaleFallback,
|
|
114
70
|
delivery,
|
|
115
|
-
|
|
116
|
-
|
|
71
|
+
localeDeliveryAreaConstName,
|
|
72
|
+
loaderStrategy,
|
|
117
73
|
});
|
|
118
74
|
|
|
119
75
|
return (
|
|
@@ -123,233 +79,179 @@ export function formatInstanceFile(options: InstanceFileOptions): string {
|
|
|
123
79
|
`} from '@xndrjs/i18n';\n` +
|
|
124
80
|
schemaTypesImport +
|
|
125
81
|
typesImportLine +
|
|
126
|
-
|
|
82
|
+
loadersImportLine +
|
|
127
83
|
`\n` +
|
|
128
|
-
createFactoryBlock
|
|
129
|
-
projectionBlock
|
|
84
|
+
createFactoryBlock
|
|
130
85
|
);
|
|
131
86
|
}
|
|
132
87
|
|
|
133
|
-
function
|
|
134
|
-
|
|
135
|
-
hasLazy: boolean;
|
|
88
|
+
function formatTypesValueImport(options: {
|
|
89
|
+
hasLocaleType: boolean;
|
|
136
90
|
hasLocaleFallback: boolean;
|
|
91
|
+
localeTypeName: string;
|
|
92
|
+
localeFallbackConstName: string;
|
|
93
|
+
localeDeliveryAreaConstName: string;
|
|
94
|
+
delivery: DeliveryMode;
|
|
95
|
+
typesImport: string;
|
|
96
|
+
}): string {
|
|
97
|
+
const {
|
|
98
|
+
hasLocaleType,
|
|
99
|
+
hasLocaleFallback,
|
|
100
|
+
localeTypeName,
|
|
101
|
+
localeFallbackConstName,
|
|
102
|
+
localeDeliveryAreaConstName,
|
|
103
|
+
delivery,
|
|
104
|
+
typesImport,
|
|
105
|
+
} = options;
|
|
106
|
+
|
|
107
|
+
if (!hasLocaleType && delivery !== "custom") {
|
|
108
|
+
return "";
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const valueNames: string[] = [];
|
|
112
|
+
if (hasLocaleFallback) {
|
|
113
|
+
valueNames.push(localeFallbackConstName);
|
|
114
|
+
}
|
|
115
|
+
if (delivery === "custom") {
|
|
116
|
+
valueNames.push(localeDeliveryAreaConstName);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (valueNames.length > 0 && hasLocaleType) {
|
|
120
|
+
return `import { ${valueNames.join(", ")}, type ${localeTypeName} } from '${typesImport}';\n`;
|
|
121
|
+
}
|
|
122
|
+
if (valueNames.length > 0) {
|
|
123
|
+
return `import { ${valueNames.join(", ")} } from '${typesImport}';\n`;
|
|
124
|
+
}
|
|
125
|
+
if (hasLocaleType) {
|
|
126
|
+
return `import type { ${localeTypeName} } from '${typesImport}';\n`;
|
|
127
|
+
}
|
|
128
|
+
return "";
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function formatCreateI18nFactory(options: {
|
|
137
132
|
providerClass: string;
|
|
138
|
-
providerTypeArgs: string;
|
|
139
|
-
providerOptions: string;
|
|
140
|
-
factoryName: string;
|
|
141
|
-
dictionaryParamType: string;
|
|
142
133
|
schemaTypeName: string;
|
|
143
134
|
paramsTypeName: string;
|
|
144
135
|
localeTypeName: string;
|
|
145
|
-
|
|
146
|
-
|
|
136
|
+
localeFallbackConstName: string;
|
|
137
|
+
factoryName: string;
|
|
138
|
+
hasLocaleFallback: boolean;
|
|
147
139
|
delivery: DeliveryMode;
|
|
148
|
-
|
|
149
|
-
|
|
140
|
+
localeDeliveryAreaConstName: string;
|
|
141
|
+
loaderStrategy: LoaderStrategy;
|
|
150
142
|
}): string {
|
|
151
143
|
const {
|
|
152
|
-
isSingle,
|
|
153
|
-
hasLazy,
|
|
154
144
|
providerClass,
|
|
155
|
-
providerTypeArgs,
|
|
156
|
-
providerOptions,
|
|
157
|
-
factoryName,
|
|
158
|
-
dictionaryParamType,
|
|
159
145
|
schemaTypeName,
|
|
160
146
|
paramsTypeName,
|
|
161
147
|
localeTypeName,
|
|
162
|
-
|
|
163
|
-
|
|
148
|
+
localeFallbackConstName,
|
|
149
|
+
factoryName,
|
|
150
|
+
hasLocaleFallback,
|
|
164
151
|
delivery,
|
|
165
|
-
|
|
166
|
-
|
|
152
|
+
localeDeliveryAreaConstName,
|
|
153
|
+
loaderStrategy,
|
|
167
154
|
} = options;
|
|
168
155
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
`): I18nScopeSingle<${schemaTypeName}, ${paramsTypeName}, ${localeTypeName}> {\n` +
|
|
175
|
-
` return new ${providerClass}<${providerTypeArgs}>(dictionary${providerOptions}).toScope();\n` +
|
|
176
|
-
`}\n`
|
|
177
|
-
);
|
|
178
|
-
}
|
|
156
|
+
const providerTypeArgs = hasLocaleFallback
|
|
157
|
+
? `${schemaTypeName}, ${paramsTypeName}, ${localeTypeName}, typeof ${localeFallbackConstName}`
|
|
158
|
+
: `${schemaTypeName}, ${paramsTypeName}`;
|
|
159
|
+
const handleReturnType = `I18nHandle<${schemaTypeName}, ${paramsTypeName}, ${localeTypeName}>`;
|
|
160
|
+
const handleTypeArgs = `<${schemaTypeName}, ${paramsTypeName}, ${localeTypeName}>`;
|
|
179
161
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
.map((ns) => JSON.stringify(ns))
|
|
185
|
-
.join(", ")}] as const`;
|
|
186
|
-
return (
|
|
187
|
-
`export function ${factoryName}(\n` +
|
|
188
|
-
` dictionary: ${dictionaryParamType},\n` +
|
|
189
|
-
` options?: { onMissing?: OnMissingTranslation },\n` +
|
|
190
|
-
`): I18nScopeMulti<${schemaTypeName}, ${paramsTypeName}, ${localeTypeName}> {\n` +
|
|
191
|
-
` const engine = new ${providerClass}<${providerTypeArgs}>(dictionary${providerOptions});\n` +
|
|
192
|
-
` return engine.toScope({ namespaces: ${namespacesLiteral} });\n` +
|
|
193
|
-
`}\n`
|
|
194
|
-
);
|
|
195
|
-
}
|
|
162
|
+
const partitionForLocale =
|
|
163
|
+
delivery === "custom"
|
|
164
|
+
? ` partitionForLocale: (locale) => ${localeDeliveryAreaConstName}[locale],\n`
|
|
165
|
+
: ` partitionForLocale: (locale) => locale,\n`;
|
|
196
166
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
167
|
+
const optionsType =
|
|
168
|
+
loaderStrategy === "fetch"
|
|
169
|
+
? `{ fetchImpl: FetchArtifact; state?: ${STATE_TYPE}; onMissing?: OnMissingTranslation }`
|
|
170
|
+
: `{ state?: ${STATE_TYPE}; onMissing?: OnMissingTranslation }`;
|
|
200
171
|
|
|
201
|
-
const
|
|
202
|
-
|
|
203
|
-
? `I18nBuilderMultiInitial<${schemaTypeName}, ${paramsTypeName}, ${localeTypeName}, ${localeTypeName}, ${deliveryAreaTypeName}, ${deliveryArtifactsTypeName}>`
|
|
204
|
-
: `I18nBuilderMultiInitial<${schemaTypeName}, ${paramsTypeName}, ${localeTypeName}>`;
|
|
172
|
+
const optionsParam =
|
|
173
|
+
loaderStrategy === "fetch" ? ` options: ${optionsType},\n` : ` options?: ${optionsType},\n`;
|
|
205
174
|
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
?
|
|
209
|
-
:
|
|
175
|
+
const namespaceLoadersLine =
|
|
176
|
+
loaderStrategy === "fetch"
|
|
177
|
+
? ` namespaceLoaders: createNamespaceLoaders(fetchImpl),\n`
|
|
178
|
+
: ` namespaceLoaders,\n`;
|
|
210
179
|
|
|
211
180
|
return (
|
|
212
181
|
`export function ${factoryName}(\n` +
|
|
213
|
-
|
|
214
|
-
`
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
182
|
+
optionsParam +
|
|
183
|
+
`): ${handleReturnType} {\n` +
|
|
184
|
+
formatBody({
|
|
185
|
+
providerClass,
|
|
186
|
+
providerTypeArgs,
|
|
187
|
+
hasLocaleFallback,
|
|
188
|
+
localeFallbackConstName,
|
|
189
|
+
loaderStrategy,
|
|
190
|
+
}) +
|
|
191
|
+
` engine.seedBuilderResources(normalized.resources);\n` +
|
|
192
|
+
` return createI18nHandle${handleTypeArgs}(engine, {\n` +
|
|
193
|
+
namespaceLoadersLine +
|
|
194
|
+
partitionForLocale +
|
|
195
|
+
` } as I18nHandleOptions<${schemaTypeName}, ${localeTypeName}>);\n` +
|
|
220
196
|
`}\n`
|
|
221
197
|
);
|
|
222
198
|
}
|
|
223
199
|
|
|
224
|
-
function
|
|
225
|
-
providerClass: string
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
} else {
|
|
239
|
-
imports.push("projectNamespaceLocalesCore", "projectDictionaryLocalesCore");
|
|
240
|
-
if (emitDeliveryAreaHelpers) {
|
|
241
|
-
imports.push("projectNamespaceForDeliveryAreaCore", "projectDictionaryForDeliveryAreaCore");
|
|
242
|
-
}
|
|
243
|
-
if (hasLazy) {
|
|
244
|
-
imports.push(
|
|
245
|
-
"createI18nMultiBuilder",
|
|
246
|
-
"type I18nBuilderMultiInitial",
|
|
247
|
-
"type I18nBuilderMultiOptions"
|
|
248
|
-
);
|
|
249
|
-
} else {
|
|
250
|
-
imports.push("type I18nScopeMulti");
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
imports.push("type OnMissingTranslation");
|
|
255
|
-
return imports.join(",\n ");
|
|
256
|
-
}
|
|
200
|
+
function formatBody(options: {
|
|
201
|
+
providerClass: string;
|
|
202
|
+
providerTypeArgs: string;
|
|
203
|
+
hasLocaleFallback: boolean;
|
|
204
|
+
localeFallbackConstName: string;
|
|
205
|
+
loaderStrategy: LoaderStrategy;
|
|
206
|
+
}): string {
|
|
207
|
+
const {
|
|
208
|
+
providerClass,
|
|
209
|
+
providerTypeArgs,
|
|
210
|
+
hasLocaleFallback,
|
|
211
|
+
localeFallbackConstName,
|
|
212
|
+
loaderStrategy,
|
|
213
|
+
} = options;
|
|
257
214
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
)
|
|
264
|
-
|
|
265
|
-
`\n` +
|
|
266
|
-
`export function projectDictionaryLocales(\n` +
|
|
267
|
-
` dictionary: ${schemaTypeName},\n` +
|
|
268
|
-
` locales: ${localesParamType},\n` +
|
|
269
|
-
`): ${schemaTypeName} {\n` +
|
|
270
|
-
` return projectNamespaceLocalesCore(dictionary, locales${fallbackArg});\n` +
|
|
271
|
-
`}\n`;
|
|
215
|
+
if (loaderStrategy === "fetch") {
|
|
216
|
+
const engineBlock = hasLocaleFallback
|
|
217
|
+
? ` const engine = new ${providerClass}<${providerTypeArgs}>(normalized.dictionary, {\n` +
|
|
218
|
+
` localeFallback: ${localeFallbackConstName},\n` +
|
|
219
|
+
` ...providerOptions,\n` +
|
|
220
|
+
` });\n`
|
|
221
|
+
: ` const engine = new ${providerClass}<${providerTypeArgs}>(normalized.dictionary, providerOptions);\n`;
|
|
272
222
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
` areaLocales: ${localesParamType},\n` +
|
|
279
|
-
`): ${schemaTypeName} {\n` +
|
|
280
|
-
` return projectNamespaceForDeliveryAreaCore(dictionary, areaLocales${fallbackArg});\n` +
|
|
281
|
-
`}\n`;
|
|
223
|
+
return (
|
|
224
|
+
` const { fetchImpl, state, ...providerOptions } = options;\n` +
|
|
225
|
+
` const normalized = normalizeI18nCreateInput(state);\n` +
|
|
226
|
+
engineBlock
|
|
227
|
+
);
|
|
282
228
|
}
|
|
283
229
|
|
|
284
|
-
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
localesParamType: string,
|
|
291
|
-
fallbackArg: string,
|
|
292
|
-
emitDeliveryAreaHelpers: boolean
|
|
293
|
-
): string {
|
|
294
|
-
const namespaceLocaleOverloads = namespaceNames
|
|
295
|
-
.map(
|
|
296
|
-
(namespace) =>
|
|
297
|
-
`export function projectNamespaceLocales(\n` +
|
|
298
|
-
` dictionary: ${schemaTypeName}["${namespace}"],\n` +
|
|
299
|
-
` locales: ${localesParamType},\n` +
|
|
300
|
-
`): ${schemaTypeName}["${namespace}"];`
|
|
301
|
-
)
|
|
302
|
-
.join("\n");
|
|
303
|
-
|
|
304
|
-
const namespaceDeliveryOverloads = emitDeliveryAreaHelpers
|
|
305
|
-
? namespaceNames
|
|
306
|
-
.map(
|
|
307
|
-
(namespace) =>
|
|
308
|
-
`export function projectNamespaceForDeliveryArea(\n` +
|
|
309
|
-
` dictionary: ${schemaTypeName}["${namespace}"],\n` +
|
|
310
|
-
` areaLocales: ${localesParamType},\n` +
|
|
311
|
-
`): ${schemaTypeName}["${namespace}"];`
|
|
312
|
-
)
|
|
313
|
-
.join("\n")
|
|
314
|
-
: "";
|
|
230
|
+
const engineBlock = hasLocaleFallback
|
|
231
|
+
? ` const engine = new ${providerClass}<${providerTypeArgs}>(normalized.dictionary, {\n` +
|
|
232
|
+
` localeFallback: ${localeFallbackConstName},\n` +
|
|
233
|
+
` ...providerOptions,\n` +
|
|
234
|
+
` });\n`
|
|
235
|
+
: ` const engine = new ${providerClass}<${providerTypeArgs}>(normalized.dictionary, providerOptions);\n`;
|
|
315
236
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
`
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
` return projectDictionaryLocalesCore(dictionary, locales${fallbackArg});\n` +
|
|
323
|
-
`}\n` +
|
|
324
|
-
`\n` +
|
|
325
|
-
namespaceLocaleOverloads +
|
|
326
|
-
`\n` +
|
|
327
|
-
`export function projectNamespaceLocales(\n` +
|
|
328
|
-
` dictionary: ${schemaTypeName}[keyof ${schemaTypeName}],\n` +
|
|
329
|
-
` locales: ${localesParamType},\n` +
|
|
330
|
-
`): ${schemaTypeName}[keyof ${schemaTypeName}] {\n` +
|
|
331
|
-
` return projectNamespaceLocalesCore(dictionary, locales${fallbackArg});\n` +
|
|
332
|
-
`}\n`;
|
|
237
|
+
return (
|
|
238
|
+
` const { state, ...providerOptions } = options ?? {};\n` +
|
|
239
|
+
` const normalized = normalizeI18nCreateInput(state);\n` +
|
|
240
|
+
engineBlock
|
|
241
|
+
);
|
|
242
|
+
}
|
|
333
243
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
`\n` +
|
|
346
|
-
`export function projectNamespaceForDeliveryArea(\n` +
|
|
347
|
-
` dictionary: ${schemaTypeName}[keyof ${schemaTypeName}],\n` +
|
|
348
|
-
` areaLocales: ${localesParamType},\n` +
|
|
349
|
-
`): ${schemaTypeName}[keyof ${schemaTypeName}] {\n` +
|
|
350
|
-
` return projectNamespaceForDeliveryAreaCore(dictionary, areaLocales${fallbackArg});\n` +
|
|
351
|
-
`}\n`;
|
|
244
|
+
function formatPackageImports(providerClass: string, loaderStrategy: LoaderStrategy): string {
|
|
245
|
+
const names = [
|
|
246
|
+
providerClass,
|
|
247
|
+
"createI18nHandle",
|
|
248
|
+
"normalizeI18nCreateInput",
|
|
249
|
+
"type I18nHandle",
|
|
250
|
+
"type I18nHandleOptions",
|
|
251
|
+
"type OnMissingTranslation",
|
|
252
|
+
];
|
|
253
|
+
if (loaderStrategy === "fetch") {
|
|
254
|
+
names.push("type FetchArtifact");
|
|
352
255
|
}
|
|
353
|
-
|
|
354
|
-
return block;
|
|
256
|
+
return names.join(",\n ");
|
|
355
257
|
}
|