intor 2.2.4 → 2.2.5
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.cjs +2 -0
- package/dist/config/index.js +2 -0
- package/dist/next/index.cjs +8 -4
- package/dist/next/index.d.cts +14 -3
- package/dist/next/index.d.ts +14 -3
- package/dist/next/index.js +8 -4
- package/package.json +5 -5
package/dist/config/index.cjs
CHANGED
|
@@ -123,6 +123,8 @@ var resolveRoutingOptions = (routing = {}) => {
|
|
|
123
123
|
|
|
124
124
|
// src/shared/error/intor-error.ts
|
|
125
125
|
var IntorError = class extends Error {
|
|
126
|
+
code;
|
|
127
|
+
id;
|
|
126
128
|
constructor({ message, code, id }) {
|
|
127
129
|
const fullMessage = id ? `[${id}] ${message}` : message;
|
|
128
130
|
super(fullMessage);
|
package/dist/config/index.js
CHANGED
|
@@ -121,6 +121,8 @@ var resolveRoutingOptions = (routing = {}) => {
|
|
|
121
121
|
|
|
122
122
|
// src/shared/error/intor-error.ts
|
|
123
123
|
var IntorError = class extends Error {
|
|
124
|
+
code;
|
|
125
|
+
id;
|
|
124
126
|
constructor({ message, code, id }) {
|
|
125
127
|
const fullMessage = id ? `[${id}] ${message}` : message;
|
|
126
128
|
super(fullMessage);
|
package/dist/next/index.cjs
CHANGED
|
@@ -805,12 +805,16 @@ var usePathname = () => {
|
|
|
805
805
|
const { config } = useConfig();
|
|
806
806
|
const { locale } = useLocale();
|
|
807
807
|
const rawPathname = navigation.usePathname();
|
|
808
|
-
const { localePrefixedPathname } = localizePathname({
|
|
808
|
+
const { localePrefixedPathname, standardizedPathname, unprefixedPathname } = localizePathname({
|
|
809
809
|
config,
|
|
810
810
|
pathname: rawPathname,
|
|
811
811
|
locale
|
|
812
812
|
});
|
|
813
|
-
return
|
|
813
|
+
return {
|
|
814
|
+
localizedPathname: localePrefixedPathname,
|
|
815
|
+
standardizedPathname,
|
|
816
|
+
unprefixedPathname
|
|
817
|
+
};
|
|
814
818
|
};
|
|
815
819
|
|
|
816
820
|
// src/adapters/next/navigation/utils/should-full-reload.ts
|
|
@@ -835,14 +839,14 @@ var shouldFullReload = ({
|
|
|
835
839
|
var useLocaleSwitch = () => {
|
|
836
840
|
const { config } = useConfig();
|
|
837
841
|
const { locale: currentLocale, setLocale } = useLocale();
|
|
838
|
-
const
|
|
842
|
+
const { localizedPathname } = usePathname();
|
|
839
843
|
const resolveHref = ({
|
|
840
844
|
href,
|
|
841
845
|
locale
|
|
842
846
|
}) => {
|
|
843
847
|
const isLocaleValid = locale && config.supportedLocales?.includes(locale);
|
|
844
848
|
const targetLocale = isLocaleValid ? locale : currentLocale;
|
|
845
|
-
const targetPathname = href ??
|
|
849
|
+
const targetPathname = href ?? localizedPathname;
|
|
846
850
|
const isExternal = targetPathname.startsWith("http");
|
|
847
851
|
const resolvedHref = !isExternal ? localizePathname({
|
|
848
852
|
config,
|
package/dist/next/index.d.cts
CHANGED
|
@@ -229,11 +229,22 @@ interface LinkProps extends Omit<LinkProps$1, "href">, Omit<React.AnchorHTMLAttr
|
|
|
229
229
|
declare const Link: ({ href, locale, children, onClick, ...props }: LinkProps) => React.JSX.Element;
|
|
230
230
|
|
|
231
231
|
/**
|
|
232
|
-
*
|
|
232
|
+
* Custom hook to get the current pathname in different forms based on the active locale.
|
|
233
233
|
*
|
|
234
|
-
*
|
|
234
|
+
* This hook wraps Next.js `usePathname` and processes the pathname according to the app's
|
|
235
|
+
* locale configuration.
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* const { localizedPathname, standardizedPathname, unprefixedPathname } = usePathname();
|
|
239
|
+
* console.log(localizedPathname); // e.g. "/en/about"
|
|
240
|
+
* console.log(standardizedPathname); // e.g. "/{locale}/about"
|
|
241
|
+
* console.log(unprefixedPathname); // e.g. "/about"
|
|
235
242
|
*/
|
|
236
|
-
declare const usePathname: () =>
|
|
243
|
+
declare const usePathname: () => {
|
|
244
|
+
localizedPathname: string;
|
|
245
|
+
standardizedPathname: string;
|
|
246
|
+
unprefixedPathname: string;
|
|
247
|
+
};
|
|
237
248
|
|
|
238
249
|
/**
|
|
239
250
|
* useRouter hook.
|
package/dist/next/index.d.ts
CHANGED
|
@@ -229,11 +229,22 @@ interface LinkProps extends Omit<LinkProps$1, "href">, Omit<React.AnchorHTMLAttr
|
|
|
229
229
|
declare const Link: ({ href, locale, children, onClick, ...props }: LinkProps) => React.JSX.Element;
|
|
230
230
|
|
|
231
231
|
/**
|
|
232
|
-
*
|
|
232
|
+
* Custom hook to get the current pathname in different forms based on the active locale.
|
|
233
233
|
*
|
|
234
|
-
*
|
|
234
|
+
* This hook wraps Next.js `usePathname` and processes the pathname according to the app's
|
|
235
|
+
* locale configuration.
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* const { localizedPathname, standardizedPathname, unprefixedPathname } = usePathname();
|
|
239
|
+
* console.log(localizedPathname); // e.g. "/en/about"
|
|
240
|
+
* console.log(standardizedPathname); // e.g. "/{locale}/about"
|
|
241
|
+
* console.log(unprefixedPathname); // e.g. "/about"
|
|
235
242
|
*/
|
|
236
|
-
declare const usePathname: () =>
|
|
243
|
+
declare const usePathname: () => {
|
|
244
|
+
localizedPathname: string;
|
|
245
|
+
standardizedPathname: string;
|
|
246
|
+
unprefixedPathname: string;
|
|
247
|
+
};
|
|
237
248
|
|
|
238
249
|
/**
|
|
239
250
|
* useRouter hook.
|
package/dist/next/index.js
CHANGED
|
@@ -778,12 +778,16 @@ var usePathname = () => {
|
|
|
778
778
|
const { config } = useConfig();
|
|
779
779
|
const { locale } = useLocale();
|
|
780
780
|
const rawPathname = usePathname$1();
|
|
781
|
-
const { localePrefixedPathname } = localizePathname({
|
|
781
|
+
const { localePrefixedPathname, standardizedPathname, unprefixedPathname } = localizePathname({
|
|
782
782
|
config,
|
|
783
783
|
pathname: rawPathname,
|
|
784
784
|
locale
|
|
785
785
|
});
|
|
786
|
-
return
|
|
786
|
+
return {
|
|
787
|
+
localizedPathname: localePrefixedPathname,
|
|
788
|
+
standardizedPathname,
|
|
789
|
+
unprefixedPathname
|
|
790
|
+
};
|
|
787
791
|
};
|
|
788
792
|
|
|
789
793
|
// src/adapters/next/navigation/utils/should-full-reload.ts
|
|
@@ -808,14 +812,14 @@ var shouldFullReload = ({
|
|
|
808
812
|
var useLocaleSwitch = () => {
|
|
809
813
|
const { config } = useConfig();
|
|
810
814
|
const { locale: currentLocale, setLocale } = useLocale();
|
|
811
|
-
const
|
|
815
|
+
const { localizedPathname } = usePathname();
|
|
812
816
|
const resolveHref = ({
|
|
813
817
|
href,
|
|
814
818
|
locale
|
|
815
819
|
}) => {
|
|
816
820
|
const isLocaleValid = locale && config.supportedLocales?.includes(locale);
|
|
817
821
|
const targetLocale = isLocaleValid ? locale : currentLocale;
|
|
818
|
-
const targetPathname = href ??
|
|
822
|
+
const targetPathname = href ?? localizedPathname;
|
|
819
823
|
const isExternal = targetPathname.startsWith("http");
|
|
820
824
|
const resolvedHref = !isExternal ? localizePathname({
|
|
821
825
|
config,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "intor",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.5",
|
|
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",
|
|
@@ -77,22 +77,22 @@
|
|
|
77
77
|
"p-limit": "^6.2.0"
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|
|
80
|
-
"@intor/cli": "
|
|
80
|
+
"@intor/cli": "^0.1.2",
|
|
81
81
|
"@types/lodash.merge": "^4.6.9",
|
|
82
82
|
"@types/node": "^24.10.1",
|
|
83
83
|
"@types/react": "^19.1.4",
|
|
84
84
|
"@types/react-dom": "^19.1.5",
|
|
85
85
|
"@vitest/coverage-v8": "4.0.9",
|
|
86
86
|
"eslint": "^9.27.0",
|
|
87
|
-
"eslint-config-prettier": "^10.1.
|
|
87
|
+
"eslint-config-prettier": "^10.1.8",
|
|
88
88
|
"eslint-import-resolver-typescript": "^4.4.4",
|
|
89
89
|
"eslint-plugin-import": "^2.31.0",
|
|
90
|
-
"eslint-plugin-prettier": "^5.4
|
|
90
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
91
91
|
"eslint-plugin-unicorn": "^62.0.0",
|
|
92
92
|
"eslint-plugin-unused-imports": "^4.1.4",
|
|
93
93
|
"knip": "^5.69.1",
|
|
94
94
|
"next": "16",
|
|
95
|
-
"prettier": "^3.
|
|
95
|
+
"prettier": "^3.6.2",
|
|
96
96
|
"react": "^19.1.0",
|
|
97
97
|
"react-dom": "^19.1.0",
|
|
98
98
|
"remark": "^15.0.1",
|