@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.
Files changed (93) hide show
  1. package/README.md +1 -2
  2. package/dist/cli/audit.js +739 -0
  3. package/dist/cli/audit.js.map +1 -0
  4. package/dist/cli/codegen.js +1471 -0
  5. package/dist/cli/codegen.js.map +1 -0
  6. package/dist/cli/setup.js +148 -0
  7. package/dist/cli/setup.js.map +1 -0
  8. package/dist/codegen/index.js +43 -40
  9. package/dist/codegen/index.js.map +1 -1
  10. package/package.json +6 -9
  11. package/bin/audit.mjs +0 -14
  12. package/bin/codegen.mjs +0 -17
  13. package/bin/setup.mjs +0 -14
  14. package/src/IcuTranslationProviderMulti.test.ts +0 -215
  15. package/src/IcuTranslationProviderMulti.ts +0 -188
  16. package/src/audit/audit-dictionaries.test.ts +0 -134
  17. package/src/audit/audit-dictionaries.ts +0 -178
  18. package/src/audit/run-audit.test.ts +0 -169
  19. package/src/audit/run-audit.ts +0 -94
  20. package/src/builder-load-registry.test.ts +0 -44
  21. package/src/builder-load-registry.ts +0 -78
  22. package/src/builder-loaders.ts +0 -15
  23. package/src/builder-types.test.ts +0 -57
  24. package/src/builder-types.ts +0 -24
  25. package/src/builder.test.ts +0 -303
  26. package/src/builder.ts +0 -15
  27. package/src/codegen/codegen-config-schema.ts +0 -156
  28. package/src/codegen/config.test.ts +0 -231
  29. package/src/codegen/config.ts +0 -42
  30. package/src/codegen/constants.ts +0 -9
  31. package/src/codegen/delivery-artifacts.test.ts +0 -167
  32. package/src/codegen/delivery-artifacts.ts +0 -154
  33. package/src/codegen/dictionary-spec-contract.test.ts +0 -28
  34. package/src/codegen/dictionary-spec-contract.ts +0 -138
  35. package/src/codegen/emit/dictionary-schema-file.ts +0 -113
  36. package/src/codegen/emit/instance-file.test.ts +0 -71
  37. package/src/codegen/emit/instance-file.ts +0 -257
  38. package/src/codegen/emit/namespace-loaders-file.test.ts +0 -251
  39. package/src/codegen/emit/namespace-loaders-file.ts +0 -229
  40. package/src/codegen/emit/types-file.test.ts +0 -96
  41. package/src/codegen/emit/types-file.ts +0 -142
  42. package/src/codegen/fixtures/billing-namespace.json +0 -6
  43. package/src/codegen/generate-i18n-types.test.ts +0 -1137
  44. package/src/codegen/generate-i18n-types.ts +0 -20
  45. package/src/codegen/icu-analysis.ts +0 -110
  46. package/src/codegen/locale-fallback.ts +0 -73
  47. package/src/codegen/locale-policy.test.ts +0 -35
  48. package/src/codegen/locale-policy.ts +0 -30
  49. package/src/codegen/paths.ts +0 -44
  50. package/src/codegen/project-locales-set-namespace.test.ts +0 -134
  51. package/src/codegen/read-dictionary.test.ts +0 -594
  52. package/src/codegen/read-dictionary.ts +0 -260
  53. package/src/codegen/regenerate-namespaces.ts +0 -180
  54. package/src/codegen/run-codegen.test.ts +0 -230
  55. package/src/codegen/run-codegen.ts +0 -252
  56. package/src/codegen/types.ts +0 -10
  57. package/src/codegen/write-file-if-changed.test.ts +0 -42
  58. package/src/codegen/write-file-if-changed.ts +0 -20
  59. package/src/codegen-config/build-config.ts +0 -15
  60. package/src/codegen-config/codegen-config.test.ts +0 -36
  61. package/src/codegen-config/index.ts +0 -37
  62. package/src/codegen-config/type-names.ts +0 -20
  63. package/src/codegen-config/write-config.ts +0 -8
  64. package/src/engine.ts +0 -47
  65. package/src/fetch-artifact.ts +0 -16
  66. package/src/format-core.ts +0 -91
  67. package/src/i18n-handle.ts +0 -216
  68. package/src/icu/extract-variables.test.ts +0 -199
  69. package/src/icu/extract-variables.ts +0 -227
  70. package/src/icu/parse-template.ts +0 -31
  71. package/src/index.ts +0 -63
  72. package/src/load-state.ts +0 -15
  73. package/src/project-locales.test.ts +0 -280
  74. package/src/project-locales.ts +0 -211
  75. package/src/resolve-locale.test.ts +0 -91
  76. package/src/resolve-locale.ts +0 -88
  77. package/src/scope-multi.ts +0 -105
  78. package/src/scope-types.ts +0 -35
  79. package/src/scope.test.ts +0 -172
  80. package/src/serialized-state.test.ts +0 -114
  81. package/src/serialized-state.ts +0 -28
  82. package/src/setup/setup-i18n.test.ts +0 -85
  83. package/src/setup/setup-i18n.ts +0 -156
  84. package/src/types.ts +0 -65
  85. package/src/validation/create-args-schema.ts +0 -76
  86. package/src/validation/create-normalized-schema.ts +0 -52
  87. package/src/validation/errors.ts +0 -43
  88. package/src/validation/index.ts +0 -202
  89. package/src/validation/normalize.ts +0 -299
  90. package/src/validation/to-dictionary.ts +0 -67
  91. package/src/validation/types.ts +0 -82
  92. package/src/validation/validate-normalized.ts +0 -133
  93. 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
- }
@@ -1,6 +0,0 @@
1
- {
2
- "invoice_summary": {
3
- "en": "You have {count, plural, one {1 invoice} other {{count} invoices}}",
4
- "it": "Hai {count, plural, one {1 fattura} other {{count} fatture}}"
5
- }
6
- }