intor 1.0.13 → 1.0.15

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
@@ -1,12 +1,12 @@
1
1
  'use strict';
2
2
 
3
3
  var logry = require('logry');
4
- var intorTranslator = require('intor-translator');
5
4
  var headers = require('next/headers');
6
5
  var path = require('path');
7
6
  var perf_hooks = require('perf_hooks');
8
7
  var pLimit = require('p-limit');
9
8
  var fs = require('fs/promises');
9
+ var intorTranslator = require('intor-translator');
10
10
 
11
11
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
12
12
 
@@ -1111,27 +1111,16 @@ var intorRuntime = async ({
1111
1111
  // src/modules/intor/intor.ts
1112
1112
  var intor = async ({
1113
1113
  request,
1114
- config,
1115
- translateHandlers
1114
+ config
1116
1115
  }) => {
1117
- var _a, _b;
1118
1116
  const logger = logry.logry({ id: config.id, scope: "intor" });
1119
1117
  logger.info("Starting Intor initialization:", {
1120
1118
  adapter: config.adapter
1121
1119
  });
1122
1120
  const runtime = await intorRuntime({ config, request });
1123
- const { initialLocale, messages } = runtime;
1124
1121
  switch (config.adapter) {
1125
1122
  case "next-server": {
1126
- const translator = new intorTranslator.Translator({
1127
- locale: initialLocale,
1128
- messages,
1129
- fallbackLocales: config.fallbackLocales,
1130
- loadingMessage: (_a = config.translator) == null ? void 0 : _a.loadingMessage,
1131
- placeholder: (_b = config.translator) == null ? void 0 : _b.placeholder,
1132
- handlers: translateHandlers
1133
- });
1134
- return translator;
1123
+ return runtime;
1135
1124
  }
1136
1125
  case "next-client": {
1137
1126
  return runtime;
@@ -1146,9 +1135,25 @@ var intor = async ({
1146
1135
  }
1147
1136
  }
1148
1137
  };
1138
+ var createIntor = (config, translateHandlers) => {
1139
+ return async (request) => {
1140
+ var _a, _b;
1141
+ const { initialLocale, messages } = await intor({ config, request });
1142
+ const translator = new intorTranslator.Translator({
1143
+ locale: initialLocale,
1144
+ messages,
1145
+ fallbackLocales: config.fallbackLocales,
1146
+ loadingMessage: (_a = config.translator) == null ? void 0 : _a.loadingMessage,
1147
+ placeholder: (_b = config.translator) == null ? void 0 : _b.placeholder,
1148
+ handlers: translateHandlers
1149
+ });
1150
+ return translator;
1151
+ };
1152
+ };
1149
1153
 
1150
1154
  exports.IntorError = IntorError;
1151
1155
  exports.IntorErrorCode = IntorErrorCode;
1156
+ exports.createIntor = createIntor;
1152
1157
  exports.defineIntorConfig = defineIntorConfig;
1153
1158
  exports.extractPathname = extractPathname;
1154
1159
  exports.fetchApiMessages = fetchApiMessages;
package/dist/index.d.cts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Level, NormalizerConfig, FormatterConfig, LoggerPreset } from 'logry';
2
2
  import { Locale, LocaleNamespaceMessages, FallbackLocalesMap, TranslateHandlers, Translator } from 'intor-translator';
3
- export { FormatMessage, HasKeyFunction, OnLoading, OnMissing, TranslateContext, TranslateFunction, TranslateHandlers } from 'intor-translator';
3
+ export { FormatMessage, OnLoading, OnMissing, TranslateContext, TranslateHandlers } from 'intor-translator';
4
+ import { NextRequest } from 'next/server';
4
5
 
5
6
  type InitCookieOptions = {
6
7
  disabled?: boolean;
@@ -114,17 +115,14 @@ type IntorRuntimeResult = {
114
115
  type IntorOptions = {
115
116
  request?: unknown;
116
117
  config: IntorResolvedConfig;
117
- translateHandlers?: TranslateHandlers;
118
118
  };
119
- type IntorNextClientClientResult = IntorRuntimeResult;
120
- type IntorNextServerServerResult = Translator<unknown>;
121
- type IntorResult = IntorNextClientClientResult & IntorNextServerServerResult;
119
+ type IntorResult = IntorRuntimeResult;
122
120
 
123
121
  /**
124
122
  * Entry point for initializing Intor (the i18n system )
125
123
  * Determines runtime context and returns a translator or runtime object based on adapter
126
124
  */
127
- declare const intor: ({ request, config, translateHandlers, }: IntorOptions) => Promise<IntorResult>;
125
+ declare const intor: ({ request, config, }: IntorOptions) => Promise<IntorResult>;
128
126
 
129
127
  type IntorErrorOptions = {
130
128
  message: string;
@@ -294,4 +292,6 @@ type IntorAdapterRuntime = (options: {
294
292
  pathname: string;
295
293
  }>;
296
294
 
297
- export { type FetchApiMessagesOptions, type IntorAdapterRuntime, IntorError, IntorErrorCode, type IntorResolvedConfig, type LoaderOptions, type ResolvedCookieOptions, defineIntorConfig, extractPathname, fetchApiMessages, intor, loadLocalMessages, mergeStaticAndDynamicMessages, normalizeLocale, normalizePathname, resolveNamespaces, resolvePreferredLocale, standardizePathname };
295
+ declare const createIntor: <M = unknown>(config: IntorResolvedConfig, translateHandlers?: TranslateHandlers) => ((request: NextRequest) => Promise<Translator<M>>);
296
+
297
+ export { type FetchApiMessagesOptions, type IntorAdapterRuntime, IntorError, IntorErrorCode, type IntorResolvedConfig, type LoaderOptions, type ResolvedCookieOptions, createIntor, defineIntorConfig, extractPathname, fetchApiMessages, intor, loadLocalMessages, mergeStaticAndDynamicMessages, normalizeLocale, normalizePathname, resolveNamespaces, resolvePreferredLocale, standardizePathname };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Level, NormalizerConfig, FormatterConfig, LoggerPreset } from 'logry';
2
2
  import { Locale, LocaleNamespaceMessages, FallbackLocalesMap, TranslateHandlers, Translator } from 'intor-translator';
3
- export { FormatMessage, HasKeyFunction, OnLoading, OnMissing, TranslateContext, TranslateFunction, TranslateHandlers } from 'intor-translator';
3
+ export { FormatMessage, OnLoading, OnMissing, TranslateContext, TranslateHandlers } from 'intor-translator';
4
+ import { NextRequest } from 'next/server';
4
5
 
5
6
  type InitCookieOptions = {
6
7
  disabled?: boolean;
@@ -114,17 +115,14 @@ type IntorRuntimeResult = {
114
115
  type IntorOptions = {
115
116
  request?: unknown;
116
117
  config: IntorResolvedConfig;
117
- translateHandlers?: TranslateHandlers;
118
118
  };
119
- type IntorNextClientClientResult = IntorRuntimeResult;
120
- type IntorNextServerServerResult = Translator<unknown>;
121
- type IntorResult = IntorNextClientClientResult & IntorNextServerServerResult;
119
+ type IntorResult = IntorRuntimeResult;
122
120
 
123
121
  /**
124
122
  * Entry point for initializing Intor (the i18n system )
125
123
  * Determines runtime context and returns a translator or runtime object based on adapter
126
124
  */
127
- declare const intor: ({ request, config, translateHandlers, }: IntorOptions) => Promise<IntorResult>;
125
+ declare const intor: ({ request, config, }: IntorOptions) => Promise<IntorResult>;
128
126
 
129
127
  type IntorErrorOptions = {
130
128
  message: string;
@@ -294,4 +292,6 @@ type IntorAdapterRuntime = (options: {
294
292
  pathname: string;
295
293
  }>;
296
294
 
297
- export { type FetchApiMessagesOptions, type IntorAdapterRuntime, IntorError, IntorErrorCode, type IntorResolvedConfig, type LoaderOptions, type ResolvedCookieOptions, defineIntorConfig, extractPathname, fetchApiMessages, intor, loadLocalMessages, mergeStaticAndDynamicMessages, normalizeLocale, normalizePathname, resolveNamespaces, resolvePreferredLocale, standardizePathname };
295
+ declare const createIntor: <M = unknown>(config: IntorResolvedConfig, translateHandlers?: TranslateHandlers) => ((request: NextRequest) => Promise<Translator<M>>);
296
+
297
+ export { type FetchApiMessagesOptions, type IntorAdapterRuntime, IntorError, IntorErrorCode, type IntorResolvedConfig, type LoaderOptions, type ResolvedCookieOptions, createIntor, defineIntorConfig, extractPathname, fetchApiMessages, intor, loadLocalMessages, mergeStaticAndDynamicMessages, normalizeLocale, normalizePathname, resolveNamespaces, resolvePreferredLocale, standardizePathname };
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { logry } from 'logry';
2
- import { Translator } from 'intor-translator';
3
2
  import { cookies, headers } from 'next/headers';
4
3
  import path from 'path';
5
4
  import { performance } from 'perf_hooks';
6
5
  import pLimit from 'p-limit';
7
6
  import fs from 'fs/promises';
7
+ import { Translator } from 'intor-translator';
8
8
 
9
9
  var __defProp = Object.defineProperty;
10
10
  var __defProps = Object.defineProperties;
@@ -1103,27 +1103,16 @@ var intorRuntime = async ({
1103
1103
  // src/modules/intor/intor.ts
1104
1104
  var intor = async ({
1105
1105
  request,
1106
- config,
1107
- translateHandlers
1106
+ config
1108
1107
  }) => {
1109
- var _a, _b;
1110
1108
  const logger = logry({ id: config.id, scope: "intor" });
1111
1109
  logger.info("Starting Intor initialization:", {
1112
1110
  adapter: config.adapter
1113
1111
  });
1114
1112
  const runtime = await intorRuntime({ config, request });
1115
- const { initialLocale, messages } = runtime;
1116
1113
  switch (config.adapter) {
1117
1114
  case "next-server": {
1118
- const translator = new Translator({
1119
- locale: initialLocale,
1120
- messages,
1121
- fallbackLocales: config.fallbackLocales,
1122
- loadingMessage: (_a = config.translator) == null ? void 0 : _a.loadingMessage,
1123
- placeholder: (_b = config.translator) == null ? void 0 : _b.placeholder,
1124
- handlers: translateHandlers
1125
- });
1126
- return translator;
1115
+ return runtime;
1127
1116
  }
1128
1117
  case "next-client": {
1129
1118
  return runtime;
@@ -1138,5 +1127,20 @@ var intor = async ({
1138
1127
  }
1139
1128
  }
1140
1129
  };
1130
+ var createIntor = (config, translateHandlers) => {
1131
+ return async (request) => {
1132
+ var _a, _b;
1133
+ const { initialLocale, messages } = await intor({ config, request });
1134
+ const translator = new Translator({
1135
+ locale: initialLocale,
1136
+ messages,
1137
+ fallbackLocales: config.fallbackLocales,
1138
+ loadingMessage: (_a = config.translator) == null ? void 0 : _a.loadingMessage,
1139
+ placeholder: (_b = config.translator) == null ? void 0 : _b.placeholder,
1140
+ handlers: translateHandlers
1141
+ });
1142
+ return translator;
1143
+ };
1144
+ };
1141
1145
 
1142
- export { IntorError, IntorErrorCode, defineIntorConfig, extractPathname, fetchApiMessages, intor, loadLocalMessages, mergeStaticAndDynamicMessages, normalizeLocale, normalizePathname, resolveNamespaces, resolvePreferredLocale, standardizePathname };
1146
+ export { IntorError, IntorErrorCode, createIntor, defineIntorConfig, extractPathname, fetchApiMessages, intor, loadLocalMessages, mergeStaticAndDynamicMessages, normalizeLocale, normalizePathname, resolveNamespaces, resolvePreferredLocale, standardizePathname };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intor",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
4
4
  "description": "A modular and extensible i18n core designed for TypeScript and JavaScript projects. Intor enables custom translation logic with support for both frontend and backend environments, featuring runtime configuration, caching, adapters, and message loaders.",
5
5
  "author": "Yiming Liao",
6
6
  "license": "MIT",