intor-translator 1.4.5 → 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 {
@@ -256,15 +251,6 @@ function translate(options) {
256
251
  return ctx.finalMessage;
257
252
  }
258
253
 
259
- // src/translators/methods/translate-raw.ts
260
- function translateRaw(options) {
261
- const { ctx } = runTranslate(options);
262
- if (ctx.rawValue === void 0) {
263
- throw new Error("Invariant violated: missing hook did not produce output");
264
- }
265
- return ctx.rawValue;
266
- }
267
-
268
254
  // src/translators/core-translator/core-translator.ts
269
255
  var CoreTranslator = class extends BaseTranslator {
270
256
  /** User-provided options including messages, locale, and config. */
@@ -320,18 +306,6 @@ var CoreTranslator = class extends BaseTranslator {
320
306
  replacements
321
307
  });
322
308
  };
323
- /** Get the raw message value for a key without formatting or interpolation. */
324
- tRaw = (key, replacements) => {
325
- return translateRaw({
326
- hooks: this.hooks,
327
- messages: this._messages,
328
- locale: this._locale,
329
- isLoading: this._isLoading,
330
- translateConfig: this.translateConfig,
331
- key,
332
- replacements
333
- });
334
- };
335
309
  };
336
310
 
337
311
  // src/translators/scope-translator/utils/get-full-key.ts
@@ -369,18 +343,6 @@ var ScopeTranslator = class extends CoreTranslator {
369
343
  key: fullKey,
370
344
  replacements
371
345
  });
372
- },
373
- tRaw: (key, replacements) => {
374
- const fullKey = getFullKey(preKey, key);
375
- return translateRaw({
376
- hooks: this.hooks,
377
- messages: this._messages,
378
- locale: this._locale,
379
- isLoading: this._isLoading,
380
- translateConfig: this.translateConfig,
381
- key: fullKey,
382
- replacements
383
- });
384
346
  }
385
347
  };
386
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 {
@@ -254,15 +249,6 @@ function translate(options) {
254
249
  return ctx.finalMessage;
255
250
  }
256
251
 
257
- // src/translators/methods/translate-raw.ts
258
- function translateRaw(options) {
259
- const { ctx } = runTranslate(options);
260
- if (ctx.rawValue === void 0) {
261
- throw new Error("Invariant violated: missing hook did not produce output");
262
- }
263
- return ctx.rawValue;
264
- }
265
-
266
252
  // src/translators/core-translator/core-translator.ts
267
253
  var CoreTranslator = class extends BaseTranslator {
268
254
  /** User-provided options including messages, locale, and config. */
@@ -318,18 +304,6 @@ var CoreTranslator = class extends BaseTranslator {
318
304
  replacements
319
305
  });
320
306
  };
321
- /** Get the raw message value for a key without formatting or interpolation. */
322
- tRaw = (key, replacements) => {
323
- return translateRaw({
324
- hooks: this.hooks,
325
- messages: this._messages,
326
- locale: this._locale,
327
- isLoading: this._isLoading,
328
- translateConfig: this.translateConfig,
329
- key,
330
- replacements
331
- });
332
- };
333
307
  };
334
308
 
335
309
  // src/translators/scope-translator/utils/get-full-key.ts
@@ -367,18 +341,6 @@ var ScopeTranslator = class extends CoreTranslator {
367
341
  key: fullKey,
368
342
  replacements
369
343
  });
370
- },
371
- tRaw: (key, replacements) => {
372
- const fullKey = getFullKey(preKey, key);
373
- return translateRaw({
374
- hooks: this.hooks,
375
- messages: this._messages,
376
- locale: this._locale,
377
- isLoading: this._isLoading,
378
- translateConfig: this.translateConfig,
379
- key: fullKey,
380
- replacements
381
- });
382
344
  }
383
345
  };
384
346
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intor-translator",
3
- "version": "1.4.5",
3
+ "version": "1.4.6",
4
4
  "description": "🤖 A modern, type-safe i18n engine.",
5
5
  "author": {
6
6
  "name": "Yiming Liao",