@vocab/core 0.0.0-add-support-for-vocab-cjs-20231109235141
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/LICENSE +21 -0
- package/dist/declarations/src/compile.d.ts +6 -0
- package/dist/declarations/src/config.d.ts +4 -0
- package/dist/declarations/src/icu-handler.d.ts +2 -0
- package/dist/declarations/src/index.d.ts +6 -0
- package/dist/declarations/src/load-translations.d.ts +32 -0
- package/dist/declarations/src/runtime.d.ts +3 -0
- package/dist/declarations/src/translation-file.d.ts +2 -0
- package/dist/declarations/src/types.d.ts +117 -0
- package/dist/declarations/src/utils.d.ts +26 -0
- package/dist/declarations/src/validate/index.d.ts +3 -0
- package/dist/vocab-core.cjs.d.ts +2 -0
- package/dist/vocab-core.cjs.d.ts.map +1 -0
- package/dist/vocab-core.cjs.dev.js +887 -0
- package/dist/vocab-core.cjs.js +7 -0
- package/dist/vocab-core.cjs.prod.js +887 -0
- package/dist/vocab-core.esm.js +860 -0
- package/icu-handler/dist/vocab-core-icu-handler.cjs.d.ts +2 -0
- package/icu-handler/dist/vocab-core-icu-handler.cjs.d.ts.map +1 -0
- package/icu-handler/dist/vocab-core-icu-handler.cjs.dev.js +31 -0
- package/icu-handler/dist/vocab-core-icu-handler.cjs.js +7 -0
- package/icu-handler/dist/vocab-core-icu-handler.cjs.prod.js +31 -0
- package/icu-handler/dist/vocab-core-icu-handler.esm.js +23 -0
- package/icu-handler/package.json +4 -0
- package/package.json +56 -0
- package/runtime/dist/vocab-core-runtime.cjs.d.ts +2 -0
- package/runtime/dist/vocab-core-runtime.cjs.d.ts.map +1 -0
- package/runtime/dist/vocab-core-runtime.cjs.dev.js +15 -0
- package/runtime/dist/vocab-core-runtime.cjs.js +7 -0
- package/runtime/dist/vocab-core-runtime.cjs.prod.js +15 -0
- package/runtime/dist/vocab-core-runtime.esm.js +10 -0
- package/runtime/package.json +4 -0
- package/translation-file/dist/vocab-core-translation-file.cjs.d.ts +2 -0
- package/translation-file/dist/vocab-core-translation-file.cjs.d.ts.map +1 -0
- package/translation-file/dist/vocab-core-translation-file.cjs.dev.js +35 -0
- package/translation-file/dist/vocab-core-translation-file.cjs.js +7 -0
- package/translation-file/dist/vocab-core-translation-file.cjs.prod.js +35 -0
- package/translation-file/dist/vocab-core-translation-file.esm.js +31 -0
- package/translation-file/package.json +4 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
### MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 SEEK
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { LoadedTranslation, UserConfig } from "./types.js";
|
|
2
|
+
export declare function generateRuntime(loadedTranslation: LoadedTranslation): Promise<void>;
|
|
3
|
+
export declare function watch(config: UserConfig): () => Promise<void>;
|
|
4
|
+
export declare function compile({ watch: shouldWatch }: {
|
|
5
|
+
watch?: boolean | undefined;
|
|
6
|
+
} | undefined, config: UserConfig): Promise<(() => Promise<void>) | undefined>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { UserConfig } from "./types.js";
|
|
2
|
+
export declare function validateConfig(c: UserConfig): boolean;
|
|
3
|
+
export declare function resolveConfig(customConfigFilePath?: string): Promise<UserConfig | null>;
|
|
4
|
+
export declare function resolveConfigSync(customConfigFilePath?: string): UserConfig | null;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { compile, watch } from "./compile.js";
|
|
2
|
+
export { validate } from "./validate/index.js";
|
|
3
|
+
export { resolveConfig, resolveConfigSync, validateConfig } from "./config.js";
|
|
4
|
+
export { getAltLanguages, getAltLanguageFilePath, getDevLanguageFileFromTsFile, } from "./utils.js";
|
|
5
|
+
export { getUniqueKey, loadAllTranslations, loadTranslation, } from "./load-translations.js";
|
|
6
|
+
export * from "./types.js";
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { TranslationsByKey, UserConfig, LoadedTranslation, LanguageTarget } from "./types.js";
|
|
2
|
+
import { type Fallback } from "./utils.js";
|
|
3
|
+
export declare function getUniqueKey(key: string, namespace: string): string;
|
|
4
|
+
export declare function mergeWithDevLanguageTranslation({ translation, devTranslation, }: {
|
|
5
|
+
translation: TranslationsByKey;
|
|
6
|
+
devTranslation: TranslationsByKey;
|
|
7
|
+
}): TranslationsByKey<string>;
|
|
8
|
+
export declare function getLanguageHierarchy({ languages, }: {
|
|
9
|
+
languages: Array<LanguageTarget>;
|
|
10
|
+
}): Map<string, string[]>;
|
|
11
|
+
export declare function getFallbackLanguageOrder({ languages, languageName, devLanguage, fallbacks, }: {
|
|
12
|
+
languages: LanguageTarget[];
|
|
13
|
+
languageName: string;
|
|
14
|
+
devLanguage: string;
|
|
15
|
+
fallbacks: Fallback;
|
|
16
|
+
}): string[];
|
|
17
|
+
export declare function loadAltLanguageFile({ filePath, languageName, devTranslation, fallbacks, }: {
|
|
18
|
+
filePath: string;
|
|
19
|
+
languageName: string;
|
|
20
|
+
devTranslation: TranslationsByKey;
|
|
21
|
+
fallbacks: Fallback;
|
|
22
|
+
}, { devLanguage, languages }: UserConfig): TranslationsByKey;
|
|
23
|
+
export declare function loadTranslation({ filePath, fallbacks, withTags, }: {
|
|
24
|
+
filePath: string;
|
|
25
|
+
fallbacks: Fallback;
|
|
26
|
+
withTags?: boolean;
|
|
27
|
+
}, userConfig: UserConfig): LoadedTranslation;
|
|
28
|
+
export declare function loadAllTranslations({ fallbacks, includeNodeModules, withTags, }: {
|
|
29
|
+
fallbacks: Fallback;
|
|
30
|
+
includeNodeModules: boolean;
|
|
31
|
+
withTags?: boolean;
|
|
32
|
+
}, config: UserConfig): Promise<Array<LoadedTranslation>>;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import type { TranslationModuleByLanguage, LanguageName, ParsedFormatFnByKey, TranslationFile } from "./types.js";
|
|
2
|
+
export declare function createTranslationFile<Language extends LanguageName, FormatFnByKey extends ParsedFormatFnByKey>(translationsByLanguage: TranslationModuleByLanguage<Language, FormatFnByKey>): TranslationFile<Language, FormatFnByKey>;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
export type { FormatXMLElementFn } from 'intl-messageformat';
|
|
2
|
+
export type LanguageName = string;
|
|
3
|
+
export type TranslationKey = string;
|
|
4
|
+
export type TranslationMessage = string;
|
|
5
|
+
export type ParsedFormatFn = (parts: any) => any;
|
|
6
|
+
export type ParsedFormatFnByKey = Record<string, ParsedFormatFn>;
|
|
7
|
+
/**
|
|
8
|
+
* Equivalent to the `string` type, but tricks the language server into prodiving
|
|
9
|
+
* suggestions for string literals passed into the `Suggestions` generic parameter
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* Accept any string, but suggest specific animals
|
|
13
|
+
* ```
|
|
14
|
+
* type AnyAnimal = StringWithSuggestions<"cat" | "dog">;
|
|
15
|
+
* // Suggests cat and dog, but accepts any string
|
|
16
|
+
* const animal: AnyAnimal = "";
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export type StringWithSuggestions<Suggestions extends string> = Suggestions | Omit<string, Suggestions>;
|
|
20
|
+
/**
|
|
21
|
+
* ParsedICUMessage A strictly typed formatter from intl-messageformat
|
|
22
|
+
*/
|
|
23
|
+
interface ParsedICUMessage<FormatFn extends ParsedFormatFn> {
|
|
24
|
+
format: FormatFn;
|
|
25
|
+
}
|
|
26
|
+
export type ParsedICUMessages<FormatFnByKey extends ParsedFormatFnByKey> = {
|
|
27
|
+
[key in keyof FormatFnByKey]: ParsedICUMessage<FormatFnByKey[key]>;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* TranslationModule is a wrapper around a potentially asynchronously loaded set of ParsedICUMessages
|
|
31
|
+
*/
|
|
32
|
+
export type TranslationModule<FormatFnByKey extends ParsedFormatFnByKey> = {
|
|
33
|
+
getValue: (locale: string) => ParsedICUMessages<FormatFnByKey> | undefined;
|
|
34
|
+
load: () => Promise<void>;
|
|
35
|
+
};
|
|
36
|
+
export type TranslationModuleByLanguage<Language extends LanguageName, FormatFnByKey extends ParsedFormatFnByKey> = Record<Language, TranslationModule<FormatFnByKey>>;
|
|
37
|
+
/**
|
|
38
|
+
* TranslationFile contains a record of TranslationModules per language, exposing a set of methods to load and return the module by language
|
|
39
|
+
*/
|
|
40
|
+
export type TranslationFile<Language extends LanguageName, FormatFnByKey extends ParsedFormatFnByKey> = {
|
|
41
|
+
/**
|
|
42
|
+
* Retrieve messages. If not loaded, will attempt to load messages and resolve once complete.
|
|
43
|
+
*/
|
|
44
|
+
getMessages: (language: Language, locale?: string) => Promise<ParsedICUMessages<FormatFnByKey>>;
|
|
45
|
+
/**
|
|
46
|
+
* Retrieve already loaded messages. Will return null if no messages have been loaded.
|
|
47
|
+
*/
|
|
48
|
+
getLoadedMessages: (language: Language, locale?: string) => ParsedICUMessages<FormatFnByKey> | null;
|
|
49
|
+
/**
|
|
50
|
+
* Load messages for the given language. Resolving once complete.
|
|
51
|
+
*/
|
|
52
|
+
load: (language: Language) => Promise<void>;
|
|
53
|
+
};
|
|
54
|
+
export type TranslationKeys<Translations extends TranslationFile<any, ParsedFormatFnByKey>> = keyof Awaited<ReturnType<Translations['getMessages']>>;
|
|
55
|
+
export interface LanguageTarget {
|
|
56
|
+
name: LanguageName;
|
|
57
|
+
extends?: LanguageName;
|
|
58
|
+
}
|
|
59
|
+
export interface MessageGenerator {
|
|
60
|
+
transformElement?: (element: string) => string;
|
|
61
|
+
transformMessage?: (message: string) => string;
|
|
62
|
+
}
|
|
63
|
+
export interface GeneratedLanguageTarget {
|
|
64
|
+
name: LanguageName;
|
|
65
|
+
extends?: LanguageName;
|
|
66
|
+
generator: MessageGenerator;
|
|
67
|
+
}
|
|
68
|
+
export interface UserConfig {
|
|
69
|
+
/**
|
|
70
|
+
* The root directory to compile and validate translations
|
|
71
|
+
*/
|
|
72
|
+
projectRoot?: string;
|
|
73
|
+
/**
|
|
74
|
+
* The language used in translations.json
|
|
75
|
+
*/
|
|
76
|
+
devLanguage: LanguageName;
|
|
77
|
+
/**
|
|
78
|
+
* An array of languages to build for
|
|
79
|
+
*/
|
|
80
|
+
languages: Array<LanguageTarget>;
|
|
81
|
+
/**
|
|
82
|
+
* An array of languages to generate from existing translations
|
|
83
|
+
*/
|
|
84
|
+
generatedLanguages?: Array<GeneratedLanguageTarget>;
|
|
85
|
+
/**
|
|
86
|
+
* A custom suffix to name vocab translation directories
|
|
87
|
+
*/
|
|
88
|
+
translationsDirectorySuffix?: string;
|
|
89
|
+
/**
|
|
90
|
+
* An array of glob paths to ignore from compilation and validation
|
|
91
|
+
*/
|
|
92
|
+
ignore?: Array<string>;
|
|
93
|
+
}
|
|
94
|
+
export type Tags = Array<string>;
|
|
95
|
+
export interface TranslationFileMetadata {
|
|
96
|
+
tags?: Tags;
|
|
97
|
+
}
|
|
98
|
+
export interface TranslationData {
|
|
99
|
+
message: TranslationMessage;
|
|
100
|
+
description?: string;
|
|
101
|
+
tags?: Tags;
|
|
102
|
+
globalKey?: string;
|
|
103
|
+
}
|
|
104
|
+
export type TranslationsByKey<Key extends TranslationKey = string> = Record<Key, TranslationData>;
|
|
105
|
+
export type TranslationFileContents = TranslationsByKey & {
|
|
106
|
+
_meta?: TranslationFileMetadata;
|
|
107
|
+
};
|
|
108
|
+
export type TranslationMessagesByKey<Key extends TranslationKey = string> = Record<Key, TranslationMessage>;
|
|
109
|
+
export type TranslationsByLanguage<Key extends TranslationKey = string> = Record<LanguageName, TranslationsByKey<Key>>;
|
|
110
|
+
export type LoadedTranslation<Key extends TranslationKey = string> = {
|
|
111
|
+
namespace: string;
|
|
112
|
+
keys: Array<Key>;
|
|
113
|
+
filePath: string;
|
|
114
|
+
relativePath: string;
|
|
115
|
+
languages: TranslationsByLanguage<Key>;
|
|
116
|
+
metadata: TranslationFileMetadata;
|
|
117
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { LanguageName, LanguageTarget, TranslationsByKey, TranslationMessagesByKey, UserConfig } from "./types.js";
|
|
2
|
+
export declare const defaultTranslationDirSuffix = ".vocab";
|
|
3
|
+
export declare const devTranslationFileName = "translations.json";
|
|
4
|
+
export type Fallback = 'none' | 'valid' | 'all';
|
|
5
|
+
export declare function isDevLanguageFile(filePath: string): boolean;
|
|
6
|
+
export declare function isAltLanguageFile(filePath: string): boolean;
|
|
7
|
+
export declare function isTranslationDirectory(filePath: string, { translationsDirectorySuffix, }: {
|
|
8
|
+
translationsDirectorySuffix?: string;
|
|
9
|
+
}): boolean;
|
|
10
|
+
export declare function getTranslationFolderGlob({ translationsDirectorySuffix, }: {
|
|
11
|
+
translationsDirectorySuffix?: string;
|
|
12
|
+
}): string;
|
|
13
|
+
export declare function getDevTranslationFileGlob({ translationsDirectorySuffix, }: {
|
|
14
|
+
translationsDirectorySuffix?: string;
|
|
15
|
+
}): string;
|
|
16
|
+
export declare function getAltTranslationFileGlob(config: UserConfig): string;
|
|
17
|
+
export declare function getAltLanguages({ devLanguage, languages, }: {
|
|
18
|
+
devLanguage: LanguageName;
|
|
19
|
+
languages: Array<LanguageTarget>;
|
|
20
|
+
}): string[];
|
|
21
|
+
export declare function getDevLanguageFileFromTsFile(tsFilePath: string): string;
|
|
22
|
+
export declare function getDevLanguageFileFromAltLanguageFile(altLanguageFilePath: string): string;
|
|
23
|
+
export declare function getTSFileFromDevLanguageFile(devLanguageFilePath: string): string;
|
|
24
|
+
export declare function getAltLanguageFilePath(devLanguageFilePath: string, language: string): string;
|
|
25
|
+
export declare function mapValues<Key extends string, OriginalValue, ReturnValue>(obj: Record<Key, OriginalValue>, func: (val: OriginalValue) => ReturnValue): TranslationMessagesByKey<Key>;
|
|
26
|
+
export declare function getTranslationMessages<Key extends string>(translations: TranslationsByKey<Key>): TranslationMessagesByKey<Key>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { UserConfig, LoadedTranslation, LanguageName } from "../types.js";
|
|
2
|
+
export declare function findMissingKeys(loadedTranslation: LoadedTranslation, devLanguageName: LanguageName, altLanguages: Array<LanguageName>): readonly [boolean, Record<string, string[]>];
|
|
3
|
+
export declare function validate(config: UserConfig): Promise<boolean>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vocab-core.cjs.d.ts","sourceRoot":"","sources":["./declarations/src/index.d.ts"],"names":[],"mappings":"AAAA"}
|