intor-translator 1.4.4 → 1.4.6

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/dist/index.cjs CHANGED
@@ -31,15 +31,11 @@ var findMessageInLocales = ({
31
31
  var findMessage = rura.rura.createHook(
32
32
  "findMessage",
33
33
  (ctx) => {
34
- ctx.rawValue = void 0;
35
- ctx.rawString = void 0;
36
- const message = findMessageInLocales({
34
+ ctx.rawMessage = findMessageInLocales({
37
35
  messages: ctx.messages,
38
36
  candidateLocales: ctx.candidateLocales,
39
37
  key: ctx.key
40
38
  });
41
- ctx.rawValue = message;
42
- if (typeof message === "string") ctx.rawString = message;
43
39
  },
44
40
  200
45
41
  );
@@ -54,8 +50,7 @@ function makeHandlerContext(ctx) {
54
50
  key: ctx.key,
55
51
  replacements: ctx.replacements,
56
52
  candidateLocales: ctx.candidateLocales,
57
- rawValue: ctx.rawValue,
58
- rawString: ctx.rawString,
53
+ rawMessage: ctx.rawMessage,
59
54
  formattedMessage: ctx.formattedMessage,
60
55
  meta: ctx.meta
61
56
  });
@@ -65,9 +60,9 @@ function makeHandlerContext(ctx) {
65
60
  var format = rura.rura.createHook(
66
61
  "format",
67
62
  (ctx) => {
68
- const { config, rawString } = ctx;
63
+ const { config, rawMessage } = ctx;
69
64
  const { formatHandler } = config.handlers || {};
70
- if (!formatHandler || rawString === void 0) return;
65
+ if (!formatHandler || rawMessage === void 0) return;
71
66
  ctx.formattedMessage = formatHandler(
72
67
  makeHandlerContext(ctx)
73
68
  );
@@ -98,8 +93,8 @@ var replaceValues = (message, params) => {
98
93
  var interpolate = rura.rura.createHook(
99
94
  "interpolate",
100
95
  (ctx) => {
101
- const { rawString, formattedMessage, replacements } = ctx;
102
- const message = formattedMessage ?? rawString;
96
+ const { rawMessage, formattedMessage, replacements } = ctx;
97
+ const message = formattedMessage ?? rawMessage;
103
98
  if (typeof message !== "string" || !replacements) {
104
99
  ctx.finalMessage = message;
105
100
  return;
@@ -130,8 +125,8 @@ var loading = rura.rura.createHook(
130
125
  var missing = rura.rura.createHook(
131
126
  "missing",
132
127
  (ctx) => {
133
- const { config, key, rawString } = ctx;
134
- if (rawString !== void 0) return;
128
+ const { config, key, rawMessage } = ctx;
129
+ if (rawMessage !== void 0) return;
135
130
  const { missingHandler } = config.handlers || {};
136
131
  if (missingHandler) {
137
132
  return {
@@ -176,7 +171,6 @@ var DEFAULT_HOOKS = [
176
171
  format,
177
172
  interpolate
178
173
  ];
179
- rura.rura.createPipeline(DEFAULT_HOOKS).debugHooks();
180
174
 
181
175
  // src/translators/base-translator/base-translator.ts
182
176
  var BaseTranslator = class {
@@ -257,15 +251,6 @@ function translate(options) {
257
251
  return ctx.finalMessage;
258
252
  }
259
253
 
260
- // src/translators/methods/translate-raw.ts
261
- function translateRaw(options) {
262
- const { ctx } = runTranslate(options);
263
- if (ctx.rawValue === void 0) {
264
- throw new Error("Invariant violated: missing hook did not produce output");
265
- }
266
- return ctx.rawValue;
267
- }
268
-
269
254
  // src/translators/core-translator/core-translator.ts
270
255
  var CoreTranslator = class extends BaseTranslator {
271
256
  /** User-provided options including messages, locale, and config. */
@@ -321,18 +306,6 @@ var CoreTranslator = class extends BaseTranslator {
321
306
  replacements
322
307
  });
323
308
  };
324
- /** Get the raw message value for a key without formatting or interpolation. */
325
- tRaw = (key, replacements) => {
326
- return translateRaw({
327
- hooks: this.hooks,
328
- messages: this._messages,
329
- locale: this._locale,
330
- isLoading: this._isLoading,
331
- translateConfig: this.translateConfig,
332
- key,
333
- replacements
334
- });
335
- };
336
309
  };
337
310
 
338
311
  // src/translators/scope-translator/utils/get-full-key.ts
@@ -370,18 +343,6 @@ var ScopeTranslator = class extends CoreTranslator {
370
343
  key: fullKey,
371
344
  replacements
372
345
  });
373
- },
374
- tRaw: (key, replacements) => {
375
- const fullKey = getFullKey(preKey, key);
376
- return translateRaw({
377
- hooks: this.hooks,
378
- messages: this._messages,
379
- locale: this._locale,
380
- isLoading: this._isLoading,
381
- translateConfig: this.translateConfig,
382
- key: fullKey,
383
- replacements
384
- });
385
346
  }
386
347
  };
387
348
  }
package/dist/index.d.cts CHANGED
@@ -299,7 +299,7 @@ type LoadingHandler = (ctx: HandlerContext) => MessageValue;
299
299
  type MissingHandler = (ctx: HandlerContext) => MessageValue;
300
300
  /** Function to format a resolved message. */
301
301
  type FormatHandler = (ctx: HandlerContext & {
302
- rawString: string;
302
+ rawMessage: string;
303
303
  }) => MessageValue;
304
304
  /**
305
305
  * Snapshot of the translate pipeline context exposed to handlers.
@@ -330,9 +330,7 @@ interface TranslateContext {
330
330
  /** Ordered list of locales to try, including fallbacks */
331
331
  candidateLocales: string[];
332
332
  /** Raw message value resolved from the message tree. */
333
- rawValue?: MessageValue;
334
- /** Raw string message before formatting. */
335
- rawString?: string;
333
+ rawMessage?: MessageValue;
336
334
  /** Message after formatting (e.g. ICU, custom formatters) */
337
335
  formattedMessage?: MessageValue;
338
336
  /** Final value produced by the pipeline */
@@ -437,15 +435,12 @@ declare class CoreTranslator<M extends LocaleMessages | unknown = unknown, L ext
437
435
  hasKey: <K extends LocalizedLeafKeys<M, L>>(key: K, targetLocale?: Locale<M>) => boolean;
438
436
  /** Get the translated message for a key, with optional replacements. */
439
437
  t: <K extends LocalizedLeafKeys<M, L> = LocalizedLeafKeys<M, L>>(key: K, replacements?: Replacement) => LocalizedLeafValue<M, K, L>;
440
- /** Get the raw message value for a key without formatting or interpolation. */
441
- tRaw: <K extends LocalizedLeafKeys<M, L> = LocalizedLeafKeys<M, L>>(key: K, replacements?: Replacement) => LocalizedLeafValue<M, K, L>;
442
438
  }
443
439
 
444
440
  type ScopeTranslatorOptions<M> = CoreTranslatorOptions<M>;
445
441
  type ScopeTranslatorMethods<M extends LocaleMessages | unknown = unknown, L extends keyof M | "union" = "union", PK extends string | undefined = undefined, K extends string = PK extends string ? ScopedLeafKeys<M, PK, L> : LocalizedLeafKeys<M, L>> = {
446
442
  hasKey: (key?: K, targetLocale?: Locale<M>) => boolean;
447
443
  t: <Key extends K>(key?: Key, replacements?: Replacement) => PK extends string ? ScopedLeafValue<M, PK, Key, L> : LocalizedLeafValue<M, Key, L>;
448
- tRaw: <Key extends K>(key?: Key, replacements?: Replacement) => PK extends string ? ScopedLeafValue<M, PK, Key, L> : LocalizedLeafValue<M, Key, L>;
449
444
  };
450
445
 
451
446
  declare class ScopeTranslator<M extends LocaleMessages | unknown = unknown, L extends keyof M | "union" = "union"> extends CoreTranslator<M> {
package/dist/index.d.ts CHANGED
@@ -299,7 +299,7 @@ type LoadingHandler = (ctx: HandlerContext) => MessageValue;
299
299
  type MissingHandler = (ctx: HandlerContext) => MessageValue;
300
300
  /** Function to format a resolved message. */
301
301
  type FormatHandler = (ctx: HandlerContext & {
302
- rawString: string;
302
+ rawMessage: string;
303
303
  }) => MessageValue;
304
304
  /**
305
305
  * Snapshot of the translate pipeline context exposed to handlers.
@@ -330,9 +330,7 @@ interface TranslateContext {
330
330
  /** Ordered list of locales to try, including fallbacks */
331
331
  candidateLocales: string[];
332
332
  /** Raw message value resolved from the message tree. */
333
- rawValue?: MessageValue;
334
- /** Raw string message before formatting. */
335
- rawString?: string;
333
+ rawMessage?: MessageValue;
336
334
  /** Message after formatting (e.g. ICU, custom formatters) */
337
335
  formattedMessage?: MessageValue;
338
336
  /** Final value produced by the pipeline */
@@ -437,15 +435,12 @@ declare class CoreTranslator<M extends LocaleMessages | unknown = unknown, L ext
437
435
  hasKey: <K extends LocalizedLeafKeys<M, L>>(key: K, targetLocale?: Locale<M>) => boolean;
438
436
  /** Get the translated message for a key, with optional replacements. */
439
437
  t: <K extends LocalizedLeafKeys<M, L> = LocalizedLeafKeys<M, L>>(key: K, replacements?: Replacement) => LocalizedLeafValue<M, K, L>;
440
- /** Get the raw message value for a key without formatting or interpolation. */
441
- tRaw: <K extends LocalizedLeafKeys<M, L> = LocalizedLeafKeys<M, L>>(key: K, replacements?: Replacement) => LocalizedLeafValue<M, K, L>;
442
438
  }
443
439
 
444
440
  type ScopeTranslatorOptions<M> = CoreTranslatorOptions<M>;
445
441
  type ScopeTranslatorMethods<M extends LocaleMessages | unknown = unknown, L extends keyof M | "union" = "union", PK extends string | undefined = undefined, K extends string = PK extends string ? ScopedLeafKeys<M, PK, L> : LocalizedLeafKeys<M, L>> = {
446
442
  hasKey: (key?: K, targetLocale?: Locale<M>) => boolean;
447
443
  t: <Key extends K>(key?: Key, replacements?: Replacement) => PK extends string ? ScopedLeafValue<M, PK, Key, L> : LocalizedLeafValue<M, Key, L>;
448
- tRaw: <Key extends K>(key?: Key, replacements?: Replacement) => PK extends string ? ScopedLeafValue<M, PK, Key, L> : LocalizedLeafValue<M, Key, L>;
449
444
  };
450
445
 
451
446
  declare class ScopeTranslator<M extends LocaleMessages | unknown = unknown, L extends keyof M | "union" = "union"> extends CoreTranslator<M> {
package/dist/index.js CHANGED
@@ -29,15 +29,11 @@ var findMessageInLocales = ({
29
29
  var findMessage = rura.createHook(
30
30
  "findMessage",
31
31
  (ctx) => {
32
- ctx.rawValue = void 0;
33
- ctx.rawString = void 0;
34
- const message = findMessageInLocales({
32
+ ctx.rawMessage = findMessageInLocales({
35
33
  messages: ctx.messages,
36
34
  candidateLocales: ctx.candidateLocales,
37
35
  key: ctx.key
38
36
  });
39
- ctx.rawValue = message;
40
- if (typeof message === "string") ctx.rawString = message;
41
37
  },
42
38
  200
43
39
  );
@@ -52,8 +48,7 @@ function makeHandlerContext(ctx) {
52
48
  key: ctx.key,
53
49
  replacements: ctx.replacements,
54
50
  candidateLocales: ctx.candidateLocales,
55
- rawValue: ctx.rawValue,
56
- rawString: ctx.rawString,
51
+ rawMessage: ctx.rawMessage,
57
52
  formattedMessage: ctx.formattedMessage,
58
53
  meta: ctx.meta
59
54
  });
@@ -63,9 +58,9 @@ function makeHandlerContext(ctx) {
63
58
  var format = rura.createHook(
64
59
  "format",
65
60
  (ctx) => {
66
- const { config, rawString } = ctx;
61
+ const { config, rawMessage } = ctx;
67
62
  const { formatHandler } = config.handlers || {};
68
- if (!formatHandler || rawString === void 0) return;
63
+ if (!formatHandler || rawMessage === void 0) return;
69
64
  ctx.formattedMessage = formatHandler(
70
65
  makeHandlerContext(ctx)
71
66
  );
@@ -96,8 +91,8 @@ var replaceValues = (message, params) => {
96
91
  var interpolate = rura.createHook(
97
92
  "interpolate",
98
93
  (ctx) => {
99
- const { rawString, formattedMessage, replacements } = ctx;
100
- const message = formattedMessage ?? rawString;
94
+ const { rawMessage, formattedMessage, replacements } = ctx;
95
+ const message = formattedMessage ?? rawMessage;
101
96
  if (typeof message !== "string" || !replacements) {
102
97
  ctx.finalMessage = message;
103
98
  return;
@@ -128,8 +123,8 @@ var loading = rura.createHook(
128
123
  var missing = rura.createHook(
129
124
  "missing",
130
125
  (ctx) => {
131
- const { config, key, rawString } = ctx;
132
- if (rawString !== void 0) return;
126
+ const { config, key, rawMessage } = ctx;
127
+ if (rawMessage !== void 0) return;
133
128
  const { missingHandler } = config.handlers || {};
134
129
  if (missingHandler) {
135
130
  return {
@@ -174,7 +169,6 @@ var DEFAULT_HOOKS = [
174
169
  format,
175
170
  interpolate
176
171
  ];
177
- rura.createPipeline(DEFAULT_HOOKS).debugHooks();
178
172
 
179
173
  // src/translators/base-translator/base-translator.ts
180
174
  var BaseTranslator = class {
@@ -255,15 +249,6 @@ function translate(options) {
255
249
  return ctx.finalMessage;
256
250
  }
257
251
 
258
- // src/translators/methods/translate-raw.ts
259
- function translateRaw(options) {
260
- const { ctx } = runTranslate(options);
261
- if (ctx.rawValue === void 0) {
262
- throw new Error("Invariant violated: missing hook did not produce output");
263
- }
264
- return ctx.rawValue;
265
- }
266
-
267
252
  // src/translators/core-translator/core-translator.ts
268
253
  var CoreTranslator = class extends BaseTranslator {
269
254
  /** User-provided options including messages, locale, and config. */
@@ -319,18 +304,6 @@ var CoreTranslator = class extends BaseTranslator {
319
304
  replacements
320
305
  });
321
306
  };
322
- /** Get the raw message value for a key without formatting or interpolation. */
323
- tRaw = (key, replacements) => {
324
- return translateRaw({
325
- hooks: this.hooks,
326
- messages: this._messages,
327
- locale: this._locale,
328
- isLoading: this._isLoading,
329
- translateConfig: this.translateConfig,
330
- key,
331
- replacements
332
- });
333
- };
334
307
  };
335
308
 
336
309
  // src/translators/scope-translator/utils/get-full-key.ts
@@ -368,18 +341,6 @@ var ScopeTranslator = class extends CoreTranslator {
368
341
  key: fullKey,
369
342
  replacements
370
343
  });
371
- },
372
- tRaw: (key, replacements) => {
373
- const fullKey = getFullKey(preKey, key);
374
- return translateRaw({
375
- hooks: this.hooks,
376
- messages: this._messages,
377
- locale: this._locale,
378
- isLoading: this._isLoading,
379
- translateConfig: this.translateConfig,
380
- key: fullKey,
381
- replacements
382
- });
383
344
  }
384
345
  };
385
346
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intor-translator",
3
- "version": "1.4.4",
3
+ "version": "1.4.6",
4
4
  "description": "🤖 A modern, type-safe i18n engine.",
5
5
  "author": {
6
6
  "name": "Yiming Liao",