@lang-tag/cli 0.9.4 → 0.10.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/{cli/config.d.ts → config.d.ts} +1 -1
- package/index.cjs +1470 -74
- package/index.js +1452 -74
- package/package.json +6 -3
- package/cli/index.cjs +0 -1492
- package/cli/index.js +0 -1474
- package/index.d.ts +0 -169
- /package/{cli/logger.d.ts → logger.d.ts} +0 -0
- /package/{cli/template → template}/base-app.mustache +0 -0
- /package/{cli/template → template}/base-library.mustache +0 -0
- /package/{cli/template → template}/placeholder.mustache +0 -0
package/index.d.ts
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Configuration for LangTag translations.
|
|
3
|
-
* @template Namespaces - The type used for namespaces, defaults to string.
|
|
4
|
-
*/
|
|
5
|
-
export interface LangTagTranslationsConfig<Namespaces = string> {
|
|
6
|
-
/** Optional base path for translation keys. */
|
|
7
|
-
path?: string;
|
|
8
|
-
/** The namespace for the translations. */
|
|
9
|
-
namespace: Namespaces;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Represents a collection of translations.
|
|
13
|
-
* Keys are strings, and values can be either strings (translations)
|
|
14
|
-
* or nested LangTagTranslations objects for hierarchical translations.
|
|
15
|
-
*/
|
|
16
|
-
export type LangTagTranslations = {
|
|
17
|
-
[key: string]: string | LangTagTranslations;
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* Defines the structure for parameters used in interpolation.
|
|
21
|
-
* It's a record where keys are placeholders and values are their replacements.
|
|
22
|
-
*/
|
|
23
|
-
export type InterpolationParams = Record<string, any>;
|
|
24
|
-
/**
|
|
25
|
-
* Represents a function that takes optional interpolation parameters
|
|
26
|
-
* and returns a translated string.
|
|
27
|
-
*/
|
|
28
|
-
export type ParameterizedTranslation = (params?: InterpolationParams) => string;
|
|
29
|
-
/**
|
|
30
|
-
* Transforms a static translation object into an object where each
|
|
31
|
-
* translation string or nested object is converted into a callable function
|
|
32
|
-
* or a nested structure of callable functions.
|
|
33
|
-
* @template T - The structure of the input translations.
|
|
34
|
-
*/
|
|
35
|
-
export type CallableTranslations<T> = {
|
|
36
|
-
[P in keyof T]: T[P] extends ParameterizedTranslation ? ParameterizedTranslation : T[P] extends (...args: any[]) => string ? T[P] : T[P] extends Record<string, any> ? CallableTranslations<T[P]> : ParameterizedTranslation;
|
|
37
|
-
};
|
|
38
|
-
/**
|
|
39
|
-
* Context provided to a translation transformer function.
|
|
40
|
-
* @template Config - The LangTag translations configuration type.
|
|
41
|
-
*/
|
|
42
|
-
export interface TranslationTransformContext<Config extends LangTagTranslationsConfig> {
|
|
43
|
-
/** The LangTag configuration object. */
|
|
44
|
-
config: Config | undefined;
|
|
45
|
-
/** The path of the direct parent object of the current translation key, including the base path from config. */
|
|
46
|
-
parentPath: string;
|
|
47
|
-
/** The full path to the current translation key, including the base path from config. */
|
|
48
|
-
path: string;
|
|
49
|
-
/** The path to the current translation key, relative to the root of the translations object (excluding the base path from config). */
|
|
50
|
-
unprefixedPath: string;
|
|
51
|
-
/** The current translation key. */
|
|
52
|
-
key: string;
|
|
53
|
-
/** The raw string value of the translation. */
|
|
54
|
-
value: string;
|
|
55
|
-
/** Optional interpolation parameters for the translation. */
|
|
56
|
-
params?: InterpolationParams;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Defines the signature for a function that transforms a raw translation string.
|
|
60
|
-
* @template Config - The LangTag translations configuration type.
|
|
61
|
-
* @param transformContext - The context for the transformation.
|
|
62
|
-
* @returns The transformed translation string.
|
|
63
|
-
*/
|
|
64
|
-
export type TranslationTransformer<Config extends LangTagTranslationsConfig> = (transformContext: TranslationTransformContext<Config>) => string;
|
|
65
|
-
/**
|
|
66
|
-
* Context provided to a translation key processor function.
|
|
67
|
-
* It omits the 'params' field from `TranslationTransformContext`.
|
|
68
|
-
* @template Config - The LangTag translations configuration type.
|
|
69
|
-
*/
|
|
70
|
-
export type TranslationKeyProcessorContext<Config extends LangTagTranslationsConfig> = Omit<TranslationTransformContext<Config>, 'params'>;
|
|
71
|
-
/**
|
|
72
|
-
* Defines the signature for a function that processes translation keys.
|
|
73
|
-
* This allows for modifying or generating new keys based on the original key and value.
|
|
74
|
-
* @template Config - The LangTag translations configuration type.
|
|
75
|
-
*/
|
|
76
|
-
export type TranslationKeyProcessor<Config extends LangTagTranslationsConfig = LangTagTranslationsConfig> = (
|
|
77
|
-
/** Context for processing the key. */
|
|
78
|
-
context: TranslationKeyProcessorContext<Config>,
|
|
79
|
-
/**
|
|
80
|
-
* Callback to add a processed key.
|
|
81
|
-
* @param newKey - The new key to be added to the result.
|
|
82
|
-
* @param originalValue - The original string value associated with the key being processed.
|
|
83
|
-
*/
|
|
84
|
-
addProcessedKey: (newKey: string, originalValue: string) => void) => void;
|
|
85
|
-
/**
|
|
86
|
-
* Defines the strategy for mapping and transforming translations.
|
|
87
|
-
* @template Config - The LangTag translations configuration type.
|
|
88
|
-
*/
|
|
89
|
-
export interface TranslationMappingStrategy<Config extends LangTagTranslationsConfig> {
|
|
90
|
-
/** The function used to transform raw translation strings. */
|
|
91
|
-
transform: TranslationTransformer<Config>;
|
|
92
|
-
/** Optional function to process translation keys. */
|
|
93
|
-
processKey?: TranslationKeyProcessor<Config>;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Creates a callable translations object from a static translations object.
|
|
97
|
-
* This function initializes the transformation process.
|
|
98
|
-
* @template T - The type of the input translations object.
|
|
99
|
-
* @template Config - The LangTag translations configuration type.
|
|
100
|
-
* @param translations - The static translations object.
|
|
101
|
-
* @param config - The LangTag configuration object.
|
|
102
|
-
* @param strategy - The translation mapping strategy.
|
|
103
|
-
* @returns A callable translations object.
|
|
104
|
-
*/
|
|
105
|
-
export declare function createCallableTranslations<T extends LangTagTranslations, Config extends LangTagTranslationsConfig>(translations: T, config: Config | undefined, strategy: TranslationMappingStrategy<Config>): CallableTranslations<T>;
|
|
106
|
-
/**
|
|
107
|
-
* Helper type to determine the flexible value of a translation property.
|
|
108
|
-
* If `T` is a function returning a string, it can be `T` or `string`.
|
|
109
|
-
* If `T` is a record, it recursively applies `RecursiveFlexibleTranslations`.
|
|
110
|
-
* Otherwise, it can be `ParameterizedTranslation`, `T`, or `string`.
|
|
111
|
-
* @template T - The type of the property value.
|
|
112
|
-
* @template IsPartial - A boolean indicating whether properties should be optional.
|
|
113
|
-
*/
|
|
114
|
-
type FlexibleValue<T, IsPartial extends boolean> = T extends (...args: any[]) => string ? T | string : T extends Record<string, any> ? RecursiveFlexibleTranslations<T, IsPartial> : ParameterizedTranslation | T | string;
|
|
115
|
-
/**
|
|
116
|
-
* Core type for flexible translations, allowing properties to be optional recursively.
|
|
117
|
-
* This type serves as the foundation for `FlexibleTranslations` and `PartialFlexibleTranslations`.
|
|
118
|
-
* It transforms a given translation structure `T` into a flexible version where each property
|
|
119
|
-
* can be its original type, a string, or a `ParameterizedTranslation` function.
|
|
120
|
-
* If `IsPartial` is true, all properties at all levels of nesting become optional.
|
|
121
|
-
*
|
|
122
|
-
* @template T The original, un-transformed, structure of the translations.
|
|
123
|
-
* @template IsPartial A boolean indicating whether properties should be optional.
|
|
124
|
-
* If true, all properties at all levels become optional (e.g., `string | undefined`).
|
|
125
|
-
* If false, properties are required (e.g., `string`).
|
|
126
|
-
*/
|
|
127
|
-
export type RecursiveFlexibleTranslations<T, IsPartial extends boolean> = IsPartial extends true ? {
|
|
128
|
-
[P in keyof T]?: FlexibleValue<T[P], IsPartial>;
|
|
129
|
-
} : {
|
|
130
|
-
[P in keyof T]: FlexibleValue<T[P], IsPartial>;
|
|
131
|
-
};
|
|
132
|
-
/**
|
|
133
|
-
* Represents a flexible structure for translations where all properties are required, based on an original type `T`.
|
|
134
|
-
* Allows for strings, `ParameterizedTranslation` functions, or other compatible functions
|
|
135
|
-
* at any level of the translation object. This provides flexibility in how translations
|
|
136
|
-
* are initially defined.
|
|
137
|
-
* This type is an alias for `RecursiveFlexibleTranslations<T, false>`.
|
|
138
|
-
* @template T - The original structure of the translations.
|
|
139
|
-
*/
|
|
140
|
-
export type FlexibleTranslations<T> = RecursiveFlexibleTranslations<T, false>;
|
|
141
|
-
/**
|
|
142
|
-
* Represents a deeply partial version of the structure that `FlexibleTranslations<T>` would produce, based on an original type `T`.
|
|
143
|
-
* All properties at all levels of nesting are made optional.
|
|
144
|
-
* The transformation rules for property types mirror those in `FlexibleTranslations<T>`.
|
|
145
|
-
* This type is an alias for `RecursiveFlexibleTranslations<T, true>`.
|
|
146
|
-
* @template T - The original, un-transformed, structure of the translations. This is the same kind of type argument that `FlexibleTranslations<T>` expects.
|
|
147
|
-
*/
|
|
148
|
-
export type PartialFlexibleTranslations<T> = RecursiveFlexibleTranslations<T, true>;
|
|
149
|
-
/**
|
|
150
|
-
* Normalizes a `FlexibleTranslations` or `PartialFlexibleTranslations` object into a `CallableTranslations` object.
|
|
151
|
-
* Converts plain strings into `ParameterizedTranslation` functions and ensures
|
|
152
|
-
* that all callable elements conform to the `ParameterizedTranslation` signature.
|
|
153
|
-
* Only properties present in the input `translations` object will be processed and included in the result.
|
|
154
|
-
* @template T - The structure of the original translations.
|
|
155
|
-
* @param translations - The flexible or partial flexible translations object to normalize.
|
|
156
|
-
* @returns A `CallableTranslations` object. The returned object will only contain callable translations for properties that were present in the input `translations` object.
|
|
157
|
-
*/
|
|
158
|
-
export declare function normalizeTranslations<T>(translations: RecursiveFlexibleTranslations<T, boolean>): CallableTranslations<T>;
|
|
159
|
-
/**
|
|
160
|
-
* Retrieves a translation function from a nested translation object using a dot-separated path.
|
|
161
|
-
* It is recommended to use an unprefixed path (a path that does not include the base path from the configuration)
|
|
162
|
-
* with this function, as it operates on the structure of the callable translations object where keys are unprefixed.
|
|
163
|
-
* @template T - The type of the translations object.
|
|
164
|
-
* @param translations The object containing translation functions.
|
|
165
|
-
* @param dottedPath A string path using dot notation (e.g., "user.profile.greeting"). This path should generally be unprefixed.
|
|
166
|
-
* @returns The translation function, or null if not found or invalid.
|
|
167
|
-
*/
|
|
168
|
-
export declare function lookupTranslation<T>(translations: CallableTranslations<T>, dottedPath: string): ParameterizedTranslation | null;
|
|
169
|
-
export {};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|