@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.
Files changed (296) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +33 -0
  3. package/changes.json +18 -0
  4. package/config.d.ts +4 -0
  5. package/dist/cjs/development/ExtractorCodec-D9Tw618d.cjs +7 -0
  6. package/dist/cjs/development/JSONCodec-rhejs716.cjs +50 -0
  7. package/dist/cjs/development/POCodec-Cv3VdXQG.cjs +105 -0
  8. package/dist/cjs/development/plugin-YzBhQjAo.cjs +1457 -0
  9. package/dist/cjs/development/plugin.cjs +13 -0
  10. package/dist/esm/development/config.js +5 -0
  11. package/dist/esm/development/extractor/ExtractionCompiler.js +38 -0
  12. package/dist/esm/development/extractor/catalog/CatalogLocales.js +84 -0
  13. package/dist/esm/development/extractor/catalog/CatalogManager.js +370 -0
  14. package/dist/esm/development/extractor/catalog/CatalogPersister.js +63 -0
  15. package/dist/esm/development/extractor/catalog/SaveScheduler.js +85 -0
  16. package/dist/esm/development/extractor/catalogLoader.js +96 -0
  17. package/dist/esm/development/extractor/extractMessages.js +15 -0
  18. package/dist/esm/development/extractor/extractionLoader.js +26 -0
  19. package/dist/esm/development/extractor/extractor/LRUCache.js +30 -0
  20. package/dist/esm/development/extractor/extractor/MessageExtractor.js +66 -0
  21. package/dist/esm/development/extractor/format/ExtractorCodec.js +5 -0
  22. package/dist/esm/development/extractor/format/codecs/JSONCodec.js +42 -0
  23. package/dist/esm/development/extractor/format/codecs/POCodec.js +93 -0
  24. package/dist/esm/development/extractor/format/index.js +44 -0
  25. package/dist/esm/development/extractor/source/SourceFileFilter.js +29 -0
  26. package/dist/esm/development/extractor/source/SourceFileScanner.js +31 -0
  27. package/dist/esm/development/extractor/source/SourceFileWatcher.js +132 -0
  28. package/dist/esm/development/extractor/utils.js +46 -0
  29. package/dist/esm/development/extractor.js +2 -0
  30. package/dist/esm/development/index.react-client.js +4 -0
  31. package/dist/esm/development/index.react-server.js +9 -0
  32. package/dist/esm/development/middleware/getAlternateLinksHeaderValue.js +91 -0
  33. package/dist/esm/development/middleware/middleware.js +168 -0
  34. package/dist/esm/development/middleware/resolveLocale.js +129 -0
  35. package/dist/esm/development/middleware/syncCookie.js +27 -0
  36. package/dist/esm/development/middleware/utils.js +194 -0
  37. package/dist/esm/development/middleware.js +1 -0
  38. package/dist/esm/development/navigation/react-client/createNavigation.js +80 -0
  39. package/dist/esm/development/navigation/react-client/useBasePathname.js +36 -0
  40. package/dist/esm/development/navigation/react-server/createNavigation.js +22 -0
  41. package/dist/esm/development/navigation/react-server/getServerLocale.js +12 -0
  42. package/dist/esm/development/navigation/shared/BaseLink.js +51 -0
  43. package/dist/esm/development/navigation/shared/createSharedNavigationFns.js +105 -0
  44. package/dist/esm/development/navigation/shared/syncLocaleCookie.js +47 -0
  45. package/dist/esm/development/navigation/shared/utils.js +165 -0
  46. package/dist/esm/development/navigation.react-client.js +1 -0
  47. package/dist/esm/development/navigation.react-server.js +1 -0
  48. package/dist/esm/development/plugin/config.js +10 -0
  49. package/dist/esm/development/plugin/createNextIntlPlugin.js +26 -0
  50. package/dist/esm/development/plugin/declaration/createMessagesDeclaration.js +70 -0
  51. package/dist/esm/development/plugin/extractor/initExtractionCompiler.js +59 -0
  52. package/dist/esm/development/plugin/getNextConfig.js +267 -0
  53. package/dist/esm/development/plugin/nextFlags.js +32 -0
  54. package/dist/esm/development/plugin/utils.js +26 -0
  55. package/dist/esm/development/plugin/watchFile.js +21 -0
  56. package/dist/esm/development/plugin.js +1 -0
  57. package/dist/esm/development/react-client/index.js +34 -0
  58. package/dist/esm/development/react-server/NextIntlClientProviderServer.js +34 -0
  59. package/dist/esm/development/react-server/useConfig.js +21 -0
  60. package/dist/esm/development/react-server/useExtracted.js +9 -0
  61. package/dist/esm/development/react-server/useFormatter.js +9 -0
  62. package/dist/esm/development/react-server/useLocale.js +8 -0
  63. package/dist/esm/development/react-server/useMessages.js +9 -0
  64. package/dist/esm/development/react-server/useNow.js +12 -0
  65. package/dist/esm/development/react-server/useTimeZone.js +8 -0
  66. package/dist/esm/development/react-server/useTranslations.js +9 -0
  67. package/dist/esm/development/routing/config.js +26 -0
  68. package/dist/esm/development/routing/defineRouting.js +25 -0
  69. package/dist/esm/development/routing.js +1 -0
  70. package/dist/esm/development/server/react-client/index.js +32 -0
  71. package/dist/esm/development/server/react-server/RequestLocale.js +36 -0
  72. package/dist/esm/development/server/react-server/RequestLocaleCache.js +18 -0
  73. package/dist/esm/development/server/react-server/createRequestConfig.js +2 -0
  74. package/dist/esm/development/server/react-server/getConfig.js +59 -0
  75. package/dist/esm/development/server/react-server/getConfigNow.js +10 -0
  76. package/dist/esm/development/server/react-server/getDefaultNow.js +9 -0
  77. package/dist/esm/development/server/react-server/getExtracted.js +24 -0
  78. package/dist/esm/development/server/react-server/getFormats.js +10 -0
  79. package/dist/esm/development/server/react-server/getFormatter.js +21 -0
  80. package/dist/esm/development/server/react-server/getLocale.js +10 -0
  81. package/dist/esm/development/server/react-server/getMessages.js +19 -0
  82. package/dist/esm/development/server/react-server/getNow.js +8 -0
  83. package/dist/esm/development/server/react-server/getRequestConfig.js +8 -0
  84. package/dist/esm/development/server/react-server/getServerExtractor.js +38 -0
  85. package/dist/esm/development/server/react-server/getServerFormatter.js +17 -0
  86. package/dist/esm/development/server/react-server/getServerTranslator.js +12 -0
  87. package/dist/esm/development/server/react-server/getTimeZone.js +13 -0
  88. package/dist/esm/development/server/react-server/getTranslations.js +28 -0
  89. package/dist/esm/development/server/react-server/validateLocale.js +12 -0
  90. package/dist/esm/development/server.react-client.js +1 -0
  91. package/dist/esm/development/server.react-server.js +9 -0
  92. package/dist/esm/development/shared/NextIntlClientProvider.js +18 -0
  93. package/dist/esm/development/shared/constants.js +4 -0
  94. package/dist/esm/development/shared/use.js +13 -0
  95. package/dist/esm/development/shared/utils.js +140 -0
  96. package/dist/esm/production/config.js +1 -0
  97. package/dist/esm/production/extractor/ExtractionCompiler.js +1 -0
  98. package/dist/esm/production/extractor/catalog/CatalogLocales.js +1 -0
  99. package/dist/esm/production/extractor/catalog/CatalogManager.js +1 -0
  100. package/dist/esm/production/extractor/catalog/CatalogPersister.js +1 -0
  101. package/dist/esm/production/extractor/catalog/SaveScheduler.js +1 -0
  102. package/dist/esm/production/extractor/catalogLoader.js +1 -0
  103. package/dist/esm/production/extractor/extractMessages.js +1 -0
  104. package/dist/esm/production/extractor/extractionLoader.js +1 -0
  105. package/dist/esm/production/extractor/extractor/LRUCache.js +1 -0
  106. package/dist/esm/production/extractor/extractor/MessageExtractor.js +1 -0
  107. package/dist/esm/production/extractor/format/ExtractorCodec.js +1 -0
  108. package/dist/esm/production/extractor/format/codecs/JSONCodec.js +1 -0
  109. package/dist/esm/production/extractor/format/codecs/POCodec.js +1 -0
  110. package/dist/esm/production/extractor/format/index.js +1 -0
  111. package/dist/esm/production/extractor/source/SourceFileFilter.js +1 -0
  112. package/dist/esm/production/extractor/source/SourceFileScanner.js +1 -0
  113. package/dist/esm/production/extractor/source/SourceFileWatcher.js +1 -0
  114. package/dist/esm/production/extractor/utils.js +1 -0
  115. package/dist/esm/production/extractor.js +1 -0
  116. package/dist/esm/production/index.react-client.js +1 -0
  117. package/dist/esm/production/index.react-server.js +1 -0
  118. package/dist/esm/production/middleware/getAlternateLinksHeaderValue.js +1 -0
  119. package/dist/esm/production/middleware/middleware.js +1 -0
  120. package/dist/esm/production/middleware/resolveLocale.js +1 -0
  121. package/dist/esm/production/middleware/syncCookie.js +1 -0
  122. package/dist/esm/production/middleware/utils.js +1 -0
  123. package/dist/esm/production/middleware.js +1 -0
  124. package/dist/esm/production/navigation/react-client/createNavigation.js +1 -0
  125. package/dist/esm/production/navigation/react-client/useBasePathname.js +1 -0
  126. package/dist/esm/production/navigation/react-server/createNavigation.js +1 -0
  127. package/dist/esm/production/navigation/react-server/getServerLocale.js +1 -0
  128. package/dist/esm/production/navigation/shared/BaseLink.js +2 -0
  129. package/dist/esm/production/navigation/shared/createSharedNavigationFns.js +1 -0
  130. package/dist/esm/production/navigation/shared/syncLocaleCookie.js +1 -0
  131. package/dist/esm/production/navigation/shared/utils.js +1 -0
  132. package/dist/esm/production/navigation.react-client.js +1 -0
  133. package/dist/esm/production/navigation.react-server.js +1 -0
  134. package/dist/esm/production/plugin/config.js +1 -0
  135. package/dist/esm/production/plugin/createNextIntlPlugin.js +1 -0
  136. package/dist/esm/production/plugin/declaration/createMessagesDeclaration.js +1 -0
  137. package/dist/esm/production/plugin/extractor/initExtractionCompiler.js +1 -0
  138. package/dist/esm/production/plugin/getNextConfig.js +1 -0
  139. package/dist/esm/production/plugin/nextFlags.js +1 -0
  140. package/dist/esm/production/plugin/utils.js +1 -0
  141. package/dist/esm/production/plugin/watchFile.js +1 -0
  142. package/dist/esm/production/plugin.js +1 -0
  143. package/dist/esm/production/react-client/index.js +1 -0
  144. package/dist/esm/production/react-server/NextIntlClientProviderServer.js +1 -0
  145. package/dist/esm/production/react-server/useConfig.js +1 -0
  146. package/dist/esm/production/react-server/useExtracted.js +1 -0
  147. package/dist/esm/production/react-server/useFormatter.js +1 -0
  148. package/dist/esm/production/react-server/useLocale.js +1 -0
  149. package/dist/esm/production/react-server/useMessages.js +1 -0
  150. package/dist/esm/production/react-server/useNow.js +1 -0
  151. package/dist/esm/production/react-server/useTimeZone.js +1 -0
  152. package/dist/esm/production/react-server/useTranslations.js +1 -0
  153. package/dist/esm/production/routing/config.js +1 -0
  154. package/dist/esm/production/routing/defineRouting.js +1 -0
  155. package/dist/esm/production/routing.js +1 -0
  156. package/dist/esm/production/server/react-client/index.js +1 -0
  157. package/dist/esm/production/server/react-server/RequestLocale.js +1 -0
  158. package/dist/esm/production/server/react-server/RequestLocaleCache.js +1 -0
  159. package/dist/esm/production/server/react-server/createRequestConfig.js +1 -0
  160. package/dist/esm/production/server/react-server/getConfig.js +1 -0
  161. package/dist/esm/production/server/react-server/getConfigNow.js +1 -0
  162. package/dist/esm/production/server/react-server/getDefaultNow.js +1 -0
  163. package/dist/esm/production/server/react-server/getExtracted.js +1 -0
  164. package/dist/esm/production/server/react-server/getFormats.js +1 -0
  165. package/dist/esm/production/server/react-server/getFormatter.js +1 -0
  166. package/dist/esm/production/server/react-server/getLocale.js +1 -0
  167. package/dist/esm/production/server/react-server/getMessages.js +1 -0
  168. package/dist/esm/production/server/react-server/getNow.js +1 -0
  169. package/dist/esm/production/server/react-server/getRequestConfig.js +1 -0
  170. package/dist/esm/production/server/react-server/getServerExtractor.js +1 -0
  171. package/dist/esm/production/server/react-server/getServerFormatter.js +1 -0
  172. package/dist/esm/production/server/react-server/getServerTranslator.js +1 -0
  173. package/dist/esm/production/server/react-server/getTimeZone.js +1 -0
  174. package/dist/esm/production/server/react-server/getTranslations.js +1 -0
  175. package/dist/esm/production/server.react-client.js +1 -0
  176. package/dist/esm/production/server.react-server.js +1 -0
  177. package/dist/esm/production/shared/NextIntlClientProvider.js +2 -0
  178. package/dist/esm/production/shared/constants.js +1 -0
  179. package/dist/esm/production/shared/use.js +1 -0
  180. package/dist/esm/production/shared/utils.js +1 -0
  181. package/dist/types/config.d.ts +1 -0
  182. package/dist/types/extractor/ExtractionCompiler.d.ts +15 -0
  183. package/dist/types/extractor/catalog/CatalogLocales.d.ts +29 -0
  184. package/dist/types/extractor/catalog/CatalogManager.d.ts +59 -0
  185. package/dist/types/extractor/catalog/CatalogPersister.d.ts +20 -0
  186. package/dist/types/extractor/catalog/SaveScheduler.d.ts +18 -0
  187. package/dist/types/extractor/extractMessages.d.ts +2 -0
  188. package/dist/types/extractor/extractor/KeyGenerator.d.ts +3 -0
  189. package/dist/types/extractor/extractor/LRUCache.d.ts +7 -0
  190. package/dist/types/extractor/extractor/MessageExtractor.bench.d.ts +1 -0
  191. package/dist/types/extractor/extractor/MessageExtractor.d.ts +21 -0
  192. package/dist/types/extractor/format/ExtractorCodec.d.ts +33 -0
  193. package/dist/types/extractor/format/codecs/JSONCodec.d.ts +2 -0
  194. package/dist/types/extractor/format/codecs/POCodec.d.ts +2 -0
  195. package/dist/types/extractor/format/codecs/fixtures/JSONCodecStructured.d.ts +2 -0
  196. package/dist/types/extractor/format/codecs/fixtures/POCodecSourceMessageKey.d.ts +2 -0
  197. package/dist/types/extractor/format/index.d.ts +15 -0
  198. package/dist/types/extractor/format/types.d.ts +8 -0
  199. package/dist/types/extractor/index.d.ts +2 -0
  200. package/dist/types/extractor/source/SourceFileFilter.d.ts +8 -0
  201. package/dist/types/extractor/source/SourceFileScanner.d.ts +4 -0
  202. package/dist/types/extractor/source/SourceFileWatcher.d.ts +15 -0
  203. package/dist/types/extractor/types.d.ts +28 -0
  204. package/dist/types/extractor/utils.d.ts +7 -0
  205. package/dist/types/extractor.d.ts +1 -0
  206. package/dist/types/index.react-client.d.ts +8 -0
  207. package/dist/types/index.react-server.d.ts +1 -0
  208. package/dist/types/middleware/getAlternateLinksHeaderValue.d.ts +13 -0
  209. package/dist/types/middleware/index.d.ts +4 -0
  210. package/dist/types/middleware/middleware.d.ts +4 -0
  211. package/dist/types/middleware/resolveLocale.d.ts +9 -0
  212. package/dist/types/middleware/syncCookie.d.ts +7 -0
  213. package/dist/types/middleware/utils.d.ts +26 -0
  214. package/dist/types/middleware.d.ts +1 -0
  215. package/dist/types/navigation/react-client/createNavigation.d.ts +464 -0
  216. package/dist/types/navigation/react-client/index.d.ts +2 -0
  217. package/dist/types/navigation/react-client/useBasePathname.d.ts +5 -0
  218. package/dist/types/navigation/react-server/createNavigation.d.ts +384 -0
  219. package/dist/types/navigation/react-server/getServerLocale.d.ts +5 -0
  220. package/dist/types/navigation/react-server/index.d.ts +2 -0
  221. package/dist/types/navigation/shared/BaseLink.d.ts +11 -0
  222. package/dist/types/navigation/shared/StrictParams.d.ts +8 -0
  223. package/dist/types/navigation/shared/createSharedNavigationFns.d.ts +370 -0
  224. package/dist/types/navigation/shared/syncLocaleCookie.d.ts +8 -0
  225. package/dist/types/navigation/shared/utils.d.ts +53 -0
  226. package/dist/types/navigation.react-client.d.ts +1 -0
  227. package/dist/types/navigation.react-server.d.ts +1 -0
  228. package/dist/types/plugin/catalog/catalogLoader.d.ts +10 -0
  229. package/dist/types/plugin/config.d.ts +3 -0
  230. package/dist/types/plugin/createNextIntlPlugin.d.ts +3 -0
  231. package/dist/types/plugin/declaration/createMessagesDeclaration.d.ts +1 -0
  232. package/dist/types/plugin/declaration/index.d.ts +1 -0
  233. package/dist/types/plugin/extractor/extractionLoader.d.ts +3 -0
  234. package/dist/types/plugin/extractor/initExtractionCompiler.d.ts +2 -0
  235. package/dist/types/plugin/getNextConfig.d.ts +3 -0
  236. package/dist/types/plugin/index.d.ts +1 -0
  237. package/dist/types/plugin/nextFlags.d.ts +2 -0
  238. package/dist/types/plugin/types.d.ts +29 -0
  239. package/dist/types/plugin/utils.d.ts +8 -0
  240. package/dist/types/plugin/watchFile.d.ts +6 -0
  241. package/dist/types/plugin.d.ts +1 -0
  242. package/dist/types/react-client/index.d.ts +16 -0
  243. package/dist/types/react-server/NextIntlClientProviderServer.d.ts +5 -0
  244. package/dist/types/react-server/index.d.ts +16 -0
  245. package/dist/types/react-server/testUtils.d.ts +2 -0
  246. package/dist/types/react-server/useConfig.d.ts +2 -0
  247. package/dist/types/react-server/useExtracted.d.ts +2 -0
  248. package/dist/types/react-server/useFormatter.d.ts +2 -0
  249. package/dist/types/react-server/useLocale.d.ts +2 -0
  250. package/dist/types/react-server/useMessages.d.ts +2 -0
  251. package/dist/types/react-server/useNow.d.ts +2 -0
  252. package/dist/types/react-server/useTimeZone.d.ts +2 -0
  253. package/dist/types/react-server/useTranslations.d.ts +2 -0
  254. package/dist/types/routing/config.d.ts +73 -0
  255. package/dist/types/routing/defineRouting.d.ts +3 -0
  256. package/dist/types/routing/index.d.ts +3 -0
  257. package/dist/types/routing/types.d.ts +24 -0
  258. package/dist/types/routing.d.ts +1 -0
  259. package/dist/types/server/react-client/index.d.ts +10 -0
  260. package/dist/types/server/react-server/RequestLocale.d.ts +1 -0
  261. package/dist/types/server/react-server/RequestLocaleCache.d.ts +3 -0
  262. package/dist/types/server/react-server/createRequestConfig.d.ts +3 -0
  263. package/dist/types/server/react-server/getConfig.d.ts +13 -0
  264. package/dist/types/server/react-server/getConfigNow.d.ts +4 -0
  265. package/dist/types/server/react-server/getDefaultNow.d.ts +3 -0
  266. package/dist/types/server/react-server/getExtracted.d.ts +10 -0
  267. package/dist/types/server/react-server/getFormats.d.ts +3 -0
  268. package/dist/types/server/react-server/getFormatter.d.ts +10 -0
  269. package/dist/types/server/react-server/getLocale.d.ts +4 -0
  270. package/dist/types/server/react-server/getMessages.d.ts +6 -0
  271. package/dist/types/server/react-server/getNow.d.ts +4 -0
  272. package/dist/types/server/react-server/getRequestConfig.d.ts +35 -0
  273. package/dist/types/server/react-server/getServerExtractor.d.ts +5 -0
  274. package/dist/types/server/react-server/getServerFormatter.d.ts +25 -0
  275. package/dist/types/server/react-server/getServerTranslator.d.ts +4 -0
  276. package/dist/types/server/react-server/getTimeZone.d.ts +4 -0
  277. package/dist/types/server/react-server/getTranslations.d.ts +8 -0
  278. package/dist/types/server/react-server/index.d.ts +12 -0
  279. package/dist/types/server/react-server/validateLocale.d.ts +1 -0
  280. package/dist/types/server.react-client.d.ts +1 -0
  281. package/dist/types/server.react-server.d.ts +1 -0
  282. package/dist/types/shared/NextIntlClientProvider.d.ts +9 -0
  283. package/dist/types/shared/constants.d.ts +1 -0
  284. package/dist/types/shared/types.d.ts +5 -0
  285. package/dist/types/shared/use.d.ts +3 -0
  286. package/dist/types/shared/utils.d.ts +20 -0
  287. package/extractor/catalogLoader.d.ts +4 -0
  288. package/extractor/extractionLoader.d.ts +4 -0
  289. package/extractor.d.ts +2 -0
  290. package/middleware.d.ts +4 -0
  291. package/navigation.d.ts +2 -0
  292. package/package.json +175 -0
  293. package/plugin.d.cts +3 -0
  294. package/plugin.d.ts +4 -0
  295. package/routing.d.ts +2 -0
  296. package/server.d.ts +2 -0
@@ -0,0 +1,36 @@
1
+ import { headers } from 'next/headers';
2
+ import { cache } from 'react';
3
+ import { HEADER_LOCALE_NAME } from '../../shared/constants.js';
4
+ import { isPromise } from '../../shared/utils.js';
5
+ import { getCachedRequestLocale } from './RequestLocaleCache.js';
6
+
7
+ async function getHeadersImpl() {
8
+ const promiseOrValue = headers();
9
+
10
+ // Compatibility with Next.js <15
11
+ return isPromise(promiseOrValue) ? await promiseOrValue : promiseOrValue;
12
+ }
13
+ const getHeaders = cache(getHeadersImpl);
14
+ async function getLocaleFromHeaderImpl() {
15
+ let locale;
16
+ try {
17
+ locale = (await getHeaders()).get(HEADER_LOCALE_NAME) || undefined;
18
+ } catch (error) {
19
+ if (error instanceof Error && error.digest === 'DYNAMIC_SERVER_USAGE') {
20
+ const wrappedError = new Error('Usage of next-intl APIs in Server Components currently opts into dynamic rendering. This limitation will eventually be lifted, but as a stopgap solution, you can use the `setRequestLocale` API to enable static rendering, see https://next-intl.dev/docs/routing/setup#static-rendering', {
21
+ cause: error
22
+ });
23
+ wrappedError.digest = error.digest;
24
+ throw wrappedError;
25
+ } else {
26
+ throw error;
27
+ }
28
+ }
29
+ return locale;
30
+ }
31
+ const getLocaleFromHeader = cache(getLocaleFromHeaderImpl);
32
+ async function getRequestLocale() {
33
+ return getCachedRequestLocale() || (await getLocaleFromHeader());
34
+ }
35
+
36
+ export { getRequestLocale };
@@ -0,0 +1,18 @@
1
+ import { cache } from 'react';
2
+
3
+ // See https://github.com/vercel/next.js/discussions/58862
4
+ function getCacheImpl() {
5
+ const value = {
6
+ locale: undefined
7
+ };
8
+ return value;
9
+ }
10
+ const getCache = cache(getCacheImpl);
11
+ function getCachedRequestLocale() {
12
+ return getCache().locale;
13
+ }
14
+ function setCachedRequestLocale(locale) {
15
+ getCache().locale = locale;
16
+ }
17
+
18
+ export { getCachedRequestLocale, setCachedRequestLocale };
@@ -0,0 +1,2 @@
1
+ import getRuntimeConfig from 'next-intl/config';
2
+ export { default } from 'next-intl/config';
@@ -0,0 +1,59 @@
1
+ import { cache } from 'react';
2
+ import { initializeConfig, _createIntlFormatters, _createCache } from 'use-intl/core';
3
+ import { isPromise } from '../../shared/utils.js';
4
+ import { getRequestLocale } from './RequestLocale.js';
5
+ import getRuntimeConfig from 'next-intl/config';
6
+ import validateLocale from './validateLocale.js';
7
+
8
+ // This is automatically inherited by `NextIntlClientProvider` if
9
+ // the component is rendered from a Server Component
10
+ function getDefaultTimeZoneImpl() {
11
+ return Intl.DateTimeFormat().resolvedOptions().timeZone;
12
+ }
13
+ const getDefaultTimeZone = cache(getDefaultTimeZoneImpl);
14
+ async function receiveRuntimeConfigImpl(getConfig, localeOverride) {
15
+ if (typeof getConfig !== 'function') {
16
+ throw new Error(`Invalid i18n request configuration detected.
17
+
18
+ Please verify that:
19
+ 1. In case you've specified a custom location in your Next.js config, make sure that the path is correct.
20
+ 2. You have a default export in your i18n request configuration file.
21
+
22
+ See also: https://next-intl.dev/docs/usage/configuration#i18n-request
23
+ `);
24
+ }
25
+ const params = {
26
+ locale: localeOverride,
27
+ // In case the consumer doesn't read `params.locale` and instead provides the
28
+ // `locale` (either in a single-language workflow or because the locale is
29
+ // read from the user settings), don't attempt to read the request locale.
30
+ get requestLocale() {
31
+ return localeOverride ? Promise.resolve(localeOverride) : getRequestLocale();
32
+ }
33
+ };
34
+ let result = getConfig(params);
35
+ if (isPromise(result)) {
36
+ result = await result;
37
+ }
38
+ if (!result.locale) {
39
+ throw new Error('No locale was returned from `getRequestConfig`.\n\nSee https://next-intl.dev/docs/usage/configuration#i18n-request');
40
+ }
41
+ {
42
+ validateLocale(result.locale);
43
+ }
44
+ return result;
45
+ }
46
+ const receiveRuntimeConfig = cache(receiveRuntimeConfigImpl);
47
+ const getFormatters = cache(_createIntlFormatters);
48
+ const getCache = cache(_createCache);
49
+ async function getConfigImpl(localeOverride) {
50
+ const runtimeConfig = await receiveRuntimeConfig(getRuntimeConfig, localeOverride);
51
+ return {
52
+ ...initializeConfig(runtimeConfig),
53
+ _formatters: getFormatters(getCache()),
54
+ timeZone: runtimeConfig.timeZone || getDefaultTimeZone()
55
+ };
56
+ }
57
+ const getConfig = cache(getConfigImpl);
58
+
59
+ export { getConfig as default };
@@ -0,0 +1,10 @@
1
+ import { cache } from 'react';
2
+ import getConfig from './getConfig.js';
3
+
4
+ async function getConfigNowImpl(locale) {
5
+ const config = await getConfig(locale);
6
+ return config.now;
7
+ }
8
+ const getConfigNow = cache(getConfigNowImpl);
9
+
10
+ export { getConfigNow as default };
@@ -0,0 +1,9 @@
1
+ import { cache } from 'react';
2
+
3
+ function defaultNow() {
4
+ // See https://next-intl.dev/docs/usage/dates-times#relative-times-server
5
+ return new Date();
6
+ }
7
+ const getDefaultNow = cache(defaultNow);
8
+
9
+ export { getDefaultNow as default };
@@ -0,0 +1,24 @@
1
+ import { cache } from 'react';
2
+ import getConfig from './getConfig.js';
3
+ import getServerExtractor from './getServerExtractor.js';
4
+
5
+ // Call signature 1: `getExtracted(namespace)`
6
+
7
+ // Call signature 2: `getExtracted({locale, namespace})`
8
+
9
+ // Implementation
10
+ async function getExtractedImpl(namespaceOrOpts) {
11
+ let namespace;
12
+ let locale;
13
+ if (typeof namespaceOrOpts === 'string') {
14
+ namespace = namespaceOrOpts;
15
+ } else if (namespaceOrOpts) {
16
+ locale = namespaceOrOpts.locale;
17
+ namespace = namespaceOrOpts.namespace;
18
+ }
19
+ const config = await getConfig(locale);
20
+ return getServerExtractor(config, namespace);
21
+ }
22
+ const getExtracted = cache(getExtractedImpl);
23
+
24
+ export { getExtracted as default };
@@ -0,0 +1,10 @@
1
+ import { cache } from 'react';
2
+ import getConfig from './getConfig.js';
3
+
4
+ async function getFormatsCachedImpl() {
5
+ const config = await getConfig();
6
+ return config.formats;
7
+ }
8
+ const getFormats = cache(getFormatsCachedImpl);
9
+
10
+ export { getFormats as default };
@@ -0,0 +1,21 @@
1
+ import { cache } from 'react';
2
+ import getConfig from './getConfig.js';
3
+ import getFormatterCached$1 from './getServerFormatter.js';
4
+
5
+ async function getFormatterCachedImpl(locale) {
6
+ const config = await getConfig(locale);
7
+ return getFormatterCached$1(config);
8
+ }
9
+ const getFormatterCached = cache(getFormatterCachedImpl);
10
+
11
+ /**
12
+ * Returns a formatter based on the given locale.
13
+ *
14
+ * The formatter automatically receives the request config, but
15
+ * you can override it by passing in additional options.
16
+ */
17
+ async function getFormatter(opts) {
18
+ return getFormatterCached(opts?.locale);
19
+ }
20
+
21
+ export { getFormatter as default };
@@ -0,0 +1,10 @@
1
+ import { cache } from 'react';
2
+ import getConfig from './getConfig.js';
3
+
4
+ async function getLocaleCachedImpl() {
5
+ const config = await getConfig();
6
+ return config.locale;
7
+ }
8
+ const getLocaleCached = cache(getLocaleCachedImpl);
9
+
10
+ export { getLocaleCached as default };
@@ -0,0 +1,19 @@
1
+ import { cache } from 'react';
2
+ import getConfig from './getConfig.js';
3
+
4
+ function getMessagesFromConfig(config) {
5
+ if (!config.messages) {
6
+ throw new Error('No messages found. Have you configured them correctly? See https://next-intl.dev/docs/configuration#messages');
7
+ }
8
+ return config.messages;
9
+ }
10
+ async function getMessagesCachedImpl(locale) {
11
+ const config = await getConfig(locale);
12
+ return getMessagesFromConfig(config);
13
+ }
14
+ const getMessagesCached = cache(getMessagesCachedImpl);
15
+ async function getMessages(opts) {
16
+ return getMessagesCached(opts?.locale);
17
+ }
18
+
19
+ export { getMessages as default, getMessagesFromConfig };
@@ -0,0 +1,8 @@
1
+ import getConfigNow from './getConfigNow.js';
2
+ import getDefaultNow from './getDefaultNow.js';
3
+
4
+ async function getNow(opts) {
5
+ return (await getConfigNow(opts?.locale)) ?? getDefaultNow();
6
+ }
7
+
8
+ export { getNow as default };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Should be called in `i18n/request.ts` to create the configuration for the current request.
3
+ */
4
+ function getRequestConfig(createRequestConfig) {
5
+ return createRequestConfig;
6
+ }
7
+
8
+ export { getRequestConfig as default };
@@ -0,0 +1,38 @@
1
+ import { cache } from 'react';
2
+ import getServerTranslator from './getServerTranslator.js';
3
+
4
+ // Note: This API is usually compiled into `useTranslations`,
5
+ // but there is some fallback handling which allows this hook
6
+ // to still work when not being compiled.
7
+ //
8
+ // This is relevant for:
9
+ // - Isolated environments like tests, Storybook, etc.
10
+ // - Fallbacks in case an extracted message is not yet available
11
+ function getServerExtractorImpl(config, namespace) {
12
+ const t = getServerTranslator(config, namespace);
13
+ function translateFn(...[message, values, formats]) {
14
+ return t(undefined, values, formats,
15
+ // @ts-expect-error -- Secret fallback parameter
16
+ message );
17
+ }
18
+ translateFn.rich = function translateRichFn(...[message, values, formats]) {
19
+ return t.rich(undefined, values, formats,
20
+ // @ts-expect-error -- Secret fallback parameter
21
+ message );
22
+ };
23
+ translateFn.markup = function translateMarkupFn(...[message, values, formats]) {
24
+ return t.markup(undefined, values, formats,
25
+ // @ts-expect-error -- Secret fallback parameter
26
+ message );
27
+ };
28
+ translateFn.has = function translateHasFn(
29
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
30
+ ...[message]) {
31
+ // Not really something better we can do here
32
+ return true;
33
+ };
34
+ return translateFn;
35
+ }
36
+ var getServerExtractor = cache(getServerExtractorImpl);
37
+
38
+ export { getServerExtractor as default };
@@ -0,0 +1,17 @@
1
+ import { cache } from 'react';
2
+ import { createFormatter } from 'use-intl/core';
3
+ import getDefaultNow from './getDefaultNow.js';
4
+
5
+ function getFormatterCachedImpl(config) {
6
+ return createFormatter({
7
+ ...config,
8
+ // Only init when necessary to avoid triggering a `dynamicIO` error
9
+ // unnecessarily (`now` is only needed for `format.relativeTime`)
10
+ get now() {
11
+ return config.now ?? getDefaultNow();
12
+ }
13
+ });
14
+ }
15
+ const getFormatterCached = cache(getFormatterCachedImpl);
16
+
17
+ export { getFormatterCached as default };
@@ -0,0 +1,12 @@
1
+ import { cache } from 'react';
2
+ import { createTranslator } from 'use-intl/core';
3
+
4
+ function getServerTranslatorImpl(config, namespace) {
5
+ return createTranslator({
6
+ ...config,
7
+ namespace
8
+ });
9
+ }
10
+ var getServerTranslator = cache(getServerTranslatorImpl);
11
+
12
+ export { getServerTranslator as default };
@@ -0,0 +1,13 @@
1
+ import { cache } from 'react';
2
+ import getConfig from './getConfig.js';
3
+
4
+ async function getTimeZoneCachedImpl(locale) {
5
+ const config = await getConfig(locale);
6
+ return config.timeZone;
7
+ }
8
+ const getTimeZoneCached = cache(getTimeZoneCachedImpl);
9
+ async function getTimeZone(opts) {
10
+ return getTimeZoneCached(opts?.locale);
11
+ }
12
+
13
+ export { getTimeZone as default };
@@ -0,0 +1,28 @@
1
+ import { cache } from 'react';
2
+ import getConfig from './getConfig.js';
3
+ import getServerTranslator from './getServerTranslator.js';
4
+
5
+ // Maintainer note: `getTranslations` has two different call signatures.
6
+ // We need to define these with function overloads, otherwise TypeScript
7
+ // messes up the return type.
8
+
9
+ // Call signature 1: `getTranslations(namespace)`
10
+
11
+ // Call signature 2: `getTranslations({locale, namespace})`
12
+
13
+ // Implementation
14
+ async function getTranslations(namespaceOrOpts) {
15
+ let namespace;
16
+ let locale;
17
+ if (typeof namespaceOrOpts === 'string') {
18
+ namespace = namespaceOrOpts;
19
+ } else if (namespaceOrOpts) {
20
+ locale = namespaceOrOpts.locale;
21
+ namespace = namespaceOrOpts.namespace;
22
+ }
23
+ const config = await getConfig(locale);
24
+ return getServerTranslator(config, namespace);
25
+ }
26
+ var getTranslations_default = cache(getTranslations);
27
+
28
+ export { getTranslations_default as default };
@@ -0,0 +1,12 @@
1
+ function validateLocale(locale) {
2
+ try {
3
+ const constructed = new Intl.Locale(locale);
4
+ if (!constructed.language) {
5
+ throw new Error('Language is required');
6
+ }
7
+ } catch {
8
+ console.error(`An invalid locale was provided: "${locale}"\nPlease ensure you're using a valid Unicode locale identifier (e.g. "en-US").`);
9
+ }
10
+ }
11
+
12
+ export { validateLocale as default };
@@ -0,0 +1 @@
1
+ export { getExtracted, getFormatter, getLocale, getMessages, getNow, getRequestConfig, getTimeZone, getTranslations, setRequestLocale } from './server/react-client/index.js';
@@ -0,0 +1,9 @@
1
+ export { default as getRequestConfig } from './server/react-server/getRequestConfig.js';
2
+ export { default as getFormatter } from './server/react-server/getFormatter.js';
3
+ export { default as getNow } from './server/react-server/getNow.js';
4
+ export { default as getTimeZone } from './server/react-server/getTimeZone.js';
5
+ export { default as getExtracted } from './server/react-server/getExtracted.js';
6
+ export { default as getMessages } from './server/react-server/getMessages.js';
7
+ export { default as getLocale } from './server/react-server/getLocale.js';
8
+ export { default as getTranslations } from './server/react-server/getTranslations.js';
9
+ export { setCachedRequestLocale as setRequestLocale } from './server/react-server/RequestLocaleCache.js';
@@ -0,0 +1,18 @@
1
+ "use client";
2
+ import { IntlProvider } from 'use-intl/react';
3
+ import { jsx } from 'react/jsx-runtime';
4
+
5
+ function NextIntlClientProvider({
6
+ locale,
7
+ ...rest
8
+ }) {
9
+ if (!locale) {
10
+ throw new Error("Couldn't infer the `locale` prop in `NextIntlClientProvider`, please provide it explicitly.\n\nSee https://next-intl.dev/docs/configuration#locale" );
11
+ }
12
+ return /*#__PURE__*/jsx(IntlProvider, {
13
+ locale: locale,
14
+ ...rest
15
+ });
16
+ }
17
+
18
+ export { NextIntlClientProvider as default };
@@ -0,0 +1,4 @@
1
+ // Used to read the locale from the middleware
2
+ const HEADER_LOCALE_NAME = 'X-NEXT-INTL-LOCALE';
3
+
4
+ export { HEADER_LOCALE_NAME };
@@ -0,0 +1,13 @@
1
+ import * as react from 'react';
2
+
3
+ // @ts-expect-error -- Ooof, Next.js doesn't make this easy.
4
+ // `use` is only available in React 19 canary, but we can
5
+ // use it in Next.js already as Next.js "vendors" a fixed
6
+ // version of React. However, if we'd simply put `use` in
7
+ // ESM code, then the build doesn't work since React does
8
+ // not export `use` officially. Therefore, we have to use
9
+ // something that is not statically analyzable. Once React
10
+ // 19 is out, we can remove this in the next major version.
11
+ var use = react['use'.trim()];
12
+
13
+ export { use as default };
@@ -0,0 +1,140 @@
1
+ function isRelativeHref(href) {
2
+ const pathname = typeof href === 'object' ? href.pathname : href;
3
+ return pathname != null && !pathname.startsWith('/');
4
+ }
5
+ function isLocalHref(href) {
6
+ if (typeof href === 'object') {
7
+ return href.host == null && href.hostname == null;
8
+ } else {
9
+ const hasProtocol = /^[a-z]+:/i.test(href);
10
+ return !hasProtocol;
11
+ }
12
+ }
13
+ function isLocalizableHref(href) {
14
+ return isLocalHref(href) && !isRelativeHref(href);
15
+ }
16
+ function unprefixPathname(pathname, prefix) {
17
+ return pathname.replace(new RegExp(`^${prefix}`), '') || '/';
18
+ }
19
+ function prefixPathname(prefix, pathname) {
20
+ let localizedHref = prefix;
21
+
22
+ // Avoid trailing slashes
23
+ if (/^\/(\?.*)?$/.test(pathname)) {
24
+ pathname = pathname.slice(1);
25
+ }
26
+ localizedHref += pathname;
27
+ return localizedHref;
28
+ }
29
+ function hasPathnamePrefixed(prefix, pathname) {
30
+ return pathname === prefix || pathname.startsWith(`${prefix}/`);
31
+ }
32
+ function hasTrailingSlash() {
33
+ try {
34
+ // Provided via `env` setting in `next.config.js` via the plugin
35
+ return process.env._next_intl_trailing_slash === 'true';
36
+ } catch {
37
+ return false;
38
+ }
39
+ }
40
+ function getLocalizedTemplate(pathnameConfig, locale, internalTemplate) {
41
+ return typeof pathnameConfig === 'string' ? pathnameConfig : pathnameConfig[locale] || internalTemplate;
42
+ }
43
+ function normalizeTrailingSlash(pathname) {
44
+ const trailingSlash = hasTrailingSlash();
45
+ const [path, ...hashParts] = pathname.split('#');
46
+ const hash = hashParts.join('#');
47
+ let normalizedPath = path;
48
+ if (normalizedPath !== '/') {
49
+ const pathnameEndsWithSlash = normalizedPath.endsWith('/');
50
+ if (trailingSlash && !pathnameEndsWithSlash) {
51
+ normalizedPath += '/';
52
+ } else if (!trailingSlash && pathnameEndsWithSlash) {
53
+ normalizedPath = normalizedPath.slice(0, -1);
54
+ }
55
+ }
56
+ if (hash) {
57
+ normalizedPath += '#' + hash;
58
+ }
59
+ return normalizedPath;
60
+ }
61
+ function matchesPathname(/** E.g. `/users/[userId]-[userName]` */
62
+ template, /** E.g. `/users/23-jane` */
63
+ pathname) {
64
+ const normalizedTemplate = normalizeTrailingSlash(template);
65
+ const normalizedPathname = normalizeTrailingSlash(pathname);
66
+ const regex = templateToRegex(normalizedTemplate);
67
+ return regex.test(normalizedPathname);
68
+ }
69
+ function getLocalePrefix(locale, localePrefix) {
70
+ return localePrefix.mode !== 'never' && localePrefix.prefixes?.[locale] ||
71
+ // We return a prefix even if `mode: 'never'`. It's up to the consumer
72
+ // to decide to use it or not.
73
+ getLocaleAsPrefix(locale);
74
+ }
75
+ function getLocaleAsPrefix(locale) {
76
+ return '/' + locale;
77
+ }
78
+ function templateToRegex(template) {
79
+ const regexPattern = template
80
+ // Replace optional catchall ('[[...slug]]')
81
+ .replace(/\/\[\[(\.\.\.[^\]]+)\]\]/g, '(?:/(.*))?') // With leading slash
82
+ .replace(/\[\[(\.\.\.[^\]]+)\]\]/g, '(?:/(.*))?') // Without leading slash
83
+ // Replace catchall ('[...slug]')
84
+ .replace(/\[(\.\.\.[^\]]+)\]/g, '(.+)')
85
+ // Replace regular parameter ('[slug]')
86
+ .replace(/\[([^\]]+)\]/g, '([^/]+)');
87
+ return new RegExp(`^${regexPattern}$`);
88
+ }
89
+ function isOptionalCatchAllSegment(pathname) {
90
+ return pathname.includes('[[...');
91
+ }
92
+ function isCatchAllSegment(pathname) {
93
+ return pathname.includes('[...');
94
+ }
95
+ function isDynamicSegment(pathname) {
96
+ return pathname.includes('[');
97
+ }
98
+ function comparePathnamePairs(a, b) {
99
+ const pathA = a.split('/');
100
+ const pathB = b.split('/');
101
+ const maxLength = Math.max(pathA.length, pathB.length);
102
+ for (let i = 0; i < maxLength; i++) {
103
+ const segmentA = pathA[i];
104
+ const segmentB = pathB[i];
105
+
106
+ // If one of the paths ends, prioritize the shorter path
107
+ if (!segmentA && segmentB) return -1;
108
+ if (segmentA && !segmentB) return 1;
109
+ if (!segmentA && !segmentB) continue;
110
+
111
+ // Prioritize static segments over dynamic segments
112
+ if (!isDynamicSegment(segmentA) && isDynamicSegment(segmentB)) return -1;
113
+ if (isDynamicSegment(segmentA) && !isDynamicSegment(segmentB)) return 1;
114
+
115
+ // Prioritize non-catch-all segments over catch-all segments
116
+ if (!isCatchAllSegment(segmentA) && isCatchAllSegment(segmentB)) return -1;
117
+ if (isCatchAllSegment(segmentA) && !isCatchAllSegment(segmentB)) return 1;
118
+
119
+ // Prioritize non-optional catch-all segments over optional catch-all segments
120
+ if (!isOptionalCatchAllSegment(segmentA) && isOptionalCatchAllSegment(segmentB)) {
121
+ return -1;
122
+ }
123
+ if (isOptionalCatchAllSegment(segmentA) && !isOptionalCatchAllSegment(segmentB)) {
124
+ return 1;
125
+ }
126
+ if (segmentA === segmentB) continue;
127
+ }
128
+
129
+ // Both pathnames are completely static
130
+ return 0;
131
+ }
132
+ function getSortedPathnames(pathnames) {
133
+ return pathnames.sort(comparePathnamePairs);
134
+ }
135
+ function isPromise(value) {
136
+ // https://github.com/amannn/next-intl/issues/1711
137
+ return typeof value.then === 'function';
138
+ }
139
+
140
+ export { getLocaleAsPrefix, getLocalePrefix, getLocalizedTemplate, getSortedPathnames, hasPathnamePrefixed, isLocalizableHref, isPromise, matchesPathname, normalizeTrailingSlash, prefixPathname, templateToRegex, unprefixPathname };
@@ -0,0 +1 @@
1
+ function t(){throw new Error("Couldn't find next-intl config file. Please follow the instructions at https://next-intl.dev/docs/getting-started/app-router")}export{t as default};
@@ -0,0 +1 @@
1
+ import s from"./catalog/CatalogManager.js";import t from"./extractor/MessageExtractor.js";class o{constructor(o,a={}){const e=a.extractor??new t(a);this.manager=new s(o,{...a,extractor:e}),this[Symbol.dispose]=this[Symbol.dispose].bind(this),this.installExitHandlers()}async extractAll(){await this.manager.loadMessages(),await this.manager.save()}[Symbol.dispose](){this.uninstallExitHandlers(),this.manager[Symbol.dispose]()}installExitHandlers(){const s=this[Symbol.dispose];process.on("exit",s),process.on("SIGINT",s),process.on("SIGTERM",s)}uninstallExitHandlers(){const s=this[Symbol.dispose];process.off("exit",s),process.off("SIGINT",s),process.off("SIGTERM",s)}}export{o as default};
@@ -0,0 +1 @@
1
+ import e from"fs";import s from"fs/promises";import t from"path";class a{onChangeCallbacks=new Set;constructor(e){this.messagesDir=e.messagesDir,this.sourceLocale=e.sourceLocale,this.extension=e.extension,this.locales=e.locales}async getTargetLocales(){return this.targetLocales||("infer"===this.locales?this.targetLocales=await this.readTargetLocales():this.targetLocales=this.locales.filter((e=>e!==this.sourceLocale))),this.targetLocales}async readTargetLocales(){try{return(await s.readdir(this.messagesDir)).filter((e=>e.endsWith(this.extension))).map((e=>t.basename(e,this.extension))).filter((e=>e!==this.sourceLocale))}catch{return[]}}subscribeLocalesChange(e){this.onChangeCallbacks.add(e),"infer"!==this.locales||this.watcher||this.startWatcher()}unsubscribeLocalesChange(e){this.onChangeCallbacks.delete(e),0===this.onChangeCallbacks.size&&this.stopWatcher()}async startWatcher(){this.watcher||(await s.mkdir(this.messagesDir,{recursive:!0}),this.watcher=e.watch(this.messagesDir,{persistent:!1,recursive:!1},((e,s)=>{null!=s&&s.endsWith(this.extension)&&!s.includes(t.sep)&&this.onChange()})))}stopWatcher(){this.watcher&&(this.watcher.close(),this.watcher=void 0)}async onChange(){const e=new Set(this.targetLocales||[]);this.targetLocales=await this.readTargetLocales();const s=new Set(this.targetLocales),t=this.targetLocales.filter((s=>!e.has(s))),a=Array.from(e).filter((e=>!s.has(e)));if(t.length>0||a.length>0)for(const e of this.onChangeCallbacks)e({added:t,removed:a})}}export{a as default};
@@ -0,0 +1 @@
1
+ import e from"fs/promises";import s from"path";import{resolveCodec as t,getFormatExtension as a}from"../format/index.js";import o from"../source/SourceFileScanner.js";import i from"../source/SourceFileWatcher.js";import{getDefaultProjectRoot as r,normalizePathToPosix as c,compareReferences as l}from"../utils.js";import n from"./CatalogLocales.js";import h from"./CatalogPersister.js";import g from"./SaveScheduler.js";class m{messagesByFile=new Map;messagesById=new Map;translationsByTargetLocale=new Map;lastWriteByLocale=new Map;constructor(e,s){this.config=e,this.saveScheduler=new g(50),this.projectRoot=s.projectRoot??r(),this.isDevelopment=s.isDevelopment??!1,this.extractor=s.extractor,this.isDevelopment&&(this.sourceWatcher=new i(this.getSrcPaths(),this.handleFileEvents.bind(this)),this.sourceWatcher.start())}async getCodec(){return this.codec||(this.codec=await t(this.config.messages.format,this.projectRoot)),this.codec}async getPersister(){return this.persister||(this.persister=new h({messagesPath:this.config.messages.path,codec:await this.getCodec(),extension:a(this.config.messages.format)})),this.persister}getCatalogLocales(){if(this.catalogLocales)return this.catalogLocales;{const e=s.join(this.projectRoot,this.config.messages.path);return this.catalogLocales=new n({messagesDir:e,sourceLocale:this.config.sourceLocale,extension:a(this.config.messages.format),locales:this.config.messages.locales}),this.catalogLocales}}async getTargetLocales(){return this.getCatalogLocales().getTargetLocales()}getSrcPaths(){return(Array.isArray(this.config.srcPath)?this.config.srcPath:[this.config.srcPath]).map((e=>s.join(this.projectRoot,e)))}async loadMessages(){const e=await this.loadSourceMessages();if(this.loadCatalogsPromise=this.loadTargetMessages(),await this.loadCatalogsPromise,this.scanCompletePromise=(async()=>{const s=await o.getSourceFiles(this.getSrcPaths());await Promise.all(Array.from(s).map((async e=>this.processFile(e)))),this.mergeSourceDiskMetadata(e)})(),await this.scanCompletePromise,this.isDevelopment){this.getCatalogLocales().subscribeLocalesChange(this.onLocalesChange)}}async loadSourceMessages(){const e=await this.loadLocaleMessages(this.config.sourceLocale),s=new Map;for(const t of e)s.set(t.id,t);return s}async loadLocaleMessages(e){const s=await this.getPersister(),t=await s.read(e),a=await s.getLastModified(e);return this.lastWriteByLocale.set(e,a),t}async loadTargetMessages(){const e=await this.getTargetLocales();await Promise.all(e.map((e=>this.reloadLocaleCatalog(e))))}async reloadLocaleCatalog(e){const s=await this.loadLocaleMessages(e);if(e===this.config.sourceLocale)for(const e of s){const s=this.messagesById.get(e.id);if(s)for(const t of Object.keys(e))["id","message","description","references"].includes(t)||(s[t]=e[t])}else{const t=this.translationsByTargetLocale.get(e),a=t&&t.size>0;if(s.length>0){const t=new Map;for(const e of s)t.set(e.id,e);this.translationsByTargetLocale.set(e,t)}else if(a);else{const s=new Map;this.translationsByTargetLocale.set(e,s)}}}mergeSourceDiskMetadata(e){for(const[s,t]of e){const e=this.messagesById.get(s);if(e)for(const s of Object.keys(t))null==e[s]&&(e[s]=t[s])}}async processFile(t){let a=[];try{const s=await e.readFile(t,"utf8");let o;try{o=await this.extractor.extract(t,s)}catch{return!1}a=o.messages}catch(e){if("ENOENT"!==e.code)throw e}const o=this.messagesByFile.get(t),i=c(s.relative(this.projectRoot,t)),r=Array.from(o?.keys()??[]),l=new Map;for(let e of a){const s=this.messagesById.get(e.id);if(s){e={...e},e.references&&(e.references=this.mergeReferences(s.references??[],i,e.references));for(const t of Object.keys(s))null==e[t]&&(e[t]=s[t])}this.messagesById.set(e.id,e),l.set(e.id,e);const t=r.indexOf(e.id);-1!==t&&r.splice(t,1)}r.forEach((e=>{const s=this.messagesById.get(e);if(!s)return;const t=s.references?.some((e=>e.path!==i));t?s.references=s.references?.filter((e=>e.path!==i)):this.messagesById.delete(e)})),a.length>0?this.messagesByFile.set(t,l):this.messagesByFile.delete(t);return this.haveMessagesChangedForFile(o,l)}mergeReferences(e,s,t){return[...e.filter((e=>e.path!==s)),...t].sort(l)}haveMessagesChangedForFile(e,s){if(!e)return s.size>0;if(e.size!==s.size)return!0;for(const[t,a]of e){const e=s.get(t);if(!e||!this.areMessagesEqual(a,e))return!0}return!1}areMessagesEqual(e,s){return e.id===s.id&&e.message===s.message&&e.description===s.description}async save(){return this.saveScheduler.schedule((()=>this.saveImpl()))}async saveImpl(){await this.saveLocale(this.config.sourceLocale);const e=await this.getTargetLocales();await Promise.all(e.map((e=>this.saveLocale(e))))}async saveLocale(e){await this.loadCatalogsPromise;const s=Array.from(this.messagesById.values()),t=await this.getPersister(),a=e===this.config.sourceLocale,o=this.lastWriteByLocale.get(e),i=await t.getLastModified(e);i&&o&&i>o&&await this.reloadLocaleCatalog(e);const r=a?this.messagesById:this.translationsByTargetLocale.get(e),c=s.map((e=>{const s=r?.get(e.id);return{...s,id:e.id,description:e.description,references:e.references,message:a?e.message:s?.message??""}}));await t.write(c,{locale:e,sourceMessagesById:this.messagesById});const l=await t.getLastModified(e);this.lastWriteByLocale.set(e,l)}onLocalesChange=async e=>{this.loadCatalogsPromise=Promise.all([this.loadCatalogsPromise,...e.added.map((e=>this.reloadLocaleCatalog(e)))]);for(const s of e.added)await this.saveLocale(s);for(const s of e.removed)this.translationsByTargetLocale.delete(s),this.lastWriteByLocale.delete(s)};async handleFileEvents(e){this.loadCatalogsPromise&&await this.loadCatalogsPromise,this.scanCompletePromise&&await this.scanCompletePromise;let s=!1;const t=await this.sourceWatcher.expandDirectoryDeleteEvents(e,Array.from(this.messagesByFile.keys()));for(const e of t){const t=await this.processFile(e.path);s||=t}s&&await this.save()}[Symbol.dispose](){this.sourceWatcher?.stop(),this.sourceWatcher=void 0,this.saveScheduler[Symbol.dispose](),this.catalogLocales&&this.isDevelopment&&this.catalogLocales.unsubscribeLocalesChange(this.onLocalesChange)}}export{m as default};
@@ -0,0 +1 @@
1
+ import e from"fs/promises";import t from"path";class r{constructor(e){this.messagesPath=e.messagesPath,this.codec=e.codec,this.extension=e.extension}getFileName(e){return e+this.extension}getFilePath(e){return t.join(this.messagesPath,this.getFileName(e))}async read(t){const r=this.getFilePath(t);let i;try{i=await e.readFile(r,"utf8")}catch(e){if(e&&"object"==typeof e&&"code"in e&&"ENOENT"===e.code)return[];throw new Error(`Error while reading ${this.getFileName(t)}:\n> ${e}`,{cause:e})}try{return this.codec.decode(i,{locale:t})}catch(e){throw new Error(`Error while decoding ${this.getFileName(t)}:\n> ${e}`,{cause:e})}}async write(r,i){const a=this.getFilePath(i.locale),s=this.codec.encode(r,i);try{const r=t.dirname(a);await e.mkdir(r,{recursive:!0}),await e.writeFile(a,s)}catch(e){console.error(`❌ Failed to write catalog: ${e}`)}}async getLastModified(t){const r=this.getFilePath(t);try{return(await e.stat(r)).mtime}catch{return}}}export{r as default};
@@ -0,0 +1 @@
1
+ class e{isSaving=!1;pendingResolvers=[];constructor(e=50){this.delayMs=e}async schedule(e){return new Promise(((s,i)=>{this.pendingResolvers.push({resolve:s,reject:i}),this.nextSaveTask=e,this.isSaving||this.saveTimeout?this.saveTimeout&&this.scheduleSave():this.executeSave()}))}scheduleSave(){this.saveTimeout&&clearTimeout(this.saveTimeout),this.saveTimeout=setTimeout((()=>{this.saveTimeout=void 0,this.executeSave()}),this.delayMs)}async executeSave(){if(this.isSaving)return;const e=this.nextSaveTask;if(!e)return;const s=this.pendingResolvers;this.pendingResolvers=[],this.nextSaveTask=void 0,this.isSaving=!0;try{const i=await e();s.forEach((({resolve:e})=>e(i)))}catch(e){s.forEach((({reject:s})=>s(e)))}finally{this.isSaving=!1,this.pendingResolvers.length>0&&this.scheduleSave()}}[Symbol.dispose](){this.saveTimeout&&(clearTimeout(this.saveTimeout),this.saveTimeout=void 0),this.pendingResolvers=[],this.nextSaveTask=void 0,this.isSaving=!1}}export{e as default};
@@ -0,0 +1 @@
1
+ import e from"path";import t from"icu-minify/compile";import{getFormatExtension as s,resolveCodec as o}from"./format/index.js";import{setNestedProperty as r}from"./utils.js";let a=null;const n=new Map;function i(i){const c=this.getOptions(),l=this.async(),f=s(c.messages.format);(async function(e,t){return a||(a=await o(e.messages.format,t)),a})(c,this.rootContext).then((s=>{const o=e.basename(this.resourcePath,f);let a;if(c.messages.precompile){const e=function(e,s){const o={},a=new Set(s.keys());for(const n of e){a.delete(n.id);const e=n.message;if(Array.isArray(e))throw new Error(`Message at \`${n.id}\` resolved to an array, but only strings are supported. See https://next-intl.dev/docs/usage/translations#arrays-of-messages`);if("object"==typeof e)throw new Error(`Message at \`${n.id}\` resolved to \`${typeof e}\`, but only strings are supported. Use a \`.\` to retrieve nested messages. See https://next-intl.dev/docs/usage/translations#structuring-messages`);const i=s.get(n.id);let c;i?.messageValue===e?c=i.compiledMessage:(c=t(e),s.set(n.id,{compiledMessage:c,messageValue:e})),r(o,n.id,c)}for(const e of a)s.delete(e);return o}(s.decode(i,{locale:o}),function(e){let t=n.get(e);return t||(t=new Map,n.set(e,t)),t}(this.resourcePath));a=JSON.stringify(e)}else a=s.toJSONString(i,{locale:o});const m=`export default JSON.parse(${JSON.stringify(a)});`;l(null,m)})).catch(l)}export{i as default};
@@ -0,0 +1 @@
1
+ import t from"./ExtractionCompiler.js";import o from"./extractor/MessageExtractor.js";import{getDefaultProjectRoot as r}from"./utils.js";async function e(e){const a=new t(e,{extractor:new o({isDevelopment:!1,projectRoot:r()})});await a.extractAll()}export{e as default};
@@ -0,0 +1 @@
1
+ import t from"./extractor/MessageExtractor.js";let e;function o(o){const r=this.async(),s=this.rootContext,c="development"===process.env["NODE_ENV".trim()];e||(e=new t({isDevelopment:c,projectRoot:s,sourceMap:this.sourceMap})),e.extract(this.resourcePath,o).then((t=>{r(null,t.code,t.map)})).catch(r)}export{o as default};
@@ -0,0 +1 @@
1
+ class e{constructor(e){this.maxSize=e,this.cache=new Map}set(e,t){if(!this.cache.has(e)&&this.cache.size>=this.maxSize){const e=this.cache.keys().next().value;void 0!==e&&this.cache.delete(e)}this.cache.set(e,{key:e,value:t})}get(e){const t=this.cache.get(e);if(t)return this.cache.delete(e),this.cache.set(e,t),t.value}}export{e as default};
@@ -0,0 +1 @@
1
+ import{createRequire as e}from"module";import t from"path";import{transform as s}from"@swc/core";import{getDefaultProjectRoot as o,normalizePathToPosix as r}from"../utils.js";import i from"./LRUCache.js";const c=e(import.meta.url);class a{compileCache=new i(750);constructor(e){this.isDevelopment=e.isDevelopment??!1,this.projectRoot=e.projectRoot??o(),this.sourceMap=e.sourceMap??!1}async extract(e,o){const i=[o,e].join("!"),a=this.compileCache.get(i);if(a)return a;if(!o.includes("useExtracted")&&!o.includes("getExtracted"))return{messages:[],code:o};const p=r(t.relative(this.projectRoot,e)),l=await s(o,{jsc:{target:"esnext",parser:{syntax:"typescript",tsx:!0,decorators:!0},experimental:{cacheRoot:"node_modules/.cache/swc",disableBuiltinTransformsForInternalTesting:!0,disableAllLints:!0,plugins:[[c.resolve("next-intl-swc-plugin-extractor"),{isDevelopment:this.isDevelopment,filePath:p}]]}},sourceMaps:this.sourceMap,sourceFileName:p,filename:p}),n=l.output,m=JSON.parse(JSON.parse(n).results),u={code:l.code,map:l.map,messages:m};return this.compileCache.set(i,u),u}}export{a as default};
@@ -0,0 +1 @@
1
+ function n(n){return n}export{n as defineCodec};
@@ -0,0 +1 @@
1
+ import{getSortedMessages as e,setNestedProperty as r}from"../../utils.js";import{defineCodec as s}from"../ExtractorCodec.js";var t=s((()=>({decode(e){const r=JSON.parse(e),s=[];return o(r,((e,r)=>{s.push({id:r,message:e})})),s},encode(s){const t={};for(const o of e(s))r(t,o.id,o.message);return JSON.stringify(t,null,2)+"\n"},toJSONString:e=>e})));function o(e,r,s=""){for(const t of Object.keys(e)){const n=s?s+"."+t:t,a=e[t];if("string"==typeof a)r(a,n);else{if(Array.isArray(a))throw new Error(`Message at \`${n}\` resolved to an array, but only strings are supported. See https://next-intl.dev/docs/usage/translations#arrays-of-messages`);"object"==typeof a&&o(a,r,n)}}}export{t as default};