@depup/next-intl 4.8.3-depup.0
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 +33 -0
- package/changes.json +18 -0
- package/config.d.ts +4 -0
- package/dist/cjs/development/ExtractorCodec-D9Tw618d.cjs +7 -0
- package/dist/cjs/development/JSONCodec-rhejs716.cjs +50 -0
- package/dist/cjs/development/POCodec-Cv3VdXQG.cjs +105 -0
- package/dist/cjs/development/plugin-YzBhQjAo.cjs +1457 -0
- package/dist/cjs/development/plugin.cjs +13 -0
- package/dist/esm/development/config.js +5 -0
- package/dist/esm/development/extractor/ExtractionCompiler.js +38 -0
- package/dist/esm/development/extractor/catalog/CatalogLocales.js +84 -0
- package/dist/esm/development/extractor/catalog/CatalogManager.js +370 -0
- package/dist/esm/development/extractor/catalog/CatalogPersister.js +63 -0
- package/dist/esm/development/extractor/catalog/SaveScheduler.js +85 -0
- package/dist/esm/development/extractor/catalogLoader.js +96 -0
- package/dist/esm/development/extractor/extractMessages.js +15 -0
- package/dist/esm/development/extractor/extractionLoader.js +26 -0
- package/dist/esm/development/extractor/extractor/LRUCache.js +30 -0
- package/dist/esm/development/extractor/extractor/MessageExtractor.js +66 -0
- package/dist/esm/development/extractor/format/ExtractorCodec.js +5 -0
- package/dist/esm/development/extractor/format/codecs/JSONCodec.js +42 -0
- package/dist/esm/development/extractor/format/codecs/POCodec.js +93 -0
- package/dist/esm/development/extractor/format/index.js +44 -0
- package/dist/esm/development/extractor/source/SourceFileFilter.js +29 -0
- package/dist/esm/development/extractor/source/SourceFileScanner.js +31 -0
- package/dist/esm/development/extractor/source/SourceFileWatcher.js +132 -0
- package/dist/esm/development/extractor/utils.js +46 -0
- package/dist/esm/development/extractor.js +2 -0
- package/dist/esm/development/index.react-client.js +4 -0
- package/dist/esm/development/index.react-server.js +9 -0
- package/dist/esm/development/middleware/getAlternateLinksHeaderValue.js +91 -0
- package/dist/esm/development/middleware/middleware.js +168 -0
- package/dist/esm/development/middleware/resolveLocale.js +129 -0
- package/dist/esm/development/middleware/syncCookie.js +27 -0
- package/dist/esm/development/middleware/utils.js +194 -0
- package/dist/esm/development/middleware.js +1 -0
- package/dist/esm/development/navigation/react-client/createNavigation.js +80 -0
- package/dist/esm/development/navigation/react-client/useBasePathname.js +36 -0
- package/dist/esm/development/navigation/react-server/createNavigation.js +22 -0
- package/dist/esm/development/navigation/react-server/getServerLocale.js +12 -0
- package/dist/esm/development/navigation/shared/BaseLink.js +51 -0
- package/dist/esm/development/navigation/shared/createSharedNavigationFns.js +105 -0
- package/dist/esm/development/navigation/shared/syncLocaleCookie.js +47 -0
- package/dist/esm/development/navigation/shared/utils.js +165 -0
- package/dist/esm/development/navigation.react-client.js +1 -0
- package/dist/esm/development/navigation.react-server.js +1 -0
- package/dist/esm/development/plugin/config.js +10 -0
- package/dist/esm/development/plugin/createNextIntlPlugin.js +26 -0
- package/dist/esm/development/plugin/declaration/createMessagesDeclaration.js +70 -0
- package/dist/esm/development/plugin/extractor/initExtractionCompiler.js +59 -0
- package/dist/esm/development/plugin/getNextConfig.js +267 -0
- package/dist/esm/development/plugin/nextFlags.js +32 -0
- package/dist/esm/development/plugin/utils.js +26 -0
- package/dist/esm/development/plugin/watchFile.js +21 -0
- package/dist/esm/development/plugin.js +1 -0
- package/dist/esm/development/react-client/index.js +34 -0
- package/dist/esm/development/react-server/NextIntlClientProviderServer.js +34 -0
- package/dist/esm/development/react-server/useConfig.js +21 -0
- package/dist/esm/development/react-server/useExtracted.js +9 -0
- package/dist/esm/development/react-server/useFormatter.js +9 -0
- package/dist/esm/development/react-server/useLocale.js +8 -0
- package/dist/esm/development/react-server/useMessages.js +9 -0
- package/dist/esm/development/react-server/useNow.js +12 -0
- package/dist/esm/development/react-server/useTimeZone.js +8 -0
- package/dist/esm/development/react-server/useTranslations.js +9 -0
- package/dist/esm/development/routing/config.js +26 -0
- package/dist/esm/development/routing/defineRouting.js +25 -0
- package/dist/esm/development/routing.js +1 -0
- package/dist/esm/development/server/react-client/index.js +32 -0
- package/dist/esm/development/server/react-server/RequestLocale.js +36 -0
- package/dist/esm/development/server/react-server/RequestLocaleCache.js +18 -0
- package/dist/esm/development/server/react-server/createRequestConfig.js +2 -0
- package/dist/esm/development/server/react-server/getConfig.js +59 -0
- package/dist/esm/development/server/react-server/getConfigNow.js +10 -0
- package/dist/esm/development/server/react-server/getDefaultNow.js +9 -0
- package/dist/esm/development/server/react-server/getExtracted.js +24 -0
- package/dist/esm/development/server/react-server/getFormats.js +10 -0
- package/dist/esm/development/server/react-server/getFormatter.js +21 -0
- package/dist/esm/development/server/react-server/getLocale.js +10 -0
- package/dist/esm/development/server/react-server/getMessages.js +19 -0
- package/dist/esm/development/server/react-server/getNow.js +8 -0
- package/dist/esm/development/server/react-server/getRequestConfig.js +8 -0
- package/dist/esm/development/server/react-server/getServerExtractor.js +38 -0
- package/dist/esm/development/server/react-server/getServerFormatter.js +17 -0
- package/dist/esm/development/server/react-server/getServerTranslator.js +12 -0
- package/dist/esm/development/server/react-server/getTimeZone.js +13 -0
- package/dist/esm/development/server/react-server/getTranslations.js +28 -0
- package/dist/esm/development/server/react-server/validateLocale.js +12 -0
- package/dist/esm/development/server.react-client.js +1 -0
- package/dist/esm/development/server.react-server.js +9 -0
- package/dist/esm/development/shared/NextIntlClientProvider.js +18 -0
- package/dist/esm/development/shared/constants.js +4 -0
- package/dist/esm/development/shared/use.js +13 -0
- package/dist/esm/development/shared/utils.js +140 -0
- package/dist/esm/production/config.js +1 -0
- package/dist/esm/production/extractor/ExtractionCompiler.js +1 -0
- package/dist/esm/production/extractor/catalog/CatalogLocales.js +1 -0
- package/dist/esm/production/extractor/catalog/CatalogManager.js +1 -0
- package/dist/esm/production/extractor/catalog/CatalogPersister.js +1 -0
- package/dist/esm/production/extractor/catalog/SaveScheduler.js +1 -0
- package/dist/esm/production/extractor/catalogLoader.js +1 -0
- package/dist/esm/production/extractor/extractMessages.js +1 -0
- package/dist/esm/production/extractor/extractionLoader.js +1 -0
- package/dist/esm/production/extractor/extractor/LRUCache.js +1 -0
- package/dist/esm/production/extractor/extractor/MessageExtractor.js +1 -0
- package/dist/esm/production/extractor/format/ExtractorCodec.js +1 -0
- package/dist/esm/production/extractor/format/codecs/JSONCodec.js +1 -0
- package/dist/esm/production/extractor/format/codecs/POCodec.js +1 -0
- package/dist/esm/production/extractor/format/index.js +1 -0
- package/dist/esm/production/extractor/source/SourceFileFilter.js +1 -0
- package/dist/esm/production/extractor/source/SourceFileScanner.js +1 -0
- package/dist/esm/production/extractor/source/SourceFileWatcher.js +1 -0
- package/dist/esm/production/extractor/utils.js +1 -0
- package/dist/esm/production/extractor.js +1 -0
- package/dist/esm/production/index.react-client.js +1 -0
- package/dist/esm/production/index.react-server.js +1 -0
- package/dist/esm/production/middleware/getAlternateLinksHeaderValue.js +1 -0
- package/dist/esm/production/middleware/middleware.js +1 -0
- package/dist/esm/production/middleware/resolveLocale.js +1 -0
- package/dist/esm/production/middleware/syncCookie.js +1 -0
- package/dist/esm/production/middleware/utils.js +1 -0
- package/dist/esm/production/middleware.js +1 -0
- package/dist/esm/production/navigation/react-client/createNavigation.js +1 -0
- package/dist/esm/production/navigation/react-client/useBasePathname.js +1 -0
- package/dist/esm/production/navigation/react-server/createNavigation.js +1 -0
- package/dist/esm/production/navigation/react-server/getServerLocale.js +1 -0
- package/dist/esm/production/navigation/shared/BaseLink.js +2 -0
- package/dist/esm/production/navigation/shared/createSharedNavigationFns.js +1 -0
- package/dist/esm/production/navigation/shared/syncLocaleCookie.js +1 -0
- package/dist/esm/production/navigation/shared/utils.js +1 -0
- package/dist/esm/production/navigation.react-client.js +1 -0
- package/dist/esm/production/navigation.react-server.js +1 -0
- package/dist/esm/production/plugin/config.js +1 -0
- package/dist/esm/production/plugin/createNextIntlPlugin.js +1 -0
- package/dist/esm/production/plugin/declaration/createMessagesDeclaration.js +1 -0
- package/dist/esm/production/plugin/extractor/initExtractionCompiler.js +1 -0
- package/dist/esm/production/plugin/getNextConfig.js +1 -0
- package/dist/esm/production/plugin/nextFlags.js +1 -0
- package/dist/esm/production/plugin/utils.js +1 -0
- package/dist/esm/production/plugin/watchFile.js +1 -0
- package/dist/esm/production/plugin.js +1 -0
- package/dist/esm/production/react-client/index.js +1 -0
- package/dist/esm/production/react-server/NextIntlClientProviderServer.js +1 -0
- package/dist/esm/production/react-server/useConfig.js +1 -0
- package/dist/esm/production/react-server/useExtracted.js +1 -0
- package/dist/esm/production/react-server/useFormatter.js +1 -0
- package/dist/esm/production/react-server/useLocale.js +1 -0
- package/dist/esm/production/react-server/useMessages.js +1 -0
- package/dist/esm/production/react-server/useNow.js +1 -0
- package/dist/esm/production/react-server/useTimeZone.js +1 -0
- package/dist/esm/production/react-server/useTranslations.js +1 -0
- package/dist/esm/production/routing/config.js +1 -0
- package/dist/esm/production/routing/defineRouting.js +1 -0
- package/dist/esm/production/routing.js +1 -0
- package/dist/esm/production/server/react-client/index.js +1 -0
- package/dist/esm/production/server/react-server/RequestLocale.js +1 -0
- package/dist/esm/production/server/react-server/RequestLocaleCache.js +1 -0
- package/dist/esm/production/server/react-server/createRequestConfig.js +1 -0
- package/dist/esm/production/server/react-server/getConfig.js +1 -0
- package/dist/esm/production/server/react-server/getConfigNow.js +1 -0
- package/dist/esm/production/server/react-server/getDefaultNow.js +1 -0
- package/dist/esm/production/server/react-server/getExtracted.js +1 -0
- package/dist/esm/production/server/react-server/getFormats.js +1 -0
- package/dist/esm/production/server/react-server/getFormatter.js +1 -0
- package/dist/esm/production/server/react-server/getLocale.js +1 -0
- package/dist/esm/production/server/react-server/getMessages.js +1 -0
- package/dist/esm/production/server/react-server/getNow.js +1 -0
- package/dist/esm/production/server/react-server/getRequestConfig.js +1 -0
- package/dist/esm/production/server/react-server/getServerExtractor.js +1 -0
- package/dist/esm/production/server/react-server/getServerFormatter.js +1 -0
- package/dist/esm/production/server/react-server/getServerTranslator.js +1 -0
- package/dist/esm/production/server/react-server/getTimeZone.js +1 -0
- package/dist/esm/production/server/react-server/getTranslations.js +1 -0
- package/dist/esm/production/server.react-client.js +1 -0
- package/dist/esm/production/server.react-server.js +1 -0
- package/dist/esm/production/shared/NextIntlClientProvider.js +2 -0
- package/dist/esm/production/shared/constants.js +1 -0
- package/dist/esm/production/shared/use.js +1 -0
- package/dist/esm/production/shared/utils.js +1 -0
- package/dist/types/config.d.ts +1 -0
- package/dist/types/extractor/ExtractionCompiler.d.ts +15 -0
- package/dist/types/extractor/catalog/CatalogLocales.d.ts +29 -0
- package/dist/types/extractor/catalog/CatalogManager.d.ts +59 -0
- package/dist/types/extractor/catalog/CatalogPersister.d.ts +20 -0
- package/dist/types/extractor/catalog/SaveScheduler.d.ts +18 -0
- package/dist/types/extractor/extractMessages.d.ts +2 -0
- package/dist/types/extractor/extractor/KeyGenerator.d.ts +3 -0
- package/dist/types/extractor/extractor/LRUCache.d.ts +7 -0
- package/dist/types/extractor/extractor/MessageExtractor.bench.d.ts +1 -0
- package/dist/types/extractor/extractor/MessageExtractor.d.ts +21 -0
- package/dist/types/extractor/format/ExtractorCodec.d.ts +33 -0
- package/dist/types/extractor/format/codecs/JSONCodec.d.ts +2 -0
- package/dist/types/extractor/format/codecs/POCodec.d.ts +2 -0
- package/dist/types/extractor/format/codecs/fixtures/JSONCodecStructured.d.ts +2 -0
- package/dist/types/extractor/format/codecs/fixtures/POCodecSourceMessageKey.d.ts +2 -0
- package/dist/types/extractor/format/index.d.ts +15 -0
- package/dist/types/extractor/format/types.d.ts +8 -0
- package/dist/types/extractor/index.d.ts +2 -0
- package/dist/types/extractor/source/SourceFileFilter.d.ts +8 -0
- package/dist/types/extractor/source/SourceFileScanner.d.ts +4 -0
- package/dist/types/extractor/source/SourceFileWatcher.d.ts +15 -0
- package/dist/types/extractor/types.d.ts +28 -0
- package/dist/types/extractor/utils.d.ts +7 -0
- package/dist/types/extractor.d.ts +1 -0
- package/dist/types/index.react-client.d.ts +8 -0
- package/dist/types/index.react-server.d.ts +1 -0
- package/dist/types/middleware/getAlternateLinksHeaderValue.d.ts +13 -0
- package/dist/types/middleware/index.d.ts +4 -0
- package/dist/types/middleware/middleware.d.ts +4 -0
- package/dist/types/middleware/resolveLocale.d.ts +9 -0
- package/dist/types/middleware/syncCookie.d.ts +7 -0
- package/dist/types/middleware/utils.d.ts +26 -0
- package/dist/types/middleware.d.ts +1 -0
- package/dist/types/navigation/react-client/createNavigation.d.ts +464 -0
- package/dist/types/navigation/react-client/index.d.ts +2 -0
- package/dist/types/navigation/react-client/useBasePathname.d.ts +5 -0
- package/dist/types/navigation/react-server/createNavigation.d.ts +384 -0
- package/dist/types/navigation/react-server/getServerLocale.d.ts +5 -0
- package/dist/types/navigation/react-server/index.d.ts +2 -0
- package/dist/types/navigation/shared/BaseLink.d.ts +11 -0
- package/dist/types/navigation/shared/StrictParams.d.ts +8 -0
- package/dist/types/navigation/shared/createSharedNavigationFns.d.ts +370 -0
- package/dist/types/navigation/shared/syncLocaleCookie.d.ts +8 -0
- package/dist/types/navigation/shared/utils.d.ts +53 -0
- package/dist/types/navigation.react-client.d.ts +1 -0
- package/dist/types/navigation.react-server.d.ts +1 -0
- package/dist/types/plugin/catalog/catalogLoader.d.ts +10 -0
- package/dist/types/plugin/config.d.ts +3 -0
- package/dist/types/plugin/createNextIntlPlugin.d.ts +3 -0
- package/dist/types/plugin/declaration/createMessagesDeclaration.d.ts +1 -0
- package/dist/types/plugin/declaration/index.d.ts +1 -0
- package/dist/types/plugin/extractor/extractionLoader.d.ts +3 -0
- package/dist/types/plugin/extractor/initExtractionCompiler.d.ts +2 -0
- package/dist/types/plugin/getNextConfig.d.ts +3 -0
- package/dist/types/plugin/index.d.ts +1 -0
- package/dist/types/plugin/nextFlags.d.ts +2 -0
- package/dist/types/plugin/types.d.ts +29 -0
- package/dist/types/plugin/utils.d.ts +8 -0
- package/dist/types/plugin/watchFile.d.ts +6 -0
- package/dist/types/plugin.d.ts +1 -0
- package/dist/types/react-client/index.d.ts +16 -0
- package/dist/types/react-server/NextIntlClientProviderServer.d.ts +5 -0
- package/dist/types/react-server/index.d.ts +16 -0
- package/dist/types/react-server/testUtils.d.ts +2 -0
- package/dist/types/react-server/useConfig.d.ts +2 -0
- package/dist/types/react-server/useExtracted.d.ts +2 -0
- package/dist/types/react-server/useFormatter.d.ts +2 -0
- package/dist/types/react-server/useLocale.d.ts +2 -0
- package/dist/types/react-server/useMessages.d.ts +2 -0
- package/dist/types/react-server/useNow.d.ts +2 -0
- package/dist/types/react-server/useTimeZone.d.ts +2 -0
- package/dist/types/react-server/useTranslations.d.ts +2 -0
- package/dist/types/routing/config.d.ts +73 -0
- package/dist/types/routing/defineRouting.d.ts +3 -0
- package/dist/types/routing/index.d.ts +3 -0
- package/dist/types/routing/types.d.ts +24 -0
- package/dist/types/routing.d.ts +1 -0
- package/dist/types/server/react-client/index.d.ts +10 -0
- package/dist/types/server/react-server/RequestLocale.d.ts +1 -0
- package/dist/types/server/react-server/RequestLocaleCache.d.ts +3 -0
- package/dist/types/server/react-server/createRequestConfig.d.ts +3 -0
- package/dist/types/server/react-server/getConfig.d.ts +13 -0
- package/dist/types/server/react-server/getConfigNow.d.ts +4 -0
- package/dist/types/server/react-server/getDefaultNow.d.ts +3 -0
- package/dist/types/server/react-server/getExtracted.d.ts +10 -0
- package/dist/types/server/react-server/getFormats.d.ts +3 -0
- package/dist/types/server/react-server/getFormatter.d.ts +10 -0
- package/dist/types/server/react-server/getLocale.d.ts +4 -0
- package/dist/types/server/react-server/getMessages.d.ts +6 -0
- package/dist/types/server/react-server/getNow.d.ts +4 -0
- package/dist/types/server/react-server/getRequestConfig.d.ts +35 -0
- package/dist/types/server/react-server/getServerExtractor.d.ts +5 -0
- package/dist/types/server/react-server/getServerFormatter.d.ts +25 -0
- package/dist/types/server/react-server/getServerTranslator.d.ts +4 -0
- package/dist/types/server/react-server/getTimeZone.d.ts +4 -0
- package/dist/types/server/react-server/getTranslations.d.ts +8 -0
- package/dist/types/server/react-server/index.d.ts +12 -0
- package/dist/types/server/react-server/validateLocale.d.ts +1 -0
- package/dist/types/server.react-client.d.ts +1 -0
- package/dist/types/server.react-server.d.ts +1 -0
- package/dist/types/shared/NextIntlClientProvider.d.ts +9 -0
- package/dist/types/shared/constants.d.ts +1 -0
- package/dist/types/shared/types.d.ts +5 -0
- package/dist/types/shared/use.d.ts +3 -0
- package/dist/types/shared/utils.d.ts +20 -0
- package/extractor/catalogLoader.d.ts +4 -0
- package/extractor/extractionLoader.d.ts +4 -0
- package/extractor.d.ts +2 -0
- package/middleware.d.ts +4 -0
- package/navigation.d.ts +2 -0
- package/package.json +175 -0
- package/plugin.d.cts +3 -0
- package/plugin.d.ts +4 -0
- package/routing.d.ts +2 -0
- package/server.d.ts +2 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import ExtractionCompiler from '../../extractor/ExtractionCompiler.js';
|
|
2
|
+
import { isDevelopment, isNextBuild } from '../config.js';
|
|
3
|
+
import { once } from '../utils.js';
|
|
4
|
+
|
|
5
|
+
// Single compiler instance, initialized once per process
|
|
6
|
+
let compiler;
|
|
7
|
+
const runOnce = once('_NEXT_INTL_EXTRACT');
|
|
8
|
+
function initExtractionCompiler(pluginConfig) {
|
|
9
|
+
const experimental = pluginConfig.experimental;
|
|
10
|
+
if (!experimental?.extract) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Avoid running for:
|
|
15
|
+
// - info
|
|
16
|
+
// - start
|
|
17
|
+
// - typegen
|
|
18
|
+
//
|
|
19
|
+
// Doesn't consult Next.js config anyway:
|
|
20
|
+
// - telemetry
|
|
21
|
+
// - lint
|
|
22
|
+
//
|
|
23
|
+
// What remains are:
|
|
24
|
+
// - dev (NODE_ENV=development)
|
|
25
|
+
// - build (NODE_ENV=production)
|
|
26
|
+
const shouldRun = isDevelopment || isNextBuild;
|
|
27
|
+
if (!shouldRun) return;
|
|
28
|
+
runOnce(() => {
|
|
29
|
+
const extractorConfig = {
|
|
30
|
+
srcPath: experimental.srcPath,
|
|
31
|
+
sourceLocale: experimental.extract.sourceLocale,
|
|
32
|
+
messages: experimental.messages
|
|
33
|
+
};
|
|
34
|
+
compiler = new ExtractionCompiler(extractorConfig, {
|
|
35
|
+
isDevelopment,
|
|
36
|
+
projectRoot: process.cwd()
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// Fire-and-forget: Start extraction, don't block config return.
|
|
40
|
+
// In dev mode, this also starts the file watcher.
|
|
41
|
+
// In prod, ideally we would wait until the extraction is complete,
|
|
42
|
+
// but we can't `await` anywhere (at least for Turbopack).
|
|
43
|
+
// The result is ok though, as if we encounter untranslated messages,
|
|
44
|
+
// we'll simply add empty messages to the catalog. So for actually
|
|
45
|
+
// running the app, there is no difference.
|
|
46
|
+
compiler.extractAll();
|
|
47
|
+
function cleanup() {
|
|
48
|
+
if (compiler) {
|
|
49
|
+
compiler[Symbol.dispose]();
|
|
50
|
+
compiler = undefined;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
process.on('exit', cleanup);
|
|
54
|
+
process.on('SIGINT', cleanup);
|
|
55
|
+
process.on('SIGTERM', cleanup);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export { initExtractionCompiler as default };
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import { createRequire } from 'module';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { getFormatExtension } from '../extractor/format/index.js';
|
|
5
|
+
import SourceFileFilter from '../extractor/source/SourceFileFilter.js';
|
|
6
|
+
import { isDevelopmentOrNextBuild } from './config.js';
|
|
7
|
+
import { isNextJs16OrHigher, hasStableTurboConfig } from './nextFlags.js';
|
|
8
|
+
import { throwError } from './utils.js';
|
|
9
|
+
|
|
10
|
+
const require$1 = createRequire(import.meta.url);
|
|
11
|
+
function withExtensions(localPath) {
|
|
12
|
+
return [`${localPath}.ts`, `${localPath}.tsx`, `${localPath}.js`, `${localPath}.jsx`];
|
|
13
|
+
}
|
|
14
|
+
function normalizeTurbopackAliasPath(pathname) {
|
|
15
|
+
// Turbopack alias targets should use forward slashes; Windows backslashes can
|
|
16
|
+
// break resolution in dev (see `next-intl/config` alias path style).
|
|
17
|
+
return pathname.replace(/\\/g, '/');
|
|
18
|
+
}
|
|
19
|
+
function resolveI18nPath(providedPath, cwd) {
|
|
20
|
+
function resolvePath(pathname) {
|
|
21
|
+
const parts = [];
|
|
22
|
+
if (cwd) parts.push(cwd);
|
|
23
|
+
parts.push(pathname);
|
|
24
|
+
return path.resolve(...parts);
|
|
25
|
+
}
|
|
26
|
+
function pathExists(pathname) {
|
|
27
|
+
return fs.existsSync(resolvePath(pathname));
|
|
28
|
+
}
|
|
29
|
+
if (providedPath) {
|
|
30
|
+
// We use the `isNextDevOrBuild` condition to avoid throwing errors
|
|
31
|
+
// if `next.config.ts` is read by a non-Next.js process.
|
|
32
|
+
// https://github.com/amannn/next-intl/discussions/2209#discussioncomment-15650927
|
|
33
|
+
if (isDevelopmentOrNextBuild && !pathExists(providedPath)) {
|
|
34
|
+
throwError(`Could not find i18n config at ${providedPath}, please provide a valid path.`);
|
|
35
|
+
}
|
|
36
|
+
return providedPath;
|
|
37
|
+
} else {
|
|
38
|
+
for (const candidate of [...withExtensions('./i18n/request'), ...withExtensions('./src/i18n/request')]) {
|
|
39
|
+
if (pathExists(candidate)) {
|
|
40
|
+
return candidate;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (isDevelopmentOrNextBuild) {
|
|
44
|
+
throwError(`Could not locate request configuration module.\n\nThis path is supported by default: ./(src/)i18n/request.{js,jsx,ts,tsx}\n\nAlternatively, you can specify a custom location in your Next.js config:\n\nconst withNextIntl = createNextIntlPlugin(\n './path/to/i18n/request.tsx'\n);`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Default as fallback
|
|
48
|
+
if (pathExists('./src')) {
|
|
49
|
+
return './src/i18n/request.ts';
|
|
50
|
+
} else {
|
|
51
|
+
return './i18n/request.ts';
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function getNextConfig(pluginConfig, nextConfig) {
|
|
56
|
+
const useTurbo = process.env.TURBOPACK != null;
|
|
57
|
+
|
|
58
|
+
// `experimental-analyze` doesn’t set the TURBOPACK env param. Since Next.js
|
|
59
|
+
// 16 doesn't print a warning when we configure both Turbo- and Webpack, just
|
|
60
|
+
// always configure Turbopack just in case.
|
|
61
|
+
const shouldConfigureTurbo = useTurbo || isNextJs16OrHigher();
|
|
62
|
+
const nextIntlConfig = {};
|
|
63
|
+
function getExtractMessagesLoaderConfig() {
|
|
64
|
+
const experimental = pluginConfig.experimental;
|
|
65
|
+
if (!experimental.srcPath || !pluginConfig.experimental?.messages) {
|
|
66
|
+
throwError('`srcPath` and `messages` are required when using `extractor`.');
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
loader: 'next-intl/extractor/extractionLoader',
|
|
70
|
+
options: {
|
|
71
|
+
srcPath: experimental.srcPath,
|
|
72
|
+
sourceLocale: experimental.extract.sourceLocale,
|
|
73
|
+
messages: pluginConfig.experimental.messages
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function getCatalogLoaderConfig() {
|
|
78
|
+
return {
|
|
79
|
+
loader: 'next-intl/extractor/catalogLoader',
|
|
80
|
+
options: {
|
|
81
|
+
messages: pluginConfig.experimental.messages
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function getTurboRules() {
|
|
86
|
+
return nextConfig?.turbopack?.rules ||
|
|
87
|
+
// @ts-expect-error -- For Next.js <16
|
|
88
|
+
nextConfig?.experimental?.turbo?.rules || {};
|
|
89
|
+
}
|
|
90
|
+
function addTurboRule(rules, glob, rule) {
|
|
91
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
92
|
+
if (rules[glob]) {
|
|
93
|
+
if (Array.isArray(rules[glob])) {
|
|
94
|
+
rules[glob].push(rule);
|
|
95
|
+
} else {
|
|
96
|
+
rules[glob] = [rules[glob], rule];
|
|
97
|
+
}
|
|
98
|
+
} else {
|
|
99
|
+
rules[glob] = rule;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Validate messages config
|
|
104
|
+
if (pluginConfig.experimental?.messages) {
|
|
105
|
+
const messages = pluginConfig.experimental.messages;
|
|
106
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- For non-TS consumers
|
|
107
|
+
if (!messages.format) {
|
|
108
|
+
throwError('`format` is required when using `messages`.');
|
|
109
|
+
}
|
|
110
|
+
if (!messages.path) {
|
|
111
|
+
throwError('`path` is required when using `messages`.');
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (shouldConfigureTurbo) {
|
|
115
|
+
if (pluginConfig.requestConfig && path.isAbsolute(pluginConfig.requestConfig)) {
|
|
116
|
+
throwError("Turbopack support for next-intl currently does not support absolute paths, please provide a relative one (e.g. './src/i18n/config.ts').\n\nFound: " + pluginConfig.requestConfig);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Assign alias for `next-intl/config`
|
|
120
|
+
const resolveAlias = {
|
|
121
|
+
// Turbo aliases don't work with absolute
|
|
122
|
+
// paths (see error handling above)
|
|
123
|
+
'next-intl/config': resolveI18nPath(pluginConfig.requestConfig)
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
// Add alias for precompiled message formatting
|
|
127
|
+
if (pluginConfig.experimental?.messages?.precompile) {
|
|
128
|
+
// Workaround for https://github.com/vercel/next.js/issues/88540
|
|
129
|
+
let formatOnlyPath = path.relative(process.cwd(), require$1.resolve('use-intl/format-message/format-only'));
|
|
130
|
+
|
|
131
|
+
// Turbopack seems to require this, otherwise `use-intl/format-message` is
|
|
132
|
+
// still bundled (despite the code correctly calling into `format-only`).
|
|
133
|
+
// Note that in this monorepo this is not necessary, because we'll end
|
|
134
|
+
// up with a path like `../…` — but for actual consumers this is required.
|
|
135
|
+
if (!formatOnlyPath.startsWith('.')) {
|
|
136
|
+
formatOnlyPath = `./${formatOnlyPath}`;
|
|
137
|
+
}
|
|
138
|
+
resolveAlias['use-intl/format-message'] = normalizeTurbopackAliasPath(formatOnlyPath);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Add loaders
|
|
142
|
+
let rules;
|
|
143
|
+
|
|
144
|
+
// Add loader for extractor
|
|
145
|
+
if (pluginConfig.experimental?.extract) {
|
|
146
|
+
if (!isNextJs16OrHigher()) {
|
|
147
|
+
throwError('Message extraction requires Next.js 16 or higher.');
|
|
148
|
+
}
|
|
149
|
+
rules ??= getTurboRules();
|
|
150
|
+
const srcPaths = (Array.isArray(pluginConfig.experimental.srcPath) ? pluginConfig.experimental.srcPath : [pluginConfig.experimental.srcPath]).map(srcPath => srcPath.endsWith('/') ? srcPath.slice(0, -1) : srcPath);
|
|
151
|
+
addTurboRule(rules, `*.{${SourceFileFilter.EXTENSIONS.join(',')}}`, {
|
|
152
|
+
loaders: [getExtractMessagesLoaderConfig()],
|
|
153
|
+
condition: {
|
|
154
|
+
// Note: We don't need `not: 'foreign'`, because this is
|
|
155
|
+
// implied by the filter based on `srcPath`.
|
|
156
|
+
path: `{${srcPaths.join(',')}}` + '/**/*',
|
|
157
|
+
content: /(useExtracted|getExtracted)/
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Add loader for catalog
|
|
163
|
+
if (pluginConfig.experimental?.messages) {
|
|
164
|
+
if (!isNextJs16OrHigher()) {
|
|
165
|
+
throwError('Message catalog loading requires Next.js 16 or higher.');
|
|
166
|
+
}
|
|
167
|
+
rules ??= getTurboRules();
|
|
168
|
+
const extension = getFormatExtension(pluginConfig.experimental.messages.format);
|
|
169
|
+
addTurboRule(rules, `*${extension}`, {
|
|
170
|
+
loaders: [getCatalogLoaderConfig()],
|
|
171
|
+
condition: {
|
|
172
|
+
path: `${pluginConfig.experimental.messages.path}/**/*`
|
|
173
|
+
},
|
|
174
|
+
as: '*.js'
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
if (hasStableTurboConfig() &&
|
|
178
|
+
// @ts-expect-error -- For Next.js <16
|
|
179
|
+
!nextConfig?.experimental?.turbo) {
|
|
180
|
+
nextIntlConfig.turbopack = {
|
|
181
|
+
...nextConfig?.turbopack,
|
|
182
|
+
...(rules && {
|
|
183
|
+
rules
|
|
184
|
+
}),
|
|
185
|
+
resolveAlias: {
|
|
186
|
+
...nextConfig?.turbopack?.resolveAlias,
|
|
187
|
+
...resolveAlias
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
} else {
|
|
191
|
+
nextIntlConfig.experimental = {
|
|
192
|
+
...nextConfig?.experimental,
|
|
193
|
+
// @ts-expect-error -- For Next.js <16
|
|
194
|
+
turbo: {
|
|
195
|
+
// @ts-expect-error -- For Next.js <16
|
|
196
|
+
...nextConfig?.experimental?.turbo,
|
|
197
|
+
...(rules && {
|
|
198
|
+
rules
|
|
199
|
+
}),
|
|
200
|
+
resolveAlias: {
|
|
201
|
+
// @ts-expect-error -- For Next.js <16
|
|
202
|
+
...nextConfig?.experimental?.turbo?.resolveAlias,
|
|
203
|
+
...resolveAlias
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
if (!useTurbo) {
|
|
210
|
+
nextIntlConfig.webpack = function webpack(config, context) {
|
|
211
|
+
if (!config.resolve) config.resolve = {};
|
|
212
|
+
if (!config.resolve.alias) config.resolve.alias = {};
|
|
213
|
+
|
|
214
|
+
// Assign alias for `next-intl/config`
|
|
215
|
+
// (Webpack requires absolute paths)
|
|
216
|
+
config.resolve.alias['next-intl/config'] = path.resolve(config.context, resolveI18nPath(pluginConfig.requestConfig, config.context));
|
|
217
|
+
|
|
218
|
+
// Add alias for precompiled message formatting
|
|
219
|
+
if (pluginConfig.experimental?.messages?.precompile) {
|
|
220
|
+
// Use require.resolve to get the actual file path, since
|
|
221
|
+
// bundlers don't properly resolve package subpath exports
|
|
222
|
+
// when used as alias targets
|
|
223
|
+
config.resolve.alias['use-intl/format-message'] = require$1.resolve('use-intl/format-message/format-only');
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// Add loader for extractor
|
|
227
|
+
if (pluginConfig.experimental?.extract) {
|
|
228
|
+
if (!config.module) config.module = {};
|
|
229
|
+
if (!config.module.rules) config.module.rules = [];
|
|
230
|
+
const srcPath = pluginConfig.experimental.srcPath;
|
|
231
|
+
config.module.rules.push({
|
|
232
|
+
test: new RegExp(`\\.(${SourceFileFilter.EXTENSIONS.join('|')})$`),
|
|
233
|
+
include: Array.isArray(srcPath) ? srcPath.map(cur => path.resolve(config.context, cur)) : path.resolve(config.context, srcPath || ''),
|
|
234
|
+
use: [getExtractMessagesLoaderConfig()]
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// Add loader for catalog
|
|
239
|
+
if (pluginConfig.experimental?.messages) {
|
|
240
|
+
if (!config.module) config.module = {};
|
|
241
|
+
if (!config.module.rules) config.module.rules = [];
|
|
242
|
+
const extension = getFormatExtension(pluginConfig.experimental.messages.format);
|
|
243
|
+
config.module.rules.push({
|
|
244
|
+
test: new RegExp(`${extension.replace(/\./g, '\\.')}$`),
|
|
245
|
+
include: path.resolve(config.context, pluginConfig.experimental.messages.path),
|
|
246
|
+
use: [getCatalogLoaderConfig()],
|
|
247
|
+
type: 'javascript/auto'
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
if (typeof nextConfig?.webpack === 'function') {
|
|
251
|
+
return nextConfig.webpack(config, context);
|
|
252
|
+
}
|
|
253
|
+
return config;
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// Forward config
|
|
258
|
+
if (nextConfig?.trailingSlash) {
|
|
259
|
+
nextIntlConfig.env = {
|
|
260
|
+
...nextConfig.env,
|
|
261
|
+
_next_intl_trailing_slash: 'true'
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
return Object.assign({}, nextConfig, nextIntlConfig);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export { getNextConfig as default };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { createRequire } from 'module';
|
|
2
|
+
|
|
3
|
+
function getCurrentVersion() {
|
|
4
|
+
try {
|
|
5
|
+
const require = createRequire(import.meta.url);
|
|
6
|
+
const pkg = require('next/package.json');
|
|
7
|
+
return pkg.version;
|
|
8
|
+
} catch (error) {
|
|
9
|
+
throw new Error('Failed to get current Next.js version. This can happen if next-intl/plugin is imported into your app code outside of your next.config.js.', {
|
|
10
|
+
cause: error
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function compareVersions(version1, version2) {
|
|
15
|
+
const v1Parts = version1.split('.').map(Number);
|
|
16
|
+
const v2Parts = version2.split('.').map(Number);
|
|
17
|
+
for (let i = 0; i < 3; i++) {
|
|
18
|
+
const v1 = v1Parts[i] || 0;
|
|
19
|
+
const v2 = v2Parts[i] || 0;
|
|
20
|
+
if (v1 > v2) return 1;
|
|
21
|
+
if (v1 < v2) return -1;
|
|
22
|
+
}
|
|
23
|
+
return 0;
|
|
24
|
+
}
|
|
25
|
+
function hasStableTurboConfig() {
|
|
26
|
+
return compareVersions(getCurrentVersion(), '15.3.0') >= 0;
|
|
27
|
+
}
|
|
28
|
+
function isNextJs16OrHigher() {
|
|
29
|
+
return compareVersions(getCurrentVersion(), '16.0.0') >= 0;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { hasStableTurboConfig, isNextJs16OrHigher };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
function formatMessage(message) {
|
|
2
|
+
return `\n[next-intl] ${message}\n`;
|
|
3
|
+
}
|
|
4
|
+
function throwError(message) {
|
|
5
|
+
throw new Error(formatMessage(message));
|
|
6
|
+
}
|
|
7
|
+
function warn(message) {
|
|
8
|
+
console.warn(formatMessage(message));
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Returns a function that runs the provided callback only once per process.
|
|
13
|
+
* Next.js can call the config multiple times - this ensures we only run once.
|
|
14
|
+
* Uses an environment variable to track execution across config loads.
|
|
15
|
+
*/
|
|
16
|
+
function once(namespace) {
|
|
17
|
+
return function runOnce(fn) {
|
|
18
|
+
if (process.env[namespace] === '1') {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
process.env[namespace] = '1';
|
|
22
|
+
fn();
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { once, throwError, warn };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Wrapper around `fs.watch` that provides a workaround
|
|
6
|
+
* for https://github.com/nodejs/node/issues/5039.
|
|
7
|
+
*/
|
|
8
|
+
function watchFile(filepath, callback) {
|
|
9
|
+
const directory = path.dirname(filepath);
|
|
10
|
+
const filename = path.basename(filepath);
|
|
11
|
+
return fs.watch(directory, {
|
|
12
|
+
persistent: false,
|
|
13
|
+
recursive: false
|
|
14
|
+
}, (event, changedFilename) => {
|
|
15
|
+
if (changedFilename === filename) {
|
|
16
|
+
callback();
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { watchFile as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './plugin/createNextIntlPlugin.js';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { useFormatter as useFormatter$1, useTranslations as useTranslations$1 } from 'use-intl';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This is the main entry file when non-'react-server'
|
|
5
|
+
* environments import from 'next-intl'.
|
|
6
|
+
*
|
|
7
|
+
* Maintainer notes:
|
|
8
|
+
* - Make sure this mirrors the API from 'react-server'.
|
|
9
|
+
* - Make sure everything exported from this module is
|
|
10
|
+
* supported in all Next.js versions that are supported.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
15
|
+
function callHook(name, hook) {
|
|
16
|
+
return (...args) => {
|
|
17
|
+
try {
|
|
18
|
+
return hook(...args);
|
|
19
|
+
} catch {
|
|
20
|
+
throw new Error(`Failed to call \`${name}\` because the context from \`NextIntlClientProvider\` was not found.
|
|
21
|
+
|
|
22
|
+
This can happen because:
|
|
23
|
+
1) You intended to render this component as a Server Component, the render
|
|
24
|
+
failed, and therefore React attempted to render the component on the client
|
|
25
|
+
instead. If this is the case, check the console for server errors.
|
|
26
|
+
2) You intended to render this component on the client side, but no context was found.
|
|
27
|
+
Learn more about this error here: https://next-intl.dev/docs/environments/server-client-components#missing-context` );
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
const useTranslations = callHook('useTranslations', useTranslations$1);
|
|
32
|
+
const useFormatter = callHook('useFormatter', useFormatter$1);
|
|
33
|
+
|
|
34
|
+
export { useFormatter, useTranslations };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import getConfigNow from '../server/react-server/getConfigNow.js';
|
|
2
|
+
import getFormats from '../server/react-server/getFormats.js';
|
|
3
|
+
import NextIntlClientProvider from '../shared/NextIntlClientProvider.js';
|
|
4
|
+
import { jsx } from 'react/jsx-runtime';
|
|
5
|
+
import getTimeZone from '../server/react-server/getTimeZone.js';
|
|
6
|
+
import getMessages from '../server/react-server/getMessages.js';
|
|
7
|
+
import getLocaleCached from '../server/react-server/getLocale.js';
|
|
8
|
+
|
|
9
|
+
async function NextIntlClientProviderServer({
|
|
10
|
+
formats,
|
|
11
|
+
locale,
|
|
12
|
+
messages,
|
|
13
|
+
now,
|
|
14
|
+
timeZone,
|
|
15
|
+
...rest
|
|
16
|
+
}) {
|
|
17
|
+
return /*#__PURE__*/jsx(NextIntlClientProvider
|
|
18
|
+
// We need to be careful about potentially reading from headers here.
|
|
19
|
+
// See https://github.com/amannn/next-intl/issues/631
|
|
20
|
+
, {
|
|
21
|
+
formats: formats === undefined ? await getFormats() : formats,
|
|
22
|
+
locale: locale ?? (await getLocaleCached()),
|
|
23
|
+
messages: messages === undefined ? await getMessages() : messages
|
|
24
|
+
// Note that we don't assign a default for `now` here,
|
|
25
|
+
// we only read one from the request config - if any.
|
|
26
|
+
// Otherwise this would cause a `dynamicIO` error.
|
|
27
|
+
,
|
|
28
|
+
now: now ?? (await getConfigNow()),
|
|
29
|
+
timeZone: timeZone ?? (await getTimeZone()),
|
|
30
|
+
...rest
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { NextIntlClientProviderServer as default };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import getConfig from '../server/react-server/getConfig.js';
|
|
2
|
+
import use from '../shared/use.js';
|
|
3
|
+
|
|
4
|
+
function useHook(hookName, promise) {
|
|
5
|
+
try {
|
|
6
|
+
return use(promise);
|
|
7
|
+
} catch (error) {
|
|
8
|
+
if (error instanceof TypeError && error.message.includes("Cannot read properties of null (reading 'use')")) {
|
|
9
|
+
throw new Error(`\`${hookName}\` is not callable within an async component. Please refer to https://next-intl.dev/docs/environments/server-client-components#async-components`, {
|
|
10
|
+
cause: error
|
|
11
|
+
});
|
|
12
|
+
} else {
|
|
13
|
+
throw error;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function useConfig(hookName) {
|
|
18
|
+
return useHook(hookName, getConfig());
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { useConfig as default };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import getServerExtractor from '../server/react-server/getServerExtractor.js';
|
|
2
|
+
import useConfig from './useConfig.js';
|
|
3
|
+
|
|
4
|
+
function useExtracted(namespace) {
|
|
5
|
+
const config = useConfig('useExtracted');
|
|
6
|
+
return getServerExtractor(config, namespace);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export { useExtracted as default };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import getFormatterCached from '../server/react-server/getServerFormatter.js';
|
|
2
|
+
import useConfig from './useConfig.js';
|
|
3
|
+
|
|
4
|
+
function useFormatter() {
|
|
5
|
+
const config = useConfig('useFormatter');
|
|
6
|
+
return getFormatterCached(config);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export { useFormatter as default };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { getMessagesFromConfig } from '../server/react-server/getMessages.js';
|
|
2
|
+
import useConfig from './useConfig.js';
|
|
3
|
+
|
|
4
|
+
function useMessages() {
|
|
5
|
+
const config = useConfig('useMessages');
|
|
6
|
+
return getMessagesFromConfig(config);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export { useMessages as default };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import getDefaultNow from '../server/react-server/getDefaultNow.js';
|
|
2
|
+
import useConfig from './useConfig.js';
|
|
3
|
+
|
|
4
|
+
function useNow(options) {
|
|
5
|
+
if (options?.updateInterval != null) {
|
|
6
|
+
console.error("`useNow` doesn't support the `updateInterval` option in Server Components, the value will be ignored. If you need the value to update, you can convert the component to a Client Component.");
|
|
7
|
+
}
|
|
8
|
+
const config = useConfig('useNow');
|
|
9
|
+
return config.now ?? getDefaultNow();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { useNow as default };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import getServerTranslator from '../server/react-server/getServerTranslator.js';
|
|
2
|
+
import useConfig from './useConfig.js';
|
|
3
|
+
|
|
4
|
+
function useTranslations(...[namespace]) {
|
|
5
|
+
const config = useConfig('useTranslations');
|
|
6
|
+
return getServerTranslator(config, namespace);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export { useTranslations as default };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
function receiveRoutingConfig(input) {
|
|
2
|
+
return {
|
|
3
|
+
...input,
|
|
4
|
+
localePrefix: receiveLocalePrefixConfig(input.localePrefix),
|
|
5
|
+
localeCookie: receiveLocaleCookie(input.localeCookie),
|
|
6
|
+
localeDetection: input.localeDetection ?? true,
|
|
7
|
+
alternateLinks: input.alternateLinks ?? true
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
function receiveLocaleCookie(localeCookie) {
|
|
11
|
+
return localeCookie ?? true ? {
|
|
12
|
+
name: 'NEXT_LOCALE',
|
|
13
|
+
sameSite: 'lax',
|
|
14
|
+
...(typeof localeCookie === 'object' && localeCookie)
|
|
15
|
+
|
|
16
|
+
// `path` needs to be provided based on a detected base path
|
|
17
|
+
// that depends on the environment when setting a cookie
|
|
18
|
+
} : false;
|
|
19
|
+
}
|
|
20
|
+
function receiveLocalePrefixConfig(localePrefix) {
|
|
21
|
+
return typeof localePrefix === 'object' ? localePrefix : {
|
|
22
|
+
mode: localePrefix || 'always'
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { receiveRoutingConfig };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
function defineRouting(config) {
|
|
2
|
+
if (config.domains) {
|
|
3
|
+
validateUniqueLocalesPerDomain(config.domains);
|
|
4
|
+
}
|
|
5
|
+
return config;
|
|
6
|
+
}
|
|
7
|
+
function validateUniqueLocalesPerDomain(domains) {
|
|
8
|
+
const domainsByLocale = new Map();
|
|
9
|
+
for (const {
|
|
10
|
+
domain,
|
|
11
|
+
locales
|
|
12
|
+
} of domains) {
|
|
13
|
+
for (const locale of locales) {
|
|
14
|
+
const localeDomains = domainsByLocale.get(locale) || new Set();
|
|
15
|
+
localeDomains.add(domain);
|
|
16
|
+
domainsByLocale.set(locale, localeDomains);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const duplicateLocaleMessages = Array.from(domainsByLocale.entries()).filter(([, localeDomains]) => localeDomains.size > 1).map(([locale, localeDomains]) => `- "${locale}" is used by: ${Array.from(localeDomains).join(', ')}`);
|
|
20
|
+
if (duplicateLocaleMessages.length > 0) {
|
|
21
|
+
console.warn('Locales are expected to be unique per domain, but found overlap:\n' + duplicateLocaleMessages.join('\n') + '\nPlease see https://next-intl.dev/docs/routing/configuration#domains');
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { defineRouting as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as defineRouting } from './routing/defineRouting.js';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Allows to import `next-intl/server` in non-RSC environments.
|
|
3
|
+
*
|
|
4
|
+
* This is mostly relevant for testing, since e.g. a `generateMetadata`
|
|
5
|
+
* export from a page might use `next-intl/server`, but the test
|
|
6
|
+
* only uses the default export for a page.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
function notSupported(message) {
|
|
10
|
+
return () => {
|
|
11
|
+
throw new Error(`\`${message}\` is not supported in Client Components.`);
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function getRequestConfig(
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
16
|
+
...args) {
|
|
17
|
+
return notSupported('getRequestConfig');
|
|
18
|
+
}
|
|
19
|
+
const getFormatter = notSupported('getFormatter');
|
|
20
|
+
const getNow = notSupported('getNow');
|
|
21
|
+
const getTimeZone = notSupported('getTimeZone');
|
|
22
|
+
const getMessages = notSupported('getMessages');
|
|
23
|
+
const getLocale = notSupported('getLocale');
|
|
24
|
+
const getExtracted = notSupported('getExtracted');
|
|
25
|
+
|
|
26
|
+
// The type of `getTranslations` is not assigned here because it
|
|
27
|
+
// causes a type error. The types use the `react-server` entry
|
|
28
|
+
// anyway, therefore this is irrelevant.
|
|
29
|
+
const getTranslations = notSupported('getTranslations');
|
|
30
|
+
const setRequestLocale = notSupported('setRequestLocale');
|
|
31
|
+
|
|
32
|
+
export { getExtracted, getFormatter, getLocale, getMessages, getNow, getRequestConfig, getTimeZone, getTranslations, setRequestLocale };
|