@vocab/core 1.7.1-isolate-rolldown-runtime-20251217033548 → 1.7.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 +827 -0
- package/dist/icu-handler-CuHzcwEH.cjs +28 -0
- package/dist/{icu-handler-BALMAIaM.cjs.map → icu-handler-CuHzcwEH.cjs.map} +1 -1
- package/dist/icu-handler-DpDWxKGr.mjs +22 -0
- package/dist/{icu-handler-CuYAM62Z.mjs.map → icu-handler-DpDWxKGr.mjs.map} +1 -1
- package/dist/icu-handler.cjs +1 -2
- package/dist/icu-handler.d.cts +3 -3
- package/dist/icu-handler.d.mts +3 -3
- package/dist/icu-handler.mjs +1 -2
- package/dist/index.cjs +86 -128
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +50 -3
- package/dist/index.d.mts +50 -3
- package/dist/index.mjs +78 -120
- package/dist/index.mjs.map +1 -1
- package/dist/{chunk-YUyckAMm.mjs → rolldown-runtime-CHUWjh9U.mjs} +1 -2
- package/dist/{chunk-BuD6V4w7.cjs → rolldown-runtime-y5NzCiFd.cjs} +0 -7
- package/dist/runtime.cjs +6 -13
- package/dist/runtime.cjs.map +1 -1
- package/dist/runtime.d.cts +4 -4
- package/dist/runtime.d.mts +4 -4
- package/dist/runtime.mjs +6 -13
- package/dist/runtime.mjs.map +1 -1
- package/dist/translation-file-Ca5lZ9Dd.d.mts +7 -0
- package/dist/translation-file-CqTkqKMS.d.cts +7 -0
- package/dist/{translation-file-C23K0G2v.cjs → translation-file-U7k1_uqE.mjs} +2 -16
- package/dist/{translation-file-C23K0G2v.cjs.map → translation-file-U7k1_uqE.mjs.map} +1 -1
- package/dist/{translation-file-D18r2tf_.mjs → translation-file-rax5G8Pd.cjs} +7 -4
- package/dist/{translation-file-D18r2tf_.mjs.map → translation-file-rax5G8Pd.cjs.map} +1 -1
- package/dist/translation-file.cjs +1 -2
- package/dist/translation-file.d.cts +1 -1
- package/dist/translation-file.d.mts +2 -1
- package/dist/translation-file.mjs +1 -2
- package/dist/types-C00NNtxU.d.cts +146 -0
- package/dist/types-DpryIirw.d.mts +146 -0
- package/package.json +1 -1
- package/dist/icu-handler-BALMAIaM.cjs +0 -37
- package/dist/icu-handler-CuYAM62Z.mjs +0 -26
- package/dist/icu-handler.cjs.map +0 -1
- package/dist/translation-file-DGrsUC73.d.cts +0 -8
- package/dist/translation-file-TvWb96IF.d.mts +0 -8
- package/dist/translation-file.cjs.map +0 -1
- package/dist/types-Dhy3ksw5.d.cts +0 -8
- package/dist/types-tajuHnML.d.mts +0 -8
package/dist/runtime.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.cjs","names":[],"sources":["../src/runtime.ts"],"sourcesContent":["import type { TranslationModule, TranslationMessagesByKey } from './types';\n\nimport { getParsedICUMessages } from './icu-handler';\n\nexport { createTranslationFile } from './translation-file';\n\nexport const createLanguage = (\n module: TranslationMessagesByKey,\n): TranslationModule<any> => ({\n getValue: (locale) => getParsedICUMessages(module, locale),\n load: () => Promise.resolve(),\n});\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"runtime.cjs","names":["getParsedICUMessages","module"],"sources":["../src/runtime.ts"],"sourcesContent":["import type { TranslationModule, TranslationMessagesByKey } from './types';\n\nimport { getParsedICUMessages } from './icu-handler';\n\nexport { createTranslationFile } from './translation-file';\n\nexport const createLanguage = (\n module: TranslationMessagesByKey,\n): TranslationModule<any> => ({\n getValue: (locale) => getParsedICUMessages(module, locale),\n load: () => Promise.resolve(),\n});\n"],"mappings":";;;;AAMA,MAAa,kBACX,cAC4B;CAC5B,WAAW,WAAWA,yCAAqBC,UAAQ,OAAO;CAC1D,YAAY,QAAQ,SAAS;CAC9B"}
|
package/dist/runtime.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { n as init_translation_file_d, t as createTranslationFile } from "./translation-file-DGrsUC73.cjs";
|
|
1
|
+
import { b as TranslationModule, y as TranslationMessagesByKey } from "./types-C00NNtxU.cjs";
|
|
2
|
+
import { t as createTranslationFile } from "./translation-file-CqTkqKMS.cjs";
|
|
4
3
|
|
|
5
4
|
//#region src/runtime.d.ts
|
|
6
|
-
|
|
5
|
+
declare const createLanguage: (module: TranslationMessagesByKey) => TranslationModule<any>;
|
|
6
|
+
//#endregion
|
|
7
7
|
export { createLanguage, createTranslationFile };
|
|
8
8
|
//# sourceMappingURL=runtime.d.cts.map
|
package/dist/runtime.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { n as init_translation_file_d, t as createTranslationFile } from "./translation-file-TvWb96IF.mjs";
|
|
1
|
+
import { b as TranslationModule, y as TranslationMessagesByKey } from "./types-DpryIirw.mjs";
|
|
2
|
+
import { t as createTranslationFile } from "./translation-file-Ca5lZ9Dd.mjs";
|
|
4
3
|
|
|
5
4
|
//#region src/runtime.d.ts
|
|
6
|
-
|
|
5
|
+
declare const createLanguage: (module: TranslationMessagesByKey) => TranslationModule<any>;
|
|
6
|
+
//#endregion
|
|
7
7
|
export { createLanguage, createTranslationFile };
|
|
8
8
|
//# sourceMappingURL=runtime.d.mts.map
|
package/dist/runtime.mjs
CHANGED
|
@@ -1,19 +1,12 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import {
|
|
3
|
-
import { n as init_translation_file, t as createTranslationFile } from "./translation-file-D18r2tf_.mjs";
|
|
1
|
+
import { t as getParsedICUMessages } from "./icu-handler-DpDWxKGr.mjs";
|
|
2
|
+
import { t as createTranslationFile } from "./translation-file-U7k1_uqE.mjs";
|
|
4
3
|
|
|
5
4
|
//#region src/runtime.ts
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
createLanguage = (module) => ({
|
|
11
|
-
getValue: (locale) => getParsedICUMessages(module, locale),
|
|
12
|
-
load: () => Promise.resolve()
|
|
13
|
-
});
|
|
14
|
-
}));
|
|
5
|
+
const createLanguage = (module) => ({
|
|
6
|
+
getValue: (locale) => getParsedICUMessages(module, locale),
|
|
7
|
+
load: () => Promise.resolve()
|
|
8
|
+
});
|
|
15
9
|
|
|
16
10
|
//#endregion
|
|
17
|
-
init_runtime();
|
|
18
11
|
export { createLanguage, createTranslationFile };
|
|
19
12
|
//# sourceMappingURL=runtime.mjs.map
|
package/dist/runtime.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.mjs","names":[],"sources":["../src/runtime.ts"],"sourcesContent":["import type { TranslationModule, TranslationMessagesByKey } from './types';\n\nimport { getParsedICUMessages } from './icu-handler';\n\nexport { createTranslationFile } from './translation-file';\n\nexport const createLanguage = (\n module: TranslationMessagesByKey,\n): TranslationModule<any> => ({\n getValue: (locale) => getParsedICUMessages(module, locale),\n load: () => Promise.resolve(),\n});\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"runtime.mjs","names":[],"sources":["../src/runtime.ts"],"sourcesContent":["import type { TranslationModule, TranslationMessagesByKey } from './types';\n\nimport { getParsedICUMessages } from './icu-handler';\n\nexport { createTranslationFile } from './translation-file';\n\nexport const createLanguage = (\n module: TranslationMessagesByKey,\n): TranslationModule<any> => ({\n getValue: (locale) => getParsedICUMessages(module, locale),\n load: () => Promise.resolve(),\n});\n"],"mappings":";;;;AAMA,MAAa,kBACX,YAC4B;CAC5B,WAAW,WAAW,qBAAqB,QAAQ,OAAO;CAC1D,YAAY,QAAQ,SAAS;CAC9B"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { c as ParsedFormatFnByKey, p as TranslationFile, r as LanguageName, x as TranslationModuleByLanguage } from "./types-DpryIirw.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/translation-file.d.ts
|
|
4
|
+
declare function createTranslationFile<Language extends LanguageName, FormatFnByKey extends ParsedFormatFnByKey>(translationsByLanguage: TranslationModuleByLanguage<Language, FormatFnByKey>): TranslationFile<Language, FormatFnByKey>;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { createTranslationFile as t };
|
|
7
|
+
//# sourceMappingURL=translation-file-Ca5lZ9Dd.d.mts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { c as ParsedFormatFnByKey, p as TranslationFile, r as LanguageName, x as TranslationModuleByLanguage } from "./types-C00NNtxU.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/translation-file.d.ts
|
|
4
|
+
declare function createTranslationFile<Language extends LanguageName, FormatFnByKey extends ParsedFormatFnByKey>(translationsByLanguage: TranslationModuleByLanguage<Language, FormatFnByKey>): TranslationFile<Language, FormatFnByKey>;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { createTranslationFile as t };
|
|
7
|
+
//# sourceMappingURL=translation-file-CqTkqKMS.d.cts.map
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
const require_chunk = require('./chunk-BuD6V4w7.cjs');
|
|
2
|
-
|
|
3
1
|
//#region src/translation-file.ts
|
|
4
2
|
function createTranslationFile(translationsByLanguage) {
|
|
5
3
|
function getByLanguage(language) {
|
|
@@ -24,19 +22,7 @@ function createTranslationFile(translationsByLanguage) {
|
|
|
24
22
|
}
|
|
25
23
|
};
|
|
26
24
|
}
|
|
27
|
-
var init_translation_file = require_chunk.__esmMin((() => {}));
|
|
28
25
|
|
|
29
26
|
//#endregion
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
get: function () {
|
|
33
|
-
return createTranslationFile;
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
Object.defineProperty(exports, 'init_translation_file', {
|
|
37
|
-
enumerable: true,
|
|
38
|
-
get: function () {
|
|
39
|
-
return init_translation_file;
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
//# sourceMappingURL=translation-file-C23K0G2v.cjs.map
|
|
27
|
+
export { createTranslationFile as t };
|
|
28
|
+
//# sourceMappingURL=translation-file-U7k1_uqE.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"translation-file-
|
|
1
|
+
{"version":3,"file":"translation-file-U7k1_uqE.mjs","names":[],"sources":["../src/translation-file.ts"],"sourcesContent":["import type {\n TranslationModule,\n TranslationModuleByLanguage,\n ParsedICUMessages,\n LanguageName,\n ParsedFormatFnByKey,\n TranslationFile,\n} from './types';\n\nexport function createTranslationFile<\n Language extends LanguageName,\n FormatFnByKey extends ParsedFormatFnByKey,\n>(\n translationsByLanguage: TranslationModuleByLanguage<Language, FormatFnByKey>,\n): TranslationFile<Language, FormatFnByKey> {\n function getByLanguage(language: Language): TranslationModule<FormatFnByKey> {\n const translationModule = translationsByLanguage[language];\n if (!translationModule) {\n throw new Error(\n `Attempted to retrieve translations for unknown language \"${language}\"`,\n );\n }\n return translationModule;\n }\n\n return {\n getLoadedMessages(\n language: Language,\n locale?: string,\n ): ParsedICUMessages<FormatFnByKey> | null {\n const translationModule = getByLanguage(language);\n return translationModule.getValue(locale || language) || null;\n },\n getMessages(\n language: Language,\n locale?: string,\n ): Promise<ParsedICUMessages<FormatFnByKey>> {\n const translationModule = getByLanguage(language);\n return translationModule.load().then(() => {\n const result = translationModule.getValue(locale || language);\n if (!result) {\n throw new Error(\n `Unable to find translations for ${language} after attempting to load. Module may have failed to load or an internal error may have occurred.`,\n );\n }\n return result;\n });\n },\n load(language: Language): Promise<void> {\n const translationModule = getByLanguage(language);\n return translationModule.load();\n },\n };\n}\n"],"mappings":";AASA,SAAgB,sBAId,wBAC0C;CAC1C,SAAS,cAAc,UAAsD;EAC3E,MAAM,oBAAoB,uBAAuB;AACjD,MAAI,CAAC,kBACH,OAAM,IAAI,MACR,4DAA4D,SAAS,GACtE;AAEH,SAAO;;AAGT,QAAO;EACL,kBACE,UACA,QACyC;AAEzC,UAD0B,cAAc,SAAS,CACxB,SAAS,UAAU,SAAS,IAAI;;EAE3D,YACE,UACA,QAC2C;GAC3C,MAAM,oBAAoB,cAAc,SAAS;AACjD,UAAO,kBAAkB,MAAM,CAAC,WAAW;IACzC,MAAM,SAAS,kBAAkB,SAAS,UAAU,SAAS;AAC7D,QAAI,CAAC,OACH,OAAM,IAAI,MACR,mCAAmC,SAAS,mGAC7C;AAEH,WAAO;KACP;;EAEJ,KAAK,UAAmC;AAEtC,UAD0B,cAAc,SAAS,CACxB,MAAM;;EAElC"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { t as __esmMin } from "./chunk-YUyckAMm.mjs";
|
|
2
1
|
|
|
3
2
|
//#region src/translation-file.ts
|
|
4
3
|
function createTranslationFile(translationsByLanguage) {
|
|
@@ -24,8 +23,12 @@ function createTranslationFile(translationsByLanguage) {
|
|
|
24
23
|
}
|
|
25
24
|
};
|
|
26
25
|
}
|
|
27
|
-
var init_translation_file = __esmMin((() => {}));
|
|
28
26
|
|
|
29
27
|
//#endregion
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
Object.defineProperty(exports, 'createTranslationFile', {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: function () {
|
|
31
|
+
return createTranslationFile;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
//# sourceMappingURL=translation-file-rax5G8Pd.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"translation-file-
|
|
1
|
+
{"version":3,"file":"translation-file-rax5G8Pd.cjs","names":[],"sources":["../src/translation-file.ts"],"sourcesContent":["import type {\n TranslationModule,\n TranslationModuleByLanguage,\n ParsedICUMessages,\n LanguageName,\n ParsedFormatFnByKey,\n TranslationFile,\n} from './types';\n\nexport function createTranslationFile<\n Language extends LanguageName,\n FormatFnByKey extends ParsedFormatFnByKey,\n>(\n translationsByLanguage: TranslationModuleByLanguage<Language, FormatFnByKey>,\n): TranslationFile<Language, FormatFnByKey> {\n function getByLanguage(language: Language): TranslationModule<FormatFnByKey> {\n const translationModule = translationsByLanguage[language];\n if (!translationModule) {\n throw new Error(\n `Attempted to retrieve translations for unknown language \"${language}\"`,\n );\n }\n return translationModule;\n }\n\n return {\n getLoadedMessages(\n language: Language,\n locale?: string,\n ): ParsedICUMessages<FormatFnByKey> | null {\n const translationModule = getByLanguage(language);\n return translationModule.getValue(locale || language) || null;\n },\n getMessages(\n language: Language,\n locale?: string,\n ): Promise<ParsedICUMessages<FormatFnByKey>> {\n const translationModule = getByLanguage(language);\n return translationModule.load().then(() => {\n const result = translationModule.getValue(locale || language);\n if (!result) {\n throw new Error(\n `Unable to find translations for ${language} after attempting to load. Module may have failed to load or an internal error may have occurred.`,\n );\n }\n return result;\n });\n },\n load(language: Language): Promise<void> {\n const translationModule = getByLanguage(language);\n return translationModule.load();\n },\n };\n}\n"],"mappings":";;AASA,SAAgB,sBAId,wBAC0C;CAC1C,SAAS,cAAc,UAAsD;EAC3E,MAAM,oBAAoB,uBAAuB;AACjD,MAAI,CAAC,kBACH,OAAM,IAAI,MACR,4DAA4D,SAAS,GACtE;AAEH,SAAO;;AAGT,QAAO;EACL,kBACE,UACA,QACyC;AAEzC,UAD0B,cAAc,SAAS,CACxB,SAAS,UAAU,SAAS,IAAI;;EAE3D,YACE,UACA,QAC2C;GAC3C,MAAM,oBAAoB,cAAc,SAAS;AACjD,UAAO,kBAAkB,MAAM,CAAC,WAAW;IACzC,MAAM,SAAS,kBAAkB,SAAS,UAAU,SAAS;AAC7D,QAAI,CAAC,OACH,OAAM,IAAI,MACR,mCAAmC,SAAS,mGAC7C;AAEH,WAAO;KACP;;EAEJ,KAAK,UAAmC;AAEtC,UAD0B,cAAc,SAAS,CACxB,MAAM;;EAElC"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
const require_translation_file = require('./translation-file-
|
|
1
|
+
const require_translation_file = require('./translation-file-rax5G8Pd.cjs');
|
|
2
2
|
|
|
3
|
-
require_translation_file.init_translation_file();
|
|
4
3
|
exports.createTranslationFile = require_translation_file.createTranslationFile;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as createTranslationFile } from "./translation-file-CqTkqKMS.cjs";
|
|
2
2
|
export { createTranslationFile };
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { FormatXMLElementFn } from "intl-messageformat";
|
|
2
|
+
|
|
3
|
+
//#region src/types.d.ts
|
|
4
|
+
type LanguageName = string;
|
|
5
|
+
type TranslationKey = string;
|
|
6
|
+
type TranslationMessage = string;
|
|
7
|
+
type ParsedFormatFn = (parts: any) => any;
|
|
8
|
+
type ParsedFormatFnByKey = Record<string, ParsedFormatFn>;
|
|
9
|
+
/**
|
|
10
|
+
* Equivalent to the `string` type, but tricks TypeScript into prodiving
|
|
11
|
+
* suggestions for string literals passed into the `Suggestions` generic parameter
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* type AnyAnimal = StringWithSuggestions<"cat" | "dog">;
|
|
15
|
+
* // Suggests cat and dog, but accepts any string
|
|
16
|
+
* const animal: AnyAnimal = "";
|
|
17
|
+
*/
|
|
18
|
+
type StringWithSuggestions<Suggestions extends string> = Suggestions | Omit<string, Suggestions>;
|
|
19
|
+
/**
|
|
20
|
+
* ParsedICUMessage A strictly typed formatter from intl-messageformat
|
|
21
|
+
*/
|
|
22
|
+
interface ParsedICUMessage<FormatFn extends ParsedFormatFn> {
|
|
23
|
+
format: FormatFn;
|
|
24
|
+
}
|
|
25
|
+
type ParsedICUMessages<FormatFnByKey extends ParsedFormatFnByKey> = { [key in keyof FormatFnByKey]: ParsedICUMessage<FormatFnByKey[key]> };
|
|
26
|
+
/**
|
|
27
|
+
* TranslationModule is a wrapper around a potentially asynchronously loaded set of ParsedICUMessages
|
|
28
|
+
*/
|
|
29
|
+
type TranslationModule<FormatFnByKey extends ParsedFormatFnByKey> = {
|
|
30
|
+
getValue: (locale: string) => ParsedICUMessages<FormatFnByKey> | undefined;
|
|
31
|
+
load: () => Promise<void>;
|
|
32
|
+
};
|
|
33
|
+
type TranslationModuleByLanguage<Language extends LanguageName, FormatFnByKey extends ParsedFormatFnByKey> = Record<Language, TranslationModule<FormatFnByKey>>;
|
|
34
|
+
/**
|
|
35
|
+
* TranslationFile contains a record of TranslationModules per language, exposing a set of methods to load and return the module by language
|
|
36
|
+
*/
|
|
37
|
+
type TranslationFile<Language extends LanguageName, FormatFnByKey extends ParsedFormatFnByKey> = {
|
|
38
|
+
/**
|
|
39
|
+
* Retrieve messages. If not loaded, will attempt to load messages and resolve once complete.
|
|
40
|
+
*/
|
|
41
|
+
getMessages: (language: Language, locale?: string) => Promise<ParsedICUMessages<FormatFnByKey>>;
|
|
42
|
+
/**
|
|
43
|
+
* Retrieve already loaded messages. Will return null if no messages have been loaded.
|
|
44
|
+
*/
|
|
45
|
+
getLoadedMessages: (language: Language, locale?: string) => ParsedICUMessages<FormatFnByKey> | null;
|
|
46
|
+
/**
|
|
47
|
+
* Load messages for the given language. Resolving once complete.
|
|
48
|
+
*/
|
|
49
|
+
load: (language: Language) => Promise<void>;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* A utility type to get the union of all translation keys from a translation file
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* // translations.json
|
|
56
|
+
* {
|
|
57
|
+
* "Hello": {
|
|
58
|
+
* "message": "Hello",
|
|
59
|
+
* },
|
|
60
|
+
* "Goodbye": {
|
|
61
|
+
* "message": "Goodbye",
|
|
62
|
+
* },
|
|
63
|
+
* }
|
|
64
|
+
*
|
|
65
|
+
* // myFile.ts
|
|
66
|
+
* import { TranslationKeys } from '@vocab/core';
|
|
67
|
+
* import translations from './.vocab';
|
|
68
|
+
*
|
|
69
|
+
* // 'Hello' | 'Goodbye'
|
|
70
|
+
* type TheTranslationKeys = TranslationKeys<typeof translations>;
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* import { TranslationKeys } from '@vocab/core';
|
|
74
|
+
* import fooTranslations from './foo.vocab';
|
|
75
|
+
* import barTranslations from './bar.vocab';
|
|
76
|
+
*
|
|
77
|
+
* // It even works with multiple translation files
|
|
78
|
+
* type FooBarTranslationKeys = TranslationKeys<typeof fooTranslations | typeof barTranslations>;
|
|
79
|
+
*/
|
|
80
|
+
type TranslationKeys<Translations extends TranslationFile<any, ParsedFormatFnByKey>> = Translations extends unknown ? keyof Awaited<ReturnType<Translations['getMessages']>> : never;
|
|
81
|
+
interface LanguageTarget {
|
|
82
|
+
name: LanguageName;
|
|
83
|
+
extends?: LanguageName;
|
|
84
|
+
}
|
|
85
|
+
interface MessageGenerator {
|
|
86
|
+
transformElement?: (element: string) => string;
|
|
87
|
+
transformMessage?: (message: string) => string;
|
|
88
|
+
}
|
|
89
|
+
interface GeneratedLanguageTarget {
|
|
90
|
+
name: LanguageName;
|
|
91
|
+
extends?: LanguageName;
|
|
92
|
+
generator: MessageGenerator;
|
|
93
|
+
}
|
|
94
|
+
interface UserConfig {
|
|
95
|
+
/**
|
|
96
|
+
* The root directory to compile and validate translations
|
|
97
|
+
*/
|
|
98
|
+
projectRoot?: string;
|
|
99
|
+
/**
|
|
100
|
+
* The language used in translations.json
|
|
101
|
+
*/
|
|
102
|
+
devLanguage: LanguageName;
|
|
103
|
+
/**
|
|
104
|
+
* An array of languages to build for
|
|
105
|
+
*/
|
|
106
|
+
languages: LanguageTarget[];
|
|
107
|
+
/**
|
|
108
|
+
* An array of languages to generate from existing translations
|
|
109
|
+
*/
|
|
110
|
+
generatedLanguages?: GeneratedLanguageTarget[];
|
|
111
|
+
/**
|
|
112
|
+
* A custom suffix to name vocab translation directories
|
|
113
|
+
*/
|
|
114
|
+
translationsDirectorySuffix?: string;
|
|
115
|
+
/**
|
|
116
|
+
* An array of glob paths to ignore from compilation and validation
|
|
117
|
+
*/
|
|
118
|
+
ignore?: string[];
|
|
119
|
+
}
|
|
120
|
+
type Tags = string[];
|
|
121
|
+
interface TranslationFileMetadata {
|
|
122
|
+
tags?: Tags;
|
|
123
|
+
}
|
|
124
|
+
interface TranslationData {
|
|
125
|
+
message: TranslationMessage;
|
|
126
|
+
description?: string;
|
|
127
|
+
tags?: Tags;
|
|
128
|
+
globalKey?: string;
|
|
129
|
+
}
|
|
130
|
+
type TranslationsByKey<Key extends TranslationKey = string> = Record<Key, TranslationData>;
|
|
131
|
+
type TranslationFileContents = TranslationsByKey & {
|
|
132
|
+
_meta?: TranslationFileMetadata;
|
|
133
|
+
};
|
|
134
|
+
type TranslationMessagesByKey<Key extends TranslationKey = string> = Record<Key, TranslationMessage>;
|
|
135
|
+
type TranslationsByLanguage<Key extends TranslationKey = string> = Record<LanguageName, TranslationsByKey<Key>>;
|
|
136
|
+
type LoadedTranslation<Key extends TranslationKey = string> = {
|
|
137
|
+
namespace: string;
|
|
138
|
+
keys: Key[];
|
|
139
|
+
filePath: string;
|
|
140
|
+
relativePath: string;
|
|
141
|
+
languages: TranslationsByLanguage<Key>;
|
|
142
|
+
metadata: TranslationFileMetadata;
|
|
143
|
+
};
|
|
144
|
+
//#endregion
|
|
145
|
+
export { TranslationsByLanguage as C, TranslationsByKey as S, TranslationKeys as _, LoadedTranslation as a, TranslationModule as b, ParsedFormatFnByKey as c, Tags as d, TranslationData as f, TranslationKey as g, TranslationFileMetadata as h, LanguageTarget as i, ParsedICUMessages as l, TranslationFileContents as m, GeneratedLanguageTarget as n, MessageGenerator as o, TranslationFile as p, LanguageName as r, ParsedFormatFn as s, FormatXMLElementFn as t, StringWithSuggestions as u, TranslationMessage as v, UserConfig as w, TranslationModuleByLanguage as x, TranslationMessagesByKey as y };
|
|
146
|
+
//# sourceMappingURL=types-C00NNtxU.d.cts.map
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { FormatXMLElementFn } from "intl-messageformat";
|
|
2
|
+
|
|
3
|
+
//#region src/types.d.ts
|
|
4
|
+
type LanguageName = string;
|
|
5
|
+
type TranslationKey = string;
|
|
6
|
+
type TranslationMessage = string;
|
|
7
|
+
type ParsedFormatFn = (parts: any) => any;
|
|
8
|
+
type ParsedFormatFnByKey = Record<string, ParsedFormatFn>;
|
|
9
|
+
/**
|
|
10
|
+
* Equivalent to the `string` type, but tricks TypeScript into prodiving
|
|
11
|
+
* suggestions for string literals passed into the `Suggestions` generic parameter
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* type AnyAnimal = StringWithSuggestions<"cat" | "dog">;
|
|
15
|
+
* // Suggests cat and dog, but accepts any string
|
|
16
|
+
* const animal: AnyAnimal = "";
|
|
17
|
+
*/
|
|
18
|
+
type StringWithSuggestions<Suggestions extends string> = Suggestions | Omit<string, Suggestions>;
|
|
19
|
+
/**
|
|
20
|
+
* ParsedICUMessage A strictly typed formatter from intl-messageformat
|
|
21
|
+
*/
|
|
22
|
+
interface ParsedICUMessage<FormatFn extends ParsedFormatFn> {
|
|
23
|
+
format: FormatFn;
|
|
24
|
+
}
|
|
25
|
+
type ParsedICUMessages<FormatFnByKey extends ParsedFormatFnByKey> = { [key in keyof FormatFnByKey]: ParsedICUMessage<FormatFnByKey[key]> };
|
|
26
|
+
/**
|
|
27
|
+
* TranslationModule is a wrapper around a potentially asynchronously loaded set of ParsedICUMessages
|
|
28
|
+
*/
|
|
29
|
+
type TranslationModule<FormatFnByKey extends ParsedFormatFnByKey> = {
|
|
30
|
+
getValue: (locale: string) => ParsedICUMessages<FormatFnByKey> | undefined;
|
|
31
|
+
load: () => Promise<void>;
|
|
32
|
+
};
|
|
33
|
+
type TranslationModuleByLanguage<Language extends LanguageName, FormatFnByKey extends ParsedFormatFnByKey> = Record<Language, TranslationModule<FormatFnByKey>>;
|
|
34
|
+
/**
|
|
35
|
+
* TranslationFile contains a record of TranslationModules per language, exposing a set of methods to load and return the module by language
|
|
36
|
+
*/
|
|
37
|
+
type TranslationFile<Language extends LanguageName, FormatFnByKey extends ParsedFormatFnByKey> = {
|
|
38
|
+
/**
|
|
39
|
+
* Retrieve messages. If not loaded, will attempt to load messages and resolve once complete.
|
|
40
|
+
*/
|
|
41
|
+
getMessages: (language: Language, locale?: string) => Promise<ParsedICUMessages<FormatFnByKey>>;
|
|
42
|
+
/**
|
|
43
|
+
* Retrieve already loaded messages. Will return null if no messages have been loaded.
|
|
44
|
+
*/
|
|
45
|
+
getLoadedMessages: (language: Language, locale?: string) => ParsedICUMessages<FormatFnByKey> | null;
|
|
46
|
+
/**
|
|
47
|
+
* Load messages for the given language. Resolving once complete.
|
|
48
|
+
*/
|
|
49
|
+
load: (language: Language) => Promise<void>;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* A utility type to get the union of all translation keys from a translation file
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* // translations.json
|
|
56
|
+
* {
|
|
57
|
+
* "Hello": {
|
|
58
|
+
* "message": "Hello",
|
|
59
|
+
* },
|
|
60
|
+
* "Goodbye": {
|
|
61
|
+
* "message": "Goodbye",
|
|
62
|
+
* },
|
|
63
|
+
* }
|
|
64
|
+
*
|
|
65
|
+
* // myFile.ts
|
|
66
|
+
* import { TranslationKeys } from '@vocab/core';
|
|
67
|
+
* import translations from './.vocab';
|
|
68
|
+
*
|
|
69
|
+
* // 'Hello' | 'Goodbye'
|
|
70
|
+
* type TheTranslationKeys = TranslationKeys<typeof translations>;
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* import { TranslationKeys } from '@vocab/core';
|
|
74
|
+
* import fooTranslations from './foo.vocab';
|
|
75
|
+
* import barTranslations from './bar.vocab';
|
|
76
|
+
*
|
|
77
|
+
* // It even works with multiple translation files
|
|
78
|
+
* type FooBarTranslationKeys = TranslationKeys<typeof fooTranslations | typeof barTranslations>;
|
|
79
|
+
*/
|
|
80
|
+
type TranslationKeys<Translations extends TranslationFile<any, ParsedFormatFnByKey>> = Translations extends unknown ? keyof Awaited<ReturnType<Translations['getMessages']>> : never;
|
|
81
|
+
interface LanguageTarget {
|
|
82
|
+
name: LanguageName;
|
|
83
|
+
extends?: LanguageName;
|
|
84
|
+
}
|
|
85
|
+
interface MessageGenerator {
|
|
86
|
+
transformElement?: (element: string) => string;
|
|
87
|
+
transformMessage?: (message: string) => string;
|
|
88
|
+
}
|
|
89
|
+
interface GeneratedLanguageTarget {
|
|
90
|
+
name: LanguageName;
|
|
91
|
+
extends?: LanguageName;
|
|
92
|
+
generator: MessageGenerator;
|
|
93
|
+
}
|
|
94
|
+
interface UserConfig {
|
|
95
|
+
/**
|
|
96
|
+
* The root directory to compile and validate translations
|
|
97
|
+
*/
|
|
98
|
+
projectRoot?: string;
|
|
99
|
+
/**
|
|
100
|
+
* The language used in translations.json
|
|
101
|
+
*/
|
|
102
|
+
devLanguage: LanguageName;
|
|
103
|
+
/**
|
|
104
|
+
* An array of languages to build for
|
|
105
|
+
*/
|
|
106
|
+
languages: LanguageTarget[];
|
|
107
|
+
/**
|
|
108
|
+
* An array of languages to generate from existing translations
|
|
109
|
+
*/
|
|
110
|
+
generatedLanguages?: GeneratedLanguageTarget[];
|
|
111
|
+
/**
|
|
112
|
+
* A custom suffix to name vocab translation directories
|
|
113
|
+
*/
|
|
114
|
+
translationsDirectorySuffix?: string;
|
|
115
|
+
/**
|
|
116
|
+
* An array of glob paths to ignore from compilation and validation
|
|
117
|
+
*/
|
|
118
|
+
ignore?: string[];
|
|
119
|
+
}
|
|
120
|
+
type Tags = string[];
|
|
121
|
+
interface TranslationFileMetadata {
|
|
122
|
+
tags?: Tags;
|
|
123
|
+
}
|
|
124
|
+
interface TranslationData {
|
|
125
|
+
message: TranslationMessage;
|
|
126
|
+
description?: string;
|
|
127
|
+
tags?: Tags;
|
|
128
|
+
globalKey?: string;
|
|
129
|
+
}
|
|
130
|
+
type TranslationsByKey<Key extends TranslationKey = string> = Record<Key, TranslationData>;
|
|
131
|
+
type TranslationFileContents = TranslationsByKey & {
|
|
132
|
+
_meta?: TranslationFileMetadata;
|
|
133
|
+
};
|
|
134
|
+
type TranslationMessagesByKey<Key extends TranslationKey = string> = Record<Key, TranslationMessage>;
|
|
135
|
+
type TranslationsByLanguage<Key extends TranslationKey = string> = Record<LanguageName, TranslationsByKey<Key>>;
|
|
136
|
+
type LoadedTranslation<Key extends TranslationKey = string> = {
|
|
137
|
+
namespace: string;
|
|
138
|
+
keys: Key[];
|
|
139
|
+
filePath: string;
|
|
140
|
+
relativePath: string;
|
|
141
|
+
languages: TranslationsByLanguage<Key>;
|
|
142
|
+
metadata: TranslationFileMetadata;
|
|
143
|
+
};
|
|
144
|
+
//#endregion
|
|
145
|
+
export { TranslationsByLanguage as C, TranslationsByKey as S, TranslationKeys as _, LoadedTranslation as a, TranslationModule as b, ParsedFormatFnByKey as c, Tags as d, TranslationData as f, TranslationKey as g, TranslationFileMetadata as h, LanguageTarget as i, ParsedICUMessages as l, TranslationFileContents as m, GeneratedLanguageTarget as n, MessageGenerator as o, TranslationFile as p, LanguageName as r, ParsedFormatFn as s, FormatXMLElementFn as t, StringWithSuggestions as u, TranslationMessage as v, UserConfig as w, TranslationModuleByLanguage as x, TranslationMessagesByKey as y };
|
|
146
|
+
//# sourceMappingURL=types-DpryIirw.d.mts.map
|
package/package.json
CHANGED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
const require_chunk = require('./chunk-BuD6V4w7.cjs');
|
|
2
|
-
let intl_messageformat = require("intl-messageformat");
|
|
3
|
-
|
|
4
|
-
//#region src/icu-handler.ts
|
|
5
|
-
var moduleCache, getParsedICUMessages;
|
|
6
|
-
var init_icu_handler = require_chunk.__esmMin((() => {
|
|
7
|
-
moduleCache = /* @__PURE__ */ new WeakMap();
|
|
8
|
-
getParsedICUMessages = (m, locale) => {
|
|
9
|
-
const moduleCachedResult = moduleCache.get(m);
|
|
10
|
-
if (moduleCachedResult && moduleCachedResult[locale]) return moduleCachedResult[locale];
|
|
11
|
-
const parsedICUMessages = {};
|
|
12
|
-
for (const translation of Object.keys(m)) {
|
|
13
|
-
const intlMessageFormat = new intl_messageformat.IntlMessageFormat(m[translation], locale);
|
|
14
|
-
parsedICUMessages[translation] = { format: (params) => intlMessageFormat.format(params) };
|
|
15
|
-
}
|
|
16
|
-
moduleCache.set(m, {
|
|
17
|
-
...moduleCachedResult,
|
|
18
|
-
[locale]: parsedICUMessages
|
|
19
|
-
});
|
|
20
|
-
return parsedICUMessages;
|
|
21
|
-
};
|
|
22
|
-
}));
|
|
23
|
-
|
|
24
|
-
//#endregion
|
|
25
|
-
Object.defineProperty(exports, 'getParsedICUMessages', {
|
|
26
|
-
enumerable: true,
|
|
27
|
-
get: function () {
|
|
28
|
-
return getParsedICUMessages;
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
Object.defineProperty(exports, 'init_icu_handler', {
|
|
32
|
-
enumerable: true,
|
|
33
|
-
get: function () {
|
|
34
|
-
return init_icu_handler;
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
//# sourceMappingURL=icu-handler-BALMAIaM.cjs.map
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { t as __esmMin } from "./chunk-YUyckAMm.mjs";
|
|
2
|
-
import { IntlMessageFormat } from "intl-messageformat";
|
|
3
|
-
|
|
4
|
-
//#region src/icu-handler.ts
|
|
5
|
-
var moduleCache, getParsedICUMessages;
|
|
6
|
-
var init_icu_handler = __esmMin((() => {
|
|
7
|
-
moduleCache = /* @__PURE__ */ new WeakMap();
|
|
8
|
-
getParsedICUMessages = (m, locale) => {
|
|
9
|
-
const moduleCachedResult = moduleCache.get(m);
|
|
10
|
-
if (moduleCachedResult && moduleCachedResult[locale]) return moduleCachedResult[locale];
|
|
11
|
-
const parsedICUMessages = {};
|
|
12
|
-
for (const translation of Object.keys(m)) {
|
|
13
|
-
const intlMessageFormat = new IntlMessageFormat(m[translation], locale);
|
|
14
|
-
parsedICUMessages[translation] = { format: (params) => intlMessageFormat.format(params) };
|
|
15
|
-
}
|
|
16
|
-
moduleCache.set(m, {
|
|
17
|
-
...moduleCachedResult,
|
|
18
|
-
[locale]: parsedICUMessages
|
|
19
|
-
});
|
|
20
|
-
return parsedICUMessages;
|
|
21
|
-
};
|
|
22
|
-
}));
|
|
23
|
-
|
|
24
|
-
//#endregion
|
|
25
|
-
export { init_icu_handler as n, getParsedICUMessages as t };
|
|
26
|
-
//# sourceMappingURL=icu-handler-CuYAM62Z.mjs.map
|
package/dist/icu-handler.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"icu-handler.cjs","names":[],"sources":["../src/icu-handler.ts"],"sourcesContent":["import type { ParsedICUMessages, TranslationMessagesByKey } from './types';\nimport { IntlMessageFormat } from 'intl-messageformat';\n\ntype ICUMessagesByLocale = Record<string, ParsedICUMessages<any>>;\n\nconst moduleCache = new WeakMap<\n TranslationMessagesByKey,\n ICUMessagesByLocale\n>();\n\nexport const getParsedICUMessages = (\n m: TranslationMessagesByKey,\n locale: string,\n): ParsedICUMessages<any> => {\n const moduleCachedResult = moduleCache.get(m);\n\n if (moduleCachedResult && moduleCachedResult[locale]) {\n return moduleCachedResult[locale];\n }\n\n const parsedICUMessages: ParsedICUMessages<any> = {};\n\n for (const translation of Object.keys(m)) {\n const intlMessageFormat = new IntlMessageFormat(m[translation], locale);\n parsedICUMessages[translation] = {\n format: (params: any) => intlMessageFormat.format(params),\n };\n }\n\n moduleCache.set(m, { ...moduleCachedResult, [locale]: parsedICUMessages });\n\n return parsedICUMessages;\n};\n"],"mappings":""}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { t as __esmMin } from "./chunk-Bdo2O6aD.cjs";
|
|
2
|
-
import { T as init_types_d, c as ParsedFormatFnByKey, p as TranslationFile, r as LanguageName, x as TranslationModuleByLanguage } from "./types-Dhy3ksw5.cjs";
|
|
3
|
-
|
|
4
|
-
//#region src/translation-file.d.ts
|
|
5
|
-
|
|
6
|
-
//#endregion
|
|
7
|
-
export { init_translation_file_d as n, createTranslationFile as t };
|
|
8
|
-
//# sourceMappingURL=translation-file-DGrsUC73.d.cts.map
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { t as __esmMin } from "./chunk-YUyckAMm.mjs";
|
|
2
|
-
import { T as init_types_d, c as ParsedFormatFnByKey, p as TranslationFile, r as LanguageName, x as TranslationModuleByLanguage } from "./types-tajuHnML.mjs";
|
|
3
|
-
|
|
4
|
-
//#region src/translation-file.d.ts
|
|
5
|
-
|
|
6
|
-
//#endregion
|
|
7
|
-
export { init_translation_file_d as n, createTranslationFile as t };
|
|
8
|
-
//# sourceMappingURL=translation-file-TvWb96IF.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"translation-file.cjs","names":[],"sources":["../src/translation-file.ts"],"sourcesContent":["import type {\n TranslationModule,\n TranslationModuleByLanguage,\n ParsedICUMessages,\n LanguageName,\n ParsedFormatFnByKey,\n TranslationFile,\n} from './types';\n\nexport function createTranslationFile<\n Language extends LanguageName,\n FormatFnByKey extends ParsedFormatFnByKey,\n>(\n translationsByLanguage: TranslationModuleByLanguage<Language, FormatFnByKey>,\n): TranslationFile<Language, FormatFnByKey> {\n function getByLanguage(language: Language): TranslationModule<FormatFnByKey> {\n const translationModule = translationsByLanguage[language];\n if (!translationModule) {\n throw new Error(\n `Attempted to retrieve translations for unknown language \"${language}\"`,\n );\n }\n return translationModule;\n }\n\n return {\n getLoadedMessages(\n language: Language,\n locale?: string,\n ): ParsedICUMessages<FormatFnByKey> | null {\n const translationModule = getByLanguage(language);\n return translationModule.getValue(locale || language) || null;\n },\n getMessages(\n language: Language,\n locale?: string,\n ): Promise<ParsedICUMessages<FormatFnByKey>> {\n const translationModule = getByLanguage(language);\n return translationModule.load().then(() => {\n const result = translationModule.getValue(locale || language);\n if (!result) {\n throw new Error(\n `Unable to find translations for ${language} after attempting to load. Module may have failed to load or an internal error may have occurred.`,\n );\n }\n return result;\n });\n },\n load(language: Language): Promise<void> {\n const translationModule = getByLanguage(language);\n return translationModule.load();\n },\n };\n}\n"],"mappings":""}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { t as __esmMin } from "./chunk-Bdo2O6aD.cjs";
|
|
2
|
-
import { FormatXMLElementFn } from "intl-messageformat";
|
|
3
|
-
|
|
4
|
-
//#region src/types.d.ts
|
|
5
|
-
|
|
6
|
-
//#endregion
|
|
7
|
-
export { TranslationsByLanguage as C, TranslationsByKey as S, init_types_d as T, TranslationKeys as _, LoadedTranslation as a, TranslationModule as b, ParsedFormatFnByKey as c, Tags as d, TranslationData as f, TranslationKey as g, TranslationFileMetadata as h, LanguageTarget as i, ParsedICUMessages as l, TranslationFileContents as m, GeneratedLanguageTarget as n, MessageGenerator as o, TranslationFile as p, LanguageName as r, ParsedFormatFn as s, FormatXMLElementFn as t, StringWithSuggestions as u, TranslationMessage as v, UserConfig as w, TranslationModuleByLanguage as x, TranslationMessagesByKey as y };
|
|
8
|
-
//# sourceMappingURL=types-Dhy3ksw5.d.cts.map
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { t as __esmMin } from "./chunk-YUyckAMm.mjs";
|
|
2
|
-
import { FormatXMLElementFn } from "intl-messageformat";
|
|
3
|
-
|
|
4
|
-
//#region src/types.d.ts
|
|
5
|
-
|
|
6
|
-
//#endregion
|
|
7
|
-
export { TranslationsByLanguage as C, TranslationsByKey as S, init_types_d as T, TranslationKeys as _, LoadedTranslation as a, TranslationModule as b, ParsedFormatFnByKey as c, Tags as d, TranslationData as f, TranslationKey as g, TranslationFileMetadata as h, LanguageTarget as i, ParsedICUMessages as l, TranslationFileContents as m, GeneratedLanguageTarget as n, MessageGenerator as o, TranslationFile as p, LanguageName as r, ParsedFormatFn as s, FormatXMLElementFn as t, StringWithSuggestions as u, TranslationMessage as v, UserConfig as w, TranslationModuleByLanguage as x, TranslationMessagesByKey as y };
|
|
8
|
-
//# sourceMappingURL=types-tajuHnML.d.mts.map
|