next-intl 2.14.0-beta.2 → 2.14.0-beta.4
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/LICENSE +21 -0
- package/README.md +3 -3
- package/dist/_virtual/next-intl.esm.js +1 -7
- package/dist/_virtual/next-intl.esm.js.map +1 -1
- package/dist/client/localizeHref.d.ts +2 -2
- package/dist/client/next-intl.esm.js +21 -32
- package/dist/client/next-intl.esm.js.map +1 -1
- package/dist/client/next-intl.esm2.js +14 -20
- package/dist/client/next-intl.esm2.js.map +1 -1
- package/dist/client/next-intl.esm3.js +18 -4
- package/dist/client/next-intl.esm3.js.map +1 -1
- package/dist/client/next-intl.esm4.js +4 -20
- package/dist/client/next-intl.esm4.js.map +1 -1
- package/dist/client/useClientLocale.d.ts +1 -0
- package/dist/client/usePathname.d.ts +1 -5
- package/dist/index.d.ts +3 -36
- package/dist/middleware/NextIntlMiddlewareConfig.d.ts +7 -7
- package/dist/next-intl.cjs.development.js +111 -125
- package/dist/next-intl.cjs.development.js.map +1 -1
- package/dist/next-intl.cjs.production.min.js +1 -1
- package/dist/next-intl.cjs.production.min.js.map +1 -1
- package/dist/next-intl.esm.js +3 -4
- package/dist/next-intl.esm.js.map +1 -1
- package/dist/react-client/Link.d.ts +16 -0
- package/dist/react-client/next-intl.esm.js +2 -3
- package/dist/react-client/next-intl.esm.js.map +1 -1
- package/dist/react-client/next-intl.esm2.js +26 -0
- package/dist/react-client/next-intl.esm2.js.map +1 -0
- package/dist/react-server/Link.d.ts +7 -0
- package/dist/react-server/index.d.ts +3 -34
- package/dist/server/getFormatter.d.ts +1 -1
- package/dist/server/getIntl.d.ts +1 -1
- package/dist/server/getRequestConfig.d.ts +3 -3
- package/dist/shared/BaseLink.d.ts +7 -0
- package/dist/shared/NextIntlClientProvider.d.ts +1 -1
- package/dist/shared/constants.d.ts +1 -0
- package/dist/shared/isLocalUrl.d.ts +5 -0
- package/dist/shared/next-intl.esm.js +36 -65
- package/dist/shared/next-intl.esm.js.map +1 -1
- package/dist/shared/next-intl.esm2.js +48 -41
- package/dist/shared/next-intl.esm2.js.map +1 -1
- package/dist/shared/next-intl.esm3.js +7 -8
- package/dist/shared/next-intl.esm3.js.map +1 -1
- package/dist/shared/next-intl.esm4.js +16 -4
- package/dist/shared/next-intl.esm4.js.map +1 -1
- package/dist/shared/next-intl.esm5.js +6 -0
- package/dist/shared/next-intl.esm5.js.map +1 -0
- package/dist/shared/next-intl.esm6.js +10 -0
- package/dist/shared/next-intl.esm6.js.map +1 -0
- package/dist/shared/prefixHref.d.ts +4 -0
- package/dist/shared/unlocalizePathname.d.ts +1 -0
- package/dist/src/client/localizeHref.d.ts +2 -2
- package/dist/src/client/localizeHref.js +8 -23
- package/dist/src/client/localizeHref.js.map +1 -1
- package/dist/src/client/useClientLocale.d.ts +1 -0
- package/dist/src/client/useClientLocale.js +16 -0
- package/dist/src/client/useClientLocale.js.map +1 -0
- package/dist/src/client/usePathname.d.ts +1 -5
- package/dist/src/client/usePathname.js +7 -26
- package/dist/src/client/usePathname.js.map +1 -1
- package/dist/src/client/useRouter.js +6 -4
- package/dist/src/client/useRouter.js.map +1 -1
- package/dist/src/index.d.ts +3 -36
- package/dist/src/index.js +2 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/middleware/NextIntlMiddlewareConfig.d.ts +7 -7
- package/dist/src/react-client/Link.d.ts +16 -0
- package/dist/src/react-client/Link.js +17 -0
- package/dist/src/react-client/Link.js.map +1 -0
- package/dist/src/react-server/Link.d.ts +7 -0
- package/dist/src/react-server/Link.js +8 -0
- package/dist/src/react-server/Link.js.map +1 -0
- package/dist/src/react-server/index.d.ts +3 -34
- package/dist/src/react-server/index.js +2 -3
- package/dist/src/react-server/index.js.map +1 -1
- package/dist/src/server/getFormatter.d.ts +1 -1
- package/dist/src/server/getIntl.d.ts +1 -1
- package/dist/src/server/getRequestConfig.d.ts +3 -3
- package/dist/src/server/getRequestConfig.js.map +1 -1
- package/dist/src/shared/BaseLink.d.ts +7 -0
- package/dist/src/shared/BaseLink.js +38 -0
- package/dist/src/shared/BaseLink.js.map +1 -0
- package/dist/src/shared/NextIntlClientProvider.d.ts +1 -1
- package/dist/src/shared/constants.d.ts +1 -0
- package/dist/src/shared/constants.js +2 -0
- package/dist/src/shared/constants.js.map +1 -1
- package/dist/src/shared/isLocalUrl.d.ts +5 -0
- package/dist/src/shared/isLocalUrl.js +10 -0
- package/dist/src/shared/isLocalUrl.js.map +1 -0
- package/dist/src/shared/prefixHref.d.ts +4 -0
- package/dist/src/shared/prefixHref.js +15 -0
- package/dist/src/shared/prefixHref.js.map +1 -0
- package/dist/src/shared/unlocalizePathname.d.ts +1 -0
- package/dist/src/shared/unlocalizePathname.js +4 -0
- package/dist/src/shared/unlocalizePathname.js.map +1 -0
- package/package.json +23 -22
- package/src/client/localizeHref.tsx +15 -24
- package/src/client/useClientLocale.tsx +17 -0
- package/src/client/usePathname.tsx +8 -32
- package/src/client/useRouter.tsx +6 -4
- package/src/index.tsx +2 -2
- package/src/react-client/Link.tsx +21 -0
- package/src/react-server/Link.tsx +12 -0
- package/src/react-server/index.tsx +2 -4
- package/src/server/getRequestConfig.tsx +3 -3
- package/src/shared/BaseLink.tsx +56 -0
- package/src/shared/constants.tsx +3 -0
- package/src/shared/isLocalUrl.tsx +13 -0
- package/src/shared/prefixHref.tsx +21 -0
- package/src/shared/unlocalizePathname.tsx +3 -0
- package/CHANGELOG.md +0 -562
- package/dist/client/getCookieLocale.d.ts +0 -1
- package/dist/shared/Link.d.ts +0 -7
- package/dist/shared/LocalizedLink.d.ts +0 -7
- package/dist/src/client/getCookieLocale.d.ts +0 -1
- package/dist/src/client/getCookieLocale.js +0 -17
- package/dist/src/client/getCookieLocale.js.map +0 -1
- package/dist/src/shared/Link.d.ts +0 -7
- package/dist/src/shared/Link.js +0 -45
- package/dist/src/shared/Link.js.map +0 -1
- package/dist/src/shared/LocalizedLink.d.ts +0 -7
- package/dist/src/shared/LocalizedLink.js +0 -18
- package/dist/src/shared/LocalizedLink.js.map +0 -1
- package/src/.DS_Store +0 -0
- package/src/client/getCookieLocale.tsx +0 -19
- package/src/shared/Link.tsx +0 -61
- package/src/shared/LocalizedLink.tsx +0 -26
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Jan Amann
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -9,13 +9,13 @@
|
|
|
9
9
|
<br>
|
|
10
10
|
</h1>
|
|
11
11
|
|
|
12
|
-
> Internationalization for Next.js that gets out of your way.
|
|
12
|
+
> Internationalization (i18n) for Next.js that gets out of your way.
|
|
13
13
|
|
|
14
14
|
  [<img src="https://img.shields.io/npm/dw/next-intl.svg" />](https://www.npmjs.com/package/next-intl)
|
|
15
15
|
|
|
16
16
|
<hr />
|
|
17
17
|
|
|
18
|
-
📣 [Support for Next.js 13 and the
|
|
18
|
+
📣 [Support for Next.js 13 and the App Router has arrived →](https://next-intl-docs.vercel.app/docs/next-13)
|
|
19
19
|
|
|
20
20
|
<hr />
|
|
21
21
|
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
Internationalization is an essential part of the user experience. next-intl gives you everything you need to get language subtleties right and has always got your back whenever you need to fine-tune a translation.
|
|
25
25
|
|
|
26
26
|
- 🌟 **ICU message syntax**: Localize your messages with interpolation, plurals, ordinal pluralization, enum-based label selection, and rich text.
|
|
27
|
-
- 📅 **Dates, times & numbers**:
|
|
27
|
+
- 📅 **Dates, times & numbers**: Apply appropriate formatting without worrying about server/client differences like time zones.
|
|
28
28
|
- ✅ **Type-safe**: Speed up development with autocompletion for message keys and catch typos early with compile-time checks.
|
|
29
29
|
- 💡 **Hooks-only API**: Learn a single API that can be used across your code base to turn translations into plain strings or rich text.
|
|
30
30
|
- 🚀 **Fast**: Get the best performance from your app by supporting internationalization on both static and dynamic pages.
|
|
@@ -1,33 +1,27 @@
|
|
|
1
1
|
function _extends() {
|
|
2
|
-
_extends = Object.assign
|
|
2
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
3
3
|
for (var i = 1; i < arguments.length; i++) {
|
|
4
4
|
var source = arguments[i];
|
|
5
|
-
|
|
6
5
|
for (var key in source) {
|
|
7
6
|
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
8
7
|
target[key] = source[key];
|
|
9
8
|
}
|
|
10
9
|
}
|
|
11
10
|
}
|
|
12
|
-
|
|
13
11
|
return target;
|
|
14
12
|
};
|
|
15
|
-
|
|
16
13
|
return _extends.apply(this, arguments);
|
|
17
14
|
}
|
|
18
|
-
|
|
19
15
|
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
20
16
|
if (source == null) return {};
|
|
21
17
|
var target = {};
|
|
22
18
|
var sourceKeys = Object.keys(source);
|
|
23
19
|
var key, i;
|
|
24
|
-
|
|
25
20
|
for (i = 0; i < sourceKeys.length; i++) {
|
|
26
21
|
key = sourceKeys[i];
|
|
27
22
|
if (excluded.indexOf(key) >= 0) continue;
|
|
28
23
|
target[key] = source[key];
|
|
29
24
|
}
|
|
30
|
-
|
|
31
25
|
return target;
|
|
32
26
|
}
|
|
33
27
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"next-intl.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"next-intl.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { UrlObject } from 'url';
|
|
3
|
-
export default function localizeHref(href: string, locale?: string, pathname?: string): string;
|
|
4
|
-
export default function localizeHref(href: UrlObject | string, locale?: string, pathname?: string): UrlObject | string;
|
|
3
|
+
export default function localizeHref(href: string, locale: string, defaultLocale?: string, pathname?: string): string;
|
|
4
|
+
export default function localizeHref(href: UrlObject | string, locale: string, defaultLocale?: string, pathname?: string): UrlObject | string;
|
|
@@ -1,37 +1,26 @@
|
|
|
1
1
|
import { extends as _extends } from '../_virtual/next-intl.esm.js';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (typeof href === 'string') {
|
|
21
|
-
prefixedHref = localizePathname(locale, href);
|
|
22
|
-
} else {
|
|
23
|
-
prefixedHref = _extends({}, href);
|
|
24
|
-
|
|
25
|
-
if (href.pathname) {
|
|
26
|
-
prefixedHref.pathname = localizePathname(locale, href.pathname);
|
|
2
|
+
import { useRouter as useRouter$1 } from 'next/navigation';
|
|
3
|
+
import { useMemo } from 'react';
|
|
4
|
+
import localizeHref from './next-intl.esm3.js';
|
|
5
|
+
import useClientLocale from './next-intl.esm2.js';
|
|
6
|
+
|
|
7
|
+
function useRouter() {
|
|
8
|
+
var router = useRouter$1();
|
|
9
|
+
var locale = useClientLocale();
|
|
10
|
+
return useMemo(function () {
|
|
11
|
+
return _extends({}, router, {
|
|
12
|
+
push: function push(href) {
|
|
13
|
+
return router.push(localizeHref(href, locale));
|
|
14
|
+
},
|
|
15
|
+
replace: function replace(href) {
|
|
16
|
+
return router.replace(localizeHref(href, locale));
|
|
17
|
+
},
|
|
18
|
+
prefetch: function prefetch(href) {
|
|
19
|
+
return router.prefetch(localizeHref(href, locale));
|
|
27
20
|
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return prefixedHref;
|
|
31
|
-
} else {
|
|
32
|
-
return href;
|
|
33
|
-
}
|
|
21
|
+
});
|
|
22
|
+
}, [locale, router]);
|
|
34
23
|
}
|
|
35
24
|
|
|
36
|
-
export {
|
|
25
|
+
export { useRouter as default };
|
|
37
26
|
//# sourceMappingURL=next-intl.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"next-intl.esm.js","sources":["../../src/client/
|
|
1
|
+
{"version":3,"file":"next-intl.esm.js","sources":["../../src/client/useRouter.tsx"],"sourcesContent":["import {useRouter as useNextRouter} from 'next/navigation';\nimport {useMemo} from 'react';\nimport localizeHref from './localizeHref';\nimport useClientLocale from './useClientLocale';\n\nexport default function useRouter() {\n const router = useNextRouter();\n const locale = useClientLocale();\n\n return useMemo(\n () => ({\n ...router,\n push(href: string) {\n return router.push(localizeHref(href, locale));\n },\n replace(href: string) {\n return router.replace(localizeHref(href, locale));\n },\n prefetch(href: string) {\n return router.prefetch(localizeHref(href, locale));\n }\n }),\n [locale, router]\n );\n}\n"],"names":["useRouter","router","useNextRouter","locale","useClientLocale","useMemo","_extends","push","href","localizeHref","replace","prefetch"],"mappings":";;;;;;AAKc,SAAUA,SAASA,GAAA;AAC/B,EAAA,IAAMC,MAAM,GAAGC,WAAa,EAAE,CAAA;AAC9B,EAAA,IAAMC,MAAM,GAAGC,eAAe,EAAE,CAAA;AAEhC,EAAA,OAAOC,OAAO,CACZ,YAAA;IAAA,OAAAC,QAAA,KACKL,MAAM,EAAA;MACTM,IAAI,EAAA,SAAAA,IAACC,CAAAA,IAAY,EAAA;QACf,OAAOP,MAAM,CAACM,IAAI,CAACE,YAAY,CAACD,IAAI,EAAEL,MAAM,CAAC,CAAC,CAAA;OAC/C;MACDO,OAAO,EAAA,SAAAA,OAACF,CAAAA,IAAY,EAAA;QAClB,OAAOP,MAAM,CAACS,OAAO,CAACD,YAAY,CAACD,IAAI,EAAEL,MAAM,CAAC,CAAC,CAAA;OAClD;MACDQ,QAAQ,EAAA,SAAAA,QAACH,CAAAA,IAAY,EAAA;QACnB,OAAOP,MAAM,CAACU,QAAQ,CAACF,YAAY,CAACD,IAAI,EAAEL,MAAM,CAAC,CAAC,CAAA;AACpD,OAAA;AAAC,KAAA,CAAA,CAAA;AAAA,GACD,EACF,CAACA,MAAM,EAAEF,MAAM,CAAC,CACjB,CAAA;AACH;;;;"}
|
|
@@ -1,24 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import localizeHref from './next-intl.esm.js';
|
|
1
|
+
import { useParams } from 'next/navigation';
|
|
2
|
+
import { useLocale } from 'use-intl';
|
|
3
|
+
import { LOCALE_SEGMENT_NAME } from '../shared/next-intl.esm5.js';
|
|
5
4
|
|
|
6
|
-
function
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
prefetch: function prefetch(href) {
|
|
17
|
-
return router.prefetch(localizeHref(href));
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
}, [router]);
|
|
5
|
+
function useClientLocale() {
|
|
6
|
+
var locale;
|
|
7
|
+
var params = useParams();
|
|
8
|
+
if (params[LOCALE_SEGMENT_NAME]) {
|
|
9
|
+
locale = params[LOCALE_SEGMENT_NAME];
|
|
10
|
+
} else {
|
|
11
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks -- Reading from context conditionally is fine
|
|
12
|
+
locale = useLocale();
|
|
13
|
+
}
|
|
14
|
+
return locale;
|
|
21
15
|
}
|
|
22
16
|
|
|
23
|
-
export {
|
|
17
|
+
export { useClientLocale as default };
|
|
24
18
|
//# sourceMappingURL=next-intl.esm2.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"next-intl.esm2.js","sources":["../../src/client/
|
|
1
|
+
{"version":3,"file":"next-intl.esm2.js","sources":["../../src/client/useClientLocale.tsx"],"sourcesContent":["import {useParams} from 'next/navigation';\nimport {useLocale} from 'use-intl';\nimport {LOCALE_SEGMENT_NAME} from '../shared/constants';\n\nexport default function useClientLocale(): string {\n let locale;\n\n const params = useParams();\n if (params[LOCALE_SEGMENT_NAME]) {\n locale = params[LOCALE_SEGMENT_NAME];\n } else {\n // eslint-disable-next-line react-hooks/rules-of-hooks -- Reading from context conditionally is fine\n locale = useLocale();\n }\n\n return locale;\n}\n"],"names":["useClientLocale","locale","params","useParams","LOCALE_SEGMENT_NAME","useLocale"],"mappings":";;;;AAIc,SAAUA,eAAeA,GAAA;AACrC,EAAA,IAAIC,MAAM,CAAA;AAEV,EAAA,IAAMC,MAAM,GAAGC,SAAS,EAAE,CAAA;AAC1B,EAAA,IAAID,MAAM,CAACE,mBAAmB,CAAC,EAAE;AAC/BH,IAAAA,MAAM,GAAGC,MAAM,CAACE,mBAAmB,CAAC,CAAA;AACrC,GAAA,MAAM;AACL;IACAH,MAAM,GAAGI,SAAS,EAAE,CAAA;AACrB,GAAA;AAED,EAAA,OAAOJ,MAAM,CAAA;AACf;;;;"}
|
|
@@ -1,7 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import prefixHref from '../shared/next-intl.esm4.js';
|
|
2
|
+
import hasPathnamePrefixed from './next-intl.esm4.js';
|
|
3
|
+
|
|
4
|
+
function localizeHref(href, locale, defaultLocale, pathname) {
|
|
5
|
+
if (defaultLocale === void 0) {
|
|
6
|
+
defaultLocale = locale;
|
|
7
|
+
}
|
|
8
|
+
if (!pathname) {
|
|
9
|
+
pathname = window.location.pathname;
|
|
10
|
+
}
|
|
11
|
+
var isSwitchingLocale = locale !== defaultLocale;
|
|
12
|
+
var isPathnamePrefixed = locale == null || hasPathnamePrefixed(locale, pathname);
|
|
13
|
+
var shouldPrefix = isPathnamePrefixed || isSwitchingLocale;
|
|
14
|
+
if (shouldPrefix && locale != null) {
|
|
15
|
+
return prefixHref(href, locale);
|
|
16
|
+
}
|
|
17
|
+
return href;
|
|
4
18
|
}
|
|
5
19
|
|
|
6
|
-
export {
|
|
20
|
+
export { localizeHref as default };
|
|
7
21
|
//# sourceMappingURL=next-intl.esm3.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"next-intl.esm3.js","sources":["../../src/client/
|
|
1
|
+
{"version":3,"file":"next-intl.esm3.js","sources":["../../src/client/localizeHref.tsx"],"sourcesContent":["import {UrlObject} from 'url';\nimport prefixHref from '../shared/prefixHref';\nimport hasPathnamePrefixed from './hasPathnamePrefixed';\n\nexport default function localizeHref(\n href: string,\n locale: string,\n defaultLocale?: string,\n pathname?: string\n): string;\nexport default function localizeHref(\n href: UrlObject | string,\n locale: string,\n defaultLocale?: string,\n pathname?: string\n): UrlObject | string;\nexport default function localizeHref(\n href: UrlObject | string,\n locale: string,\n defaultLocale: string = locale,\n pathname?: string\n) {\n if (!pathname) {\n pathname = window.location.pathname;\n }\n\n const isSwitchingLocale = locale !== defaultLocale;\n const isPathnamePrefixed =\n locale == null || hasPathnamePrefixed(locale, pathname);\n const shouldPrefix = isPathnamePrefixed || isSwitchingLocale;\n\n if (shouldPrefix && locale != null) {\n return prefixHref(href, locale);\n }\n\n return href;\n}\n"],"names":["localizeHref","href","locale","defaultLocale","pathname","window","location","isSwitchingLocale","isPathnamePrefixed","hasPathnamePrefixed","shouldPrefix","prefixHref"],"mappings":";;;AAgBwB,SAAAA,YAAYA,CAClCC,IAAwB,EACxBC,MAAc,EACdC,aAAA,EACAC,QAAiB,EAAA;AAAA,EAAA,IADjBD,aAAA,KAAA,KAAA,CAAA,EAAA;AAAAA,IAAAA,aAAA,GAAwBD,MAAM,CAAA;AAAA,GAAA;EAG9B,IAAI,CAACE,QAAQ,EAAE;AACbA,IAAAA,QAAQ,GAAGC,MAAM,CAACC,QAAQ,CAACF,QAAQ,CAAA;AACpC,GAAA;AAED,EAAA,IAAMG,iBAAiB,GAAGL,MAAM,KAAKC,aAAa,CAAA;EAClD,IAAMK,kBAAkB,GACtBN,MAAM,IAAI,IAAI,IAAIO,mBAAmB,CAACP,MAAM,EAAEE,QAAQ,CAAC,CAAA;AACzD,EAAA,IAAMM,YAAY,GAAGF,kBAAkB,IAAID,iBAAiB,CAAA;AAE5D,EAAA,IAAIG,YAAY,IAAIR,MAAM,IAAI,IAAI,EAAE;AAClC,IAAA,OAAOS,UAAU,CAACV,IAAI,EAAEC,MAAM,CAAC,CAAA;AAChC,GAAA;AAED,EAAA,OAAOD,IAAI,CAAA;AACb;;;;"}
|
|
@@ -1,23 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
// https://stackoverflow.com/a/15724300/343045
|
|
5
|
-
var value = "; " + document.cookie;
|
|
6
|
-
var parts = value.split("; " + name + "=");
|
|
7
|
-
|
|
8
|
-
if (parts.length === 2) {
|
|
9
|
-
var _parts$pop;
|
|
10
|
-
|
|
11
|
-
var part = (_parts$pop = parts.pop()) == null ? void 0 : _parts$pop.split(';').shift();
|
|
12
|
-
if (part) return part;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
throw new Error("Unable to find next-intl cookie, have you configured the middleware?");
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function getCookieLocale() {
|
|
19
|
-
return getCookieValueByName(COOKIE_LOCALE_NAME);
|
|
1
|
+
function hasPathnamePrefixed(locale, pathname) {
|
|
2
|
+
var prefix = "/" + locale;
|
|
3
|
+
return pathname === prefix || pathname.startsWith(prefix + "/") && pathname.length > prefix.length;
|
|
20
4
|
}
|
|
21
5
|
|
|
22
|
-
export {
|
|
6
|
+
export { hasPathnamePrefixed as default };
|
|
23
7
|
//# sourceMappingURL=next-intl.esm4.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"next-intl.esm4.js","sources":["../../src/client/
|
|
1
|
+
{"version":3,"file":"next-intl.esm4.js","sources":["../../src/client/hasPathnamePrefixed.tsx"],"sourcesContent":["export default function hasPathnamePrefixed(locale: string, pathname: string) {\n const prefix = `/${locale}`;\n return (\n pathname === prefix ||\n (pathname.startsWith(`${prefix}/`) && pathname.length > prefix.length)\n );\n}\n"],"names":["hasPathnamePrefixed","locale","pathname","prefix","startsWith","length"],"mappings":"AAAc,SAAUA,mBAAmBA,CAACC,MAAc,EAAEC,QAAgB,EAAA;EAC1E,IAAMC,MAAM,SAAOF,MAAQ,CAAA;AAC3B,EAAA,OACEC,QAAQ,KAAKC,MAAM,IAClBD,QAAQ,CAACE,UAAU,CAAID,MAAM,GAAG,GAAA,CAAC,IAAID,QAAQ,CAACG,MAAM,GAAGF,MAAM,CAACE,MAAO,CAAA;AAE1E;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function useClientLocale(): string;
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
export declare function unlocalizePathname(pathname: string): string;
|
|
2
1
|
/**
|
|
3
2
|
* Returns the pathname without a potential locale prefix.
|
|
4
3
|
*
|
|
5
4
|
* This can be helpful e.g. to implement navigation links,
|
|
6
5
|
* where the active link is highlighted.
|
|
7
|
-
*
|
|
8
|
-
* Note that on the server side `null` is returned, only on
|
|
9
|
-
* the client side the correct pathname will be returned.
|
|
10
6
|
*/
|
|
11
|
-
export default function usePathname(): string
|
|
7
|
+
export default function usePathname(): string;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,44 +2,11 @@
|
|
|
2
2
|
* This is the main entry file when non-'react-server' environments import
|
|
3
3
|
* from 'next-intl'. Make sure this mirrors the API from 'react-server'.
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
/// <reference types="node" />
|
|
5
|
+
import Link from './react-client/Link';
|
|
7
6
|
export * from 'use-intl';
|
|
8
7
|
export { default as useLocalizedRouter } from './react-client/useLocalizedRouter';
|
|
9
|
-
export { default as Link } from './
|
|
8
|
+
export { default as Link } from './react-client/Link';
|
|
10
9
|
/** @deprecated Is called `Link` now. */
|
|
11
|
-
export declare const LocalizedLink:
|
|
12
|
-
href: string | import("url").UrlObject;
|
|
13
|
-
/** @deprecated Is called `Link` now. */
|
|
14
|
-
as?: (string | import("url").UrlObject) | undefined;
|
|
15
|
-
replace?: boolean | undefined;
|
|
16
|
-
scroll?: boolean | undefined;
|
|
17
|
-
shallow?: boolean | undefined;
|
|
18
|
-
passHref?: boolean | undefined;
|
|
19
|
-
prefetch?: boolean | undefined;
|
|
20
|
-
locale?: string | false | undefined;
|
|
21
|
-
legacyBehavior?: boolean | undefined;
|
|
22
|
-
onMouseEnter?: import("react").MouseEventHandler<HTMLAnchorElement> | undefined;
|
|
23
|
-
onTouchStart?: import("react").TouchEventHandler<HTMLAnchorElement> | undefined;
|
|
24
|
-
onClick?: import("react").MouseEventHandler<HTMLAnchorElement> | undefined;
|
|
25
|
-
}> & {
|
|
26
|
-
href: string | import("url").UrlObject;
|
|
27
|
-
/** @deprecated Is called `Link` now. */
|
|
28
|
-
as?: (string | import("url").UrlObject) | undefined;
|
|
29
|
-
replace?: boolean | undefined;
|
|
30
|
-
scroll?: boolean | undefined;
|
|
31
|
-
shallow?: boolean | undefined;
|
|
32
|
-
passHref?: boolean | undefined;
|
|
33
|
-
prefetch?: boolean | undefined;
|
|
34
|
-
locale?: string | false | undefined;
|
|
35
|
-
legacyBehavior?: boolean | undefined;
|
|
36
|
-
onMouseEnter?: import("react").MouseEventHandler<HTMLAnchorElement> | undefined;
|
|
37
|
-
onTouchStart?: import("react").TouchEventHandler<HTMLAnchorElement> | undefined;
|
|
38
|
-
onClick?: import("react").MouseEventHandler<HTMLAnchorElement> | undefined;
|
|
39
|
-
} & {
|
|
40
|
-
children?: import("react").ReactNode;
|
|
41
|
-
} & import("react").RefAttributes<HTMLAnchorElement>, "locale"> & {
|
|
42
|
-
locale?: string | undefined;
|
|
43
|
-
}, "href" | "as" | "replace" | "scroll" | "shallow" | "passHref" | "prefetch" | "locale" | "legacyBehavior" | "onMouseEnter" | "onTouchStart" | "onClick" | "download" | "hrefLang" | "media" | "ping" | "rel" | "target" | "type" | "referrerPolicy" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "nonce" | "placeholder" | "slot" | "spellCheck" | "style" | "tabIndex" | "title" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "tw" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "children" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "key"> & import("react").RefAttributes<HTMLAnchorElement>>;
|
|
10
|
+
export declare const LocalizedLink: typeof Link;
|
|
44
11
|
export { default as NextIntlClientProvider } from './shared/NextIntlClientProvider';
|
|
45
12
|
export { default as NextIntlProvider } from './shared/NextIntlClientProvider';
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
type RoutingConfigPrefix = {
|
|
2
2
|
type: 'prefix';
|
|
3
3
|
/** The default locale can be used without a prefix (e.g. `/about`). If you prefer to have a prefix for the default locale as well (e.g. `/en/about`), you can switch this option to `always`.
|
|
4
4
|
*/
|
|
5
5
|
prefix?: 'as-needed' | 'always';
|
|
6
6
|
};
|
|
7
|
-
|
|
7
|
+
type RoutingConfigDomain = {
|
|
8
8
|
type: 'domain';
|
|
9
9
|
/** Provide a list of mappings between domains and locales. Note that the `x-forwarded-host` or alternatively the `host` header will be used to determine the requested domain. */
|
|
10
10
|
domains: Array<{
|
|
@@ -12,8 +12,8 @@ declare type RoutingConfigDomain = {
|
|
|
12
12
|
locale: string;
|
|
13
13
|
}>;
|
|
14
14
|
};
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
type LocalePrefix = 'as-needed' | 'always';
|
|
16
|
+
type RoutingBaseConfig = {
|
|
17
17
|
/** A list of all locales that are supported. */
|
|
18
18
|
locales: Array<string>;
|
|
19
19
|
defaultLocale: string;
|
|
@@ -21,14 +21,14 @@ declare type RoutingBaseConfig = {
|
|
|
21
21
|
*/
|
|
22
22
|
localePrefix?: LocalePrefix;
|
|
23
23
|
};
|
|
24
|
-
export
|
|
24
|
+
export type DomainConfig = Omit<RoutingBaseConfig, 'locales' | 'localePrefix'> & {
|
|
25
25
|
/** The domain name (e.g. "example.com", "www.example.com" or "fr.example.com"). Note that the `x-forwarded-host` or alternatively the `host` header will be used to determine the requested domain. */
|
|
26
26
|
domain: string;
|
|
27
27
|
locales?: RoutingBaseConfig['locales'];
|
|
28
28
|
/** @deprecated Use `defaultLocale` instead. */
|
|
29
29
|
locale?: string;
|
|
30
30
|
};
|
|
31
|
-
|
|
31
|
+
type MiddlewareConfig = RoutingBaseConfig & {
|
|
32
32
|
/** Can be used to change the locale handling per domain. */
|
|
33
33
|
domains?: Array<DomainConfig>;
|
|
34
34
|
/** By setting this to `false`, the `accept-language` header will no longer be used for locale detection. */
|
|
@@ -38,7 +38,7 @@ declare type MiddlewareConfig = RoutingBaseConfig & {
|
|
|
38
38
|
/** @deprecated Deprecated in favor of `localePrefix` and `domains`. */
|
|
39
39
|
routing?: RoutingConfigPrefix | RoutingConfigDomain;
|
|
40
40
|
};
|
|
41
|
-
export
|
|
41
|
+
export type MiddlewareConfigWithDefaults = MiddlewareConfig & {
|
|
42
42
|
alternateLinks: boolean;
|
|
43
43
|
localePrefix: LocalePrefix;
|
|
44
44
|
localeDetection: boolean;
|