@lang-tag/cli 0.18.1 → 0.20.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.
@@ -1,9 +1,9 @@
1
1
  {{#isTypeScript}}
2
2
  import {
3
- CallableTranslations,
4
- LangTagTranslations,
5
- LangTagTranslationsConfig,
6
- PartialFlexibleTranslations,
3
+ type CallableTranslations,
4
+ type LangTagTranslations,
5
+ type LangTagTranslationsConfig,
6
+ type PartialFlexibleTranslations,
7
7
  createCallableTranslations,
8
8
  normalizeTranslations,
9
9
  lookupTranslation
@@ -17,7 +17,7 @@ import React, {
17
17
  createContext,
18
18
  useContext,
19
19
  useMemo,
20
- ReactNode
20
+ type ReactNode
21
21
  } from 'react';
22
22
  {{/isReact}}
23
23
 
@@ -30,8 +30,16 @@ export function processPlaceholders(
30
30
  }
31
31
 
32
32
  const key = placeholder.trim();
33
- if (params && key in params) {
34
- parts.push(params[key]);
33
+ const value = params?.[key];
34
+
35
+ if (React.isValidElement(value)) {
36
+ parts.push(value);
37
+ } else if (
38
+ typeof value === 'string' ||
39
+ typeof value === 'number' ||
40
+ typeof value === 'boolean'
41
+ ) {
42
+ parts.push(String(value));
35
43
  } else {
36
44
  parts.push('');
37
45
  }
@@ -49,12 +57,11 @@ export function processPlaceholders(
49
57
  return parts.join('');
50
58
  }
51
59
 
52
- return parts.map((part, index) => {
53
- if (React.isValidElement(part)) {
54
- return React.cloneElement(part, { key: index });
55
- }
56
- return React.createElement(React.Fragment, { key: index }, part);
57
- }){{#isTypeScript}} as unknown as string{{/isTypeScript}};
60
+ return parts.map((part, index) =>
61
+ React.isValidElement(part)
62
+ ? React.cloneElement(part, { key: index })
63
+ : React.createElement(React.Fragment, { key: index }, part)
64
+ ){{#isTypeScript}} as unknown as string{{/isTypeScript}};
58
65
  }
59
66
  {{/isReact}}
60
67
 
package/type.d.ts CHANGED
@@ -40,6 +40,17 @@ export interface LangTagCLIConfig {
40
40
  * @default false
41
41
  */
42
42
  isLibrary: boolean;
43
+ /**
44
+ * When true and isLibrary is true, automatically adds "_" prefix to tagName
45
+ * to prevent the tag from being suggested in TypeScript autocomplete after compilation.
46
+ * This ensures that library tags remain internal and are not exposed in .d.ts files.
47
+ * @default true
48
+ * @example
49
+ * // With enforceLibraryTagPrefix: true and tagName: "lang"
50
+ * // Generated tag function will be: export function _lang(...)
51
+ * // Config tagName also will be automatically set to "_lang"
52
+ */
53
+ enforceLibraryTagPrefix?: boolean;
43
54
  collect?: {
44
55
  /**
45
56
  * Translation collector that defines how translation tags are organized into output files.
@@ -134,6 +145,12 @@ export interface LangTagCLIConfig {
134
145
  * @default 1
135
146
  */
136
147
  translationArgPosition: 1 | 2;
148
+ /**
149
+ * Directory containing compiled TypeScript declaration files (.d.ts) to remove export modifier.
150
+ * Used by the `hide-compiled-exports` command to remove exports of lang-tag variables.
151
+ * @default 'dist'
152
+ */
153
+ hideDistDir?: string;
137
154
  debug?: boolean;
138
155
  }
139
156
  type Validity = 'ok' | 'invalid-param-1' | 'invalid-param-2' | 'translations-not-found';
@@ -144,6 +161,8 @@ export interface LangTagCLIProcessedTag {
144
161
  parameterTranslations: any;
145
162
  parameterConfig?: any;
146
163
  variableName?: string;
164
+ /** Generic type parameter if present (e.g., "ValidationTranslations" from "lang<ValidationTranslations>(...)") */
165
+ genericType?: string;
147
166
  /** Character index in the whole text where the match starts */
148
167
  index: number;
149
168
  /** Line number (1-based) where the match was found */
@@ -232,6 +251,23 @@ export interface LangTagCLIConfigGenerationEvent {
232
251
  * null = means configuration will be removed
233
252
  **/
234
253
  save(config: LangTagTranslationsConfig | null, triggerName?: string): void;
254
+ /**
255
+ * Returns the current configuration object that should be used as a base for modifications.
256
+ * This method provides a reusable way to get the active configuration:
257
+ * - If `save()` was called, returns `savedConfig` (a mutable copy)
258
+ * - Otherwise, returns `config` (a mutable copy)
259
+ * - If neither exists, returns an empty object `{}`
260
+ *
261
+ * The returned object is always a shallow copy, so it can be safely modified.
262
+ *
263
+ * @example
264
+ * ```ts
265
+ * const currentConfig = event.getCurrentConfig();
266
+ * currentConfig.namespace = 'new-namespace';
267
+ * event.save(currentConfig);
268
+ * ```
269
+ */
270
+ getCurrentConfig(): LangTagTranslationsConfig;
235
271
  }
236
272
  export interface LangTagCLICollectConfigFixEvent {
237
273
  config: LangTagTranslationsConfig;