intor 2.2.7 → 2.2.9
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/config/index.d.cts +12 -8
- package/dist/config/index.d.ts +12 -8
- package/dist/index.d.cts +5 -7
- package/dist/index.d.ts +5 -7
- package/dist/next/index.d.cts +5 -7
- package/dist/next/index.d.ts +5 -7
- package/dist/next/middleware/index.d.cts +5 -7
- package/dist/next/middleware/index.d.ts +5 -7
- package/dist/next/server/index.d.cts +5 -7
- package/dist/next/server/index.d.ts +5 -7
- package/dist/react/index.cjs +17 -0
- package/dist/react/index.d.cts +17 -8
- package/dist/react/index.d.ts +17 -8
- package/dist/react/index.js +17 -1
- package/dist/server/index.d.cts +5 -7
- package/dist/server/index.d.ts +5 -7
- package/package.json +2 -1
package/dist/config/index.d.cts
CHANGED
|
@@ -99,15 +99,13 @@ type TranslatorOptions = {
|
|
|
99
99
|
placeholder?: string;
|
|
100
100
|
};
|
|
101
101
|
|
|
102
|
-
type
|
|
103
|
-
loader?: undefined;
|
|
104
|
-
supportedLocales?: readonly Locale[];
|
|
105
|
-
};
|
|
106
|
-
type WithLoader = {
|
|
102
|
+
type IntorRawConfig = ({
|
|
107
103
|
loader: LoaderOptions;
|
|
108
104
|
supportedLocales: readonly Locale[];
|
|
109
|
-
}
|
|
110
|
-
|
|
105
|
+
} | {
|
|
106
|
+
loader?: undefined;
|
|
107
|
+
supportedLocales?: readonly Locale[];
|
|
108
|
+
}) & {
|
|
111
109
|
readonly id?: string;
|
|
112
110
|
readonly messages?: LocaleMessages;
|
|
113
111
|
readonly defaultLocale: Locale;
|
|
@@ -118,7 +116,13 @@ type IntorRawConfig = (WithLoader | WithoutLoader) & {
|
|
|
118
116
|
readonly logger?: LoggerOptions;
|
|
119
117
|
readonly cache?: CacheRawOptions;
|
|
120
118
|
};
|
|
121
|
-
type IntorResolvedConfig = (
|
|
119
|
+
type IntorResolvedConfig = ({
|
|
120
|
+
loader: LoaderOptions;
|
|
121
|
+
supportedLocales: readonly Locale[];
|
|
122
|
+
} | {
|
|
123
|
+
loader?: undefined;
|
|
124
|
+
supportedLocales: readonly Locale[];
|
|
125
|
+
}) & {
|
|
122
126
|
readonly id: string;
|
|
123
127
|
readonly messages?: LocaleMessages;
|
|
124
128
|
readonly defaultLocale: Locale;
|
package/dist/config/index.d.ts
CHANGED
|
@@ -99,15 +99,13 @@ type TranslatorOptions = {
|
|
|
99
99
|
placeholder?: string;
|
|
100
100
|
};
|
|
101
101
|
|
|
102
|
-
type
|
|
103
|
-
loader?: undefined;
|
|
104
|
-
supportedLocales?: readonly Locale[];
|
|
105
|
-
};
|
|
106
|
-
type WithLoader = {
|
|
102
|
+
type IntorRawConfig = ({
|
|
107
103
|
loader: LoaderOptions;
|
|
108
104
|
supportedLocales: readonly Locale[];
|
|
109
|
-
}
|
|
110
|
-
|
|
105
|
+
} | {
|
|
106
|
+
loader?: undefined;
|
|
107
|
+
supportedLocales?: readonly Locale[];
|
|
108
|
+
}) & {
|
|
111
109
|
readonly id?: string;
|
|
112
110
|
readonly messages?: LocaleMessages;
|
|
113
111
|
readonly defaultLocale: Locale;
|
|
@@ -118,7 +116,13 @@ type IntorRawConfig = (WithLoader | WithoutLoader) & {
|
|
|
118
116
|
readonly logger?: LoggerOptions;
|
|
119
117
|
readonly cache?: CacheRawOptions;
|
|
120
118
|
};
|
|
121
|
-
type IntorResolvedConfig = (
|
|
119
|
+
type IntorResolvedConfig = ({
|
|
120
|
+
loader: LoaderOptions;
|
|
121
|
+
supportedLocales: readonly Locale[];
|
|
122
|
+
} | {
|
|
123
|
+
loader?: undefined;
|
|
124
|
+
supportedLocales: readonly Locale[];
|
|
125
|
+
}) & {
|
|
122
126
|
readonly id: string;
|
|
123
127
|
readonly messages?: LocaleMessages;
|
|
124
128
|
readonly defaultLocale: Locale;
|
package/dist/index.d.cts
CHANGED
|
@@ -111,15 +111,13 @@ type TranslatorOptions = {
|
|
|
111
111
|
placeholder?: string;
|
|
112
112
|
};
|
|
113
113
|
|
|
114
|
-
type
|
|
115
|
-
loader?: undefined;
|
|
116
|
-
supportedLocales?: readonly Locale[];
|
|
117
|
-
};
|
|
118
|
-
type WithLoader = {
|
|
114
|
+
type IntorResolvedConfig = ({
|
|
119
115
|
loader: LoaderOptions;
|
|
120
116
|
supportedLocales: readonly Locale[];
|
|
121
|
-
}
|
|
122
|
-
|
|
117
|
+
} | {
|
|
118
|
+
loader?: undefined;
|
|
119
|
+
supportedLocales: readonly Locale[];
|
|
120
|
+
}) & {
|
|
123
121
|
readonly id: string;
|
|
124
122
|
readonly messages?: LocaleMessages;
|
|
125
123
|
readonly defaultLocale: Locale;
|
package/dist/index.d.ts
CHANGED
|
@@ -111,15 +111,13 @@ type TranslatorOptions = {
|
|
|
111
111
|
placeholder?: string;
|
|
112
112
|
};
|
|
113
113
|
|
|
114
|
-
type
|
|
115
|
-
loader?: undefined;
|
|
116
|
-
supportedLocales?: readonly Locale[];
|
|
117
|
-
};
|
|
118
|
-
type WithLoader = {
|
|
114
|
+
type IntorResolvedConfig = ({
|
|
119
115
|
loader: LoaderOptions;
|
|
120
116
|
supportedLocales: readonly Locale[];
|
|
121
|
-
}
|
|
122
|
-
|
|
117
|
+
} | {
|
|
118
|
+
loader?: undefined;
|
|
119
|
+
supportedLocales: readonly Locale[];
|
|
120
|
+
}) & {
|
|
123
121
|
readonly id: string;
|
|
124
122
|
readonly messages?: LocaleMessages;
|
|
125
123
|
readonly defaultLocale: Locale;
|
package/dist/next/index.d.cts
CHANGED
|
@@ -185,15 +185,13 @@ type TranslatorOptions = {
|
|
|
185
185
|
placeholder?: string;
|
|
186
186
|
};
|
|
187
187
|
|
|
188
|
-
type
|
|
189
|
-
loader?: undefined;
|
|
190
|
-
supportedLocales?: readonly Locale[];
|
|
191
|
-
};
|
|
192
|
-
type WithLoader = {
|
|
188
|
+
type IntorResolvedConfig = ({
|
|
193
189
|
loader: LoaderOptions;
|
|
194
190
|
supportedLocales: readonly Locale[];
|
|
195
|
-
}
|
|
196
|
-
|
|
191
|
+
} | {
|
|
192
|
+
loader?: undefined;
|
|
193
|
+
supportedLocales: readonly Locale[];
|
|
194
|
+
}) & {
|
|
197
195
|
readonly id: string;
|
|
198
196
|
readonly messages?: LocaleMessages;
|
|
199
197
|
readonly defaultLocale: Locale;
|
package/dist/next/index.d.ts
CHANGED
|
@@ -185,15 +185,13 @@ type TranslatorOptions = {
|
|
|
185
185
|
placeholder?: string;
|
|
186
186
|
};
|
|
187
187
|
|
|
188
|
-
type
|
|
189
|
-
loader?: undefined;
|
|
190
|
-
supportedLocales?: readonly Locale[];
|
|
191
|
-
};
|
|
192
|
-
type WithLoader = {
|
|
188
|
+
type IntorResolvedConfig = ({
|
|
193
189
|
loader: LoaderOptions;
|
|
194
190
|
supportedLocales: readonly Locale[];
|
|
195
|
-
}
|
|
196
|
-
|
|
191
|
+
} | {
|
|
192
|
+
loader?: undefined;
|
|
193
|
+
supportedLocales: readonly Locale[];
|
|
194
|
+
}) & {
|
|
197
195
|
readonly id: string;
|
|
198
196
|
readonly messages?: LocaleMessages;
|
|
199
197
|
readonly defaultLocale: Locale;
|
|
@@ -100,15 +100,13 @@ type TranslatorOptions = {
|
|
|
100
100
|
placeholder?: string;
|
|
101
101
|
};
|
|
102
102
|
|
|
103
|
-
type
|
|
104
|
-
loader?: undefined;
|
|
105
|
-
supportedLocales?: readonly Locale[];
|
|
106
|
-
};
|
|
107
|
-
type WithLoader = {
|
|
103
|
+
type IntorResolvedConfig = ({
|
|
108
104
|
loader: LoaderOptions;
|
|
109
105
|
supportedLocales: readonly Locale[];
|
|
110
|
-
}
|
|
111
|
-
|
|
106
|
+
} | {
|
|
107
|
+
loader?: undefined;
|
|
108
|
+
supportedLocales: readonly Locale[];
|
|
109
|
+
}) & {
|
|
112
110
|
readonly id: string;
|
|
113
111
|
readonly messages?: LocaleMessages;
|
|
114
112
|
readonly defaultLocale: Locale;
|
|
@@ -100,15 +100,13 @@ type TranslatorOptions = {
|
|
|
100
100
|
placeholder?: string;
|
|
101
101
|
};
|
|
102
102
|
|
|
103
|
-
type
|
|
104
|
-
loader?: undefined;
|
|
105
|
-
supportedLocales?: readonly Locale[];
|
|
106
|
-
};
|
|
107
|
-
type WithLoader = {
|
|
103
|
+
type IntorResolvedConfig = ({
|
|
108
104
|
loader: LoaderOptions;
|
|
109
105
|
supportedLocales: readonly Locale[];
|
|
110
|
-
}
|
|
111
|
-
|
|
106
|
+
} | {
|
|
107
|
+
loader?: undefined;
|
|
108
|
+
supportedLocales: readonly Locale[];
|
|
109
|
+
}) & {
|
|
112
110
|
readonly id: string;
|
|
113
111
|
readonly messages?: LocaleMessages;
|
|
114
112
|
readonly defaultLocale: Locale;
|
|
@@ -101,15 +101,13 @@ type TranslatorOptions = {
|
|
|
101
101
|
placeholder?: string;
|
|
102
102
|
};
|
|
103
103
|
|
|
104
|
-
type
|
|
105
|
-
loader?: undefined;
|
|
106
|
-
supportedLocales?: readonly Locale[];
|
|
107
|
-
};
|
|
108
|
-
type WithLoader = {
|
|
104
|
+
type IntorResolvedConfig = ({
|
|
109
105
|
loader: LoaderOptions;
|
|
110
106
|
supportedLocales: readonly Locale[];
|
|
111
|
-
}
|
|
112
|
-
|
|
107
|
+
} | {
|
|
108
|
+
loader?: undefined;
|
|
109
|
+
supportedLocales: readonly Locale[];
|
|
110
|
+
}) & {
|
|
113
111
|
readonly id: string;
|
|
114
112
|
readonly messages?: LocaleMessages;
|
|
115
113
|
readonly defaultLocale: Locale;
|
|
@@ -101,15 +101,13 @@ type TranslatorOptions = {
|
|
|
101
101
|
placeholder?: string;
|
|
102
102
|
};
|
|
103
103
|
|
|
104
|
-
type
|
|
105
|
-
loader?: undefined;
|
|
106
|
-
supportedLocales?: readonly Locale[];
|
|
107
|
-
};
|
|
108
|
-
type WithLoader = {
|
|
104
|
+
type IntorResolvedConfig = ({
|
|
109
105
|
loader: LoaderOptions;
|
|
110
106
|
supportedLocales: readonly Locale[];
|
|
111
|
-
}
|
|
112
|
-
|
|
107
|
+
} | {
|
|
108
|
+
loader?: undefined;
|
|
109
|
+
supportedLocales: readonly Locale[];
|
|
110
|
+
}) & {
|
|
113
111
|
readonly id: string;
|
|
114
112
|
readonly messages?: LocaleMessages;
|
|
115
113
|
readonly defaultLocale: Locale;
|
package/dist/react/index.cjs
CHANGED
|
@@ -645,6 +645,23 @@ function useTranslator2(preKey) {
|
|
|
645
645
|
};
|
|
646
646
|
}
|
|
647
647
|
|
|
648
|
+
// src/client/shared/utils/get-initial-locale.ts
|
|
649
|
+
function getInitialLocale(config, cookieName = config.cookie.name) {
|
|
650
|
+
const { defaultLocale, supportedLocales } = config;
|
|
651
|
+
const match = document.cookie.match(
|
|
652
|
+
new RegExp(
|
|
653
|
+
`(?:^|; )${cookieName.replaceAll(/([.$?*|{}()[\]\\/+^])/g, String.raw`\$1`)}=([^;]*)`
|
|
654
|
+
)
|
|
655
|
+
);
|
|
656
|
+
const cookieLocale = match ? decodeURIComponent(match[1]) : null;
|
|
657
|
+
const browserLocale = navigator.languages?.[0] || navigator.language;
|
|
658
|
+
const locale = cookieLocale || browserLocale || defaultLocale;
|
|
659
|
+
const normalized = locale.toLowerCase();
|
|
660
|
+
const matched = supportedLocales.find((l) => l.toLowerCase() === normalized);
|
|
661
|
+
return matched ?? defaultLocale;
|
|
662
|
+
}
|
|
663
|
+
|
|
648
664
|
exports.IntorProvider = IntorProvider;
|
|
649
665
|
exports.TranslateHandlersProvider = TranslateHandlersProvider;
|
|
666
|
+
exports.getInitialLocale = getInitialLocale;
|
|
650
667
|
exports.useTranslator = useTranslator2;
|
package/dist/react/index.d.cts
CHANGED
|
@@ -101,15 +101,13 @@ type TranslatorOptions = {
|
|
|
101
101
|
placeholder?: string;
|
|
102
102
|
};
|
|
103
103
|
|
|
104
|
-
type
|
|
105
|
-
loader?: undefined;
|
|
106
|
-
supportedLocales?: readonly Locale[];
|
|
107
|
-
};
|
|
108
|
-
type WithLoader = {
|
|
104
|
+
type IntorResolvedConfig = ({
|
|
109
105
|
loader: LoaderOptions;
|
|
110
106
|
supportedLocales: readonly Locale[];
|
|
111
|
-
}
|
|
112
|
-
|
|
107
|
+
} | {
|
|
108
|
+
loader?: undefined;
|
|
109
|
+
supportedLocales: readonly Locale[];
|
|
110
|
+
}) & {
|
|
113
111
|
readonly id: string;
|
|
114
112
|
readonly messages?: LocaleMessages;
|
|
115
113
|
readonly defaultLocale: Locale;
|
|
@@ -210,4 +208,15 @@ type TranslatorInstance<M, PK extends string | undefined = undefined> = {
|
|
|
210
208
|
declare function useTranslator<CK extends GenConfigKeys = "__default__">(): TranslatorInstance<GenMessages<CK>>;
|
|
211
209
|
declare function useTranslator<CK extends GenConfigKeys = "__default__", PK extends string = LocalizedNodeKeys<GenMessages<CK>>>(preKey: IfGen<PK, string>): TranslatorInstance<GenMessages<CK>, PK>;
|
|
212
210
|
|
|
213
|
-
|
|
211
|
+
/**
|
|
212
|
+
* Get the initial locale from cookie, browser, or default.
|
|
213
|
+
*
|
|
214
|
+
* - This function is intended for client-side use only.
|
|
215
|
+
*
|
|
216
|
+
* @param {IntorResolvedConfig} config - The intor configuration.
|
|
217
|
+
* @param {string} [cookieName=config.cookie.name] - Optional cookie name to check.
|
|
218
|
+
* @returns {string} The matched locale or the default locale.
|
|
219
|
+
*/
|
|
220
|
+
declare function getInitialLocale(config: IntorResolvedConfig, cookieName?: string): string;
|
|
221
|
+
|
|
222
|
+
export { IntorProvider, type IntorProviderProps, TranslateHandlersProvider, type TranslateHandlersProviderProps, getInitialLocale, useTranslator };
|
package/dist/react/index.d.ts
CHANGED
|
@@ -101,15 +101,13 @@ type TranslatorOptions = {
|
|
|
101
101
|
placeholder?: string;
|
|
102
102
|
};
|
|
103
103
|
|
|
104
|
-
type
|
|
105
|
-
loader?: undefined;
|
|
106
|
-
supportedLocales?: readonly Locale[];
|
|
107
|
-
};
|
|
108
|
-
type WithLoader = {
|
|
104
|
+
type IntorResolvedConfig = ({
|
|
109
105
|
loader: LoaderOptions;
|
|
110
106
|
supportedLocales: readonly Locale[];
|
|
111
|
-
}
|
|
112
|
-
|
|
107
|
+
} | {
|
|
108
|
+
loader?: undefined;
|
|
109
|
+
supportedLocales: readonly Locale[];
|
|
110
|
+
}) & {
|
|
113
111
|
readonly id: string;
|
|
114
112
|
readonly messages?: LocaleMessages;
|
|
115
113
|
readonly defaultLocale: Locale;
|
|
@@ -210,4 +208,15 @@ type TranslatorInstance<M, PK extends string | undefined = undefined> = {
|
|
|
210
208
|
declare function useTranslator<CK extends GenConfigKeys = "__default__">(): TranslatorInstance<GenMessages<CK>>;
|
|
211
209
|
declare function useTranslator<CK extends GenConfigKeys = "__default__", PK extends string = LocalizedNodeKeys<GenMessages<CK>>>(preKey: IfGen<PK, string>): TranslatorInstance<GenMessages<CK>, PK>;
|
|
212
210
|
|
|
213
|
-
|
|
211
|
+
/**
|
|
212
|
+
* Get the initial locale from cookie, browser, or default.
|
|
213
|
+
*
|
|
214
|
+
* - This function is intended for client-side use only.
|
|
215
|
+
*
|
|
216
|
+
* @param {IntorResolvedConfig} config - The intor configuration.
|
|
217
|
+
* @param {string} [cookieName=config.cookie.name] - Optional cookie name to check.
|
|
218
|
+
* @returns {string} The matched locale or the default locale.
|
|
219
|
+
*/
|
|
220
|
+
declare function getInitialLocale(config: IntorResolvedConfig, cookieName?: string): string;
|
|
221
|
+
|
|
222
|
+
export { IntorProvider, type IntorProviderProps, TranslateHandlersProvider, type TranslateHandlersProviderProps, getInitialLocale, useTranslator };
|
package/dist/react/index.js
CHANGED
|
@@ -619,4 +619,20 @@ function useTranslator2(preKey) {
|
|
|
619
619
|
};
|
|
620
620
|
}
|
|
621
621
|
|
|
622
|
-
|
|
622
|
+
// src/client/shared/utils/get-initial-locale.ts
|
|
623
|
+
function getInitialLocale(config, cookieName = config.cookie.name) {
|
|
624
|
+
const { defaultLocale, supportedLocales } = config;
|
|
625
|
+
const match = document.cookie.match(
|
|
626
|
+
new RegExp(
|
|
627
|
+
`(?:^|; )${cookieName.replaceAll(/([.$?*|{}()[\]\\/+^])/g, String.raw`\$1`)}=([^;]*)`
|
|
628
|
+
)
|
|
629
|
+
);
|
|
630
|
+
const cookieLocale = match ? decodeURIComponent(match[1]) : null;
|
|
631
|
+
const browserLocale = navigator.languages?.[0] || navigator.language;
|
|
632
|
+
const locale = cookieLocale || browserLocale || defaultLocale;
|
|
633
|
+
const normalized = locale.toLowerCase();
|
|
634
|
+
const matched = supportedLocales.find((l) => l.toLowerCase() === normalized);
|
|
635
|
+
return matched ?? defaultLocale;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
export { IntorProvider, TranslateHandlersProvider, getInitialLocale, useTranslator2 as useTranslator };
|
package/dist/server/index.d.cts
CHANGED
|
@@ -101,15 +101,13 @@ type TranslatorOptions = {
|
|
|
101
101
|
placeholder?: string;
|
|
102
102
|
};
|
|
103
103
|
|
|
104
|
-
type
|
|
105
|
-
loader?: undefined;
|
|
106
|
-
supportedLocales?: readonly Locale[];
|
|
107
|
-
};
|
|
108
|
-
type WithLoader = {
|
|
104
|
+
type IntorResolvedConfig = ({
|
|
109
105
|
loader: LoaderOptions;
|
|
110
106
|
supportedLocales: readonly Locale[];
|
|
111
|
-
}
|
|
112
|
-
|
|
107
|
+
} | {
|
|
108
|
+
loader?: undefined;
|
|
109
|
+
supportedLocales: readonly Locale[];
|
|
110
|
+
}) & {
|
|
113
111
|
readonly id: string;
|
|
114
112
|
readonly messages?: LocaleMessages;
|
|
115
113
|
readonly defaultLocale: Locale;
|
package/dist/server/index.d.ts
CHANGED
|
@@ -101,15 +101,13 @@ type TranslatorOptions = {
|
|
|
101
101
|
placeholder?: string;
|
|
102
102
|
};
|
|
103
103
|
|
|
104
|
-
type
|
|
105
|
-
loader?: undefined;
|
|
106
|
-
supportedLocales?: readonly Locale[];
|
|
107
|
-
};
|
|
108
|
-
type WithLoader = {
|
|
104
|
+
type IntorResolvedConfig = ({
|
|
109
105
|
loader: LoaderOptions;
|
|
110
106
|
supportedLocales: readonly Locale[];
|
|
111
|
-
}
|
|
112
|
-
|
|
107
|
+
} | {
|
|
108
|
+
loader?: undefined;
|
|
109
|
+
supportedLocales: readonly Locale[];
|
|
110
|
+
}) & {
|
|
113
111
|
readonly id: string;
|
|
114
112
|
readonly messages?: LocaleMessages;
|
|
115
113
|
readonly defaultLocale: Locale;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "intor",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.9",
|
|
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",
|
|
@@ -100,6 +100,7 @@
|
|
|
100
100
|
"eslint-plugin-prettier": "^5.5.4",
|
|
101
101
|
"eslint-plugin-unicorn": "^62.0.0",
|
|
102
102
|
"eslint-plugin-unused-imports": "^4.1.4",
|
|
103
|
+
"jsdom": "^27.2.0",
|
|
103
104
|
"knip": "^5.69.1",
|
|
104
105
|
"next": "^16.0.3",
|
|
105
106
|
"prettier": "^3.6.2",
|