next-tongue 0.9.1 → 0.9.3

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 (259) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +90 -0
  3. package/dist/cli/check-types.d.ts +0 -1
  4. package/dist/cli/check-types.js +0 -1
  5. package/dist/cli/check.d.ts +0 -1
  6. package/dist/cli/check.js +0 -1
  7. package/dist/cli/export-import.d.ts +0 -1
  8. package/dist/cli/export-import.js +0 -1
  9. package/dist/cli/extract.d.ts +0 -1
  10. package/dist/cli/extract.js +0 -1
  11. package/dist/cli/index.d.ts +0 -1
  12. package/dist/cli/index.js +0 -1
  13. package/dist/cli/init.d.ts +7 -1
  14. package/dist/cli/init.js +144 -54
  15. package/dist/cli/migrate.d.ts +0 -1
  16. package/dist/cli/migrate.js +0 -1
  17. package/dist/cli/report.d.ts +0 -1
  18. package/dist/cli/report.js +0 -1
  19. package/dist/cli/reporters.d.ts +0 -1
  20. package/dist/cli/reporters.js +0 -1
  21. package/dist/cli/safe-path.d.ts +0 -1
  22. package/dist/cli/safe-path.js +0 -1
  23. package/dist/cli/translate.d.ts +0 -1
  24. package/dist/cli/translate.js +0 -1
  25. package/dist/client/dev-overlay-gate.d.ts +0 -1
  26. package/dist/client/dev-overlay-gate.js +0 -1
  27. package/dist/client/dev-overlay.d.ts +0 -1
  28. package/dist/client/dev-overlay.js +0 -1
  29. package/dist/client/dev-registry.d.ts +0 -1
  30. package/dist/client/dev-registry.js +0 -1
  31. package/dist/client/editor-url.d.ts +0 -1
  32. package/dist/client/editor-url.js +0 -1
  33. package/dist/client/index.d.ts +0 -1
  34. package/dist/client/index.js +0 -1
  35. package/dist/compiler/ast.d.ts +0 -1
  36. package/dist/compiler/ast.js +0 -1
  37. package/dist/compiler/build.d.ts +0 -1
  38. package/dist/compiler/build.js +0 -1
  39. package/dist/compiler/codegen/emit-js.d.ts +0 -1
  40. package/dist/compiler/codegen/emit-js.js +0 -1
  41. package/dist/compiler/codegen/emit-types.d.ts +0 -1
  42. package/dist/compiler/codegen/emit-types.js +0 -1
  43. package/dist/compiler/fallback.d.ts +0 -1
  44. package/dist/compiler/fallback.js +0 -1
  45. package/dist/compiler/index.d.ts +0 -1
  46. package/dist/compiler/index.js +0 -1
  47. package/dist/compiler/json-locations.d.ts +0 -1
  48. package/dist/compiler/json-locations.js +0 -1
  49. package/dist/compiler/load-messages.d.ts +0 -1
  50. package/dist/compiler/load-messages.js +0 -1
  51. package/dist/compiler/parse/icu-parser.d.ts +0 -1
  52. package/dist/compiler/parse/icu-parser.js +0 -1
  53. package/dist/compiler/pseudo.d.ts +0 -1
  54. package/dist/compiler/pseudo.js +0 -1
  55. package/dist/compiler/scan-keys.d.ts +0 -1
  56. package/dist/compiler/scan-keys.js +0 -1
  57. package/dist/compiler/scan-routes.d.ts +0 -1
  58. package/dist/compiler/scan-routes.js +0 -1
  59. package/dist/compiler/sources.d.ts +0 -1
  60. package/dist/compiler/sources.js +0 -1
  61. package/dist/compiler/validate/a11y.d.ts +7 -3
  62. package/dist/compiler/validate/a11y.js +99 -36
  63. package/dist/compiler/validate/bidi.d.ts +0 -1
  64. package/dist/compiler/validate/bidi.js +0 -1
  65. package/dist/compiler/validate/catalog.d.ts +0 -1
  66. package/dist/compiler/validate/catalog.js +0 -1
  67. package/dist/compiler/validate/length.d.ts +0 -1
  68. package/dist/compiler/validate/length.js +0 -1
  69. package/dist/compiler/validate/plurals.d.ts +0 -1
  70. package/dist/compiler/validate/plurals.js +0 -1
  71. package/dist/compiler/validate/usage.d.ts +0 -1
  72. package/dist/compiler/validate/usage.js +0 -1
  73. package/dist/config/define-config.d.ts +0 -1
  74. package/dist/config/define-config.js +0 -1
  75. package/dist/config/index.d.ts +0 -1
  76. package/dist/config/index.js +0 -1
  77. package/dist/config/load-config.d.ts +0 -1
  78. package/dist/config/load-config.js +0 -1
  79. package/dist/config/types.d.ts +0 -1
  80. package/dist/config/types.js +0 -1
  81. package/dist/config/validate.d.ts +0 -1
  82. package/dist/config/validate.js +0 -1
  83. package/dist/errors.d.ts +0 -1
  84. package/dist/errors.js +0 -1
  85. package/dist/index.d.ts +0 -1
  86. package/dist/index.js +0 -1
  87. package/dist/navigation/index.d.ts +0 -1
  88. package/dist/navigation/index.js +0 -1
  89. package/dist/navigation/locale-switcher.d.ts +0 -1
  90. package/dist/navigation/locale-switcher.js +0 -1
  91. package/dist/navigation/pathname.d.ts +0 -1
  92. package/dist/navigation/pathname.js +0 -1
  93. package/dist/next/index.d.ts +0 -1
  94. package/dist/next/index.js +0 -1
  95. package/dist/next/loader.d.ts +0 -1
  96. package/dist/next/loader.js +0 -1
  97. package/dist/next/watcher.d.ts +0 -1
  98. package/dist/next/watcher.js +0 -1
  99. package/dist/next/with-tongue.d.ts +0 -1
  100. package/dist/next/with-tongue.js +12 -4
  101. package/dist/proxy/index.d.ts +0 -1
  102. package/dist/proxy/index.js +0 -1
  103. package/dist/proxy/locale-matcher.d.ts +0 -1
  104. package/dist/proxy/locale-matcher.js +0 -1
  105. package/dist/runtime/create-t.d.ts +0 -1
  106. package/dist/runtime/create-t.js +0 -1
  107. package/dist/runtime/format-message.d.ts +0 -1
  108. package/dist/runtime/format-message.js +0 -1
  109. package/dist/runtime/format.d.ts +0 -1
  110. package/dist/runtime/format.js +0 -1
  111. package/dist/runtime/locale-preference.d.ts +0 -1
  112. package/dist/runtime/locale-preference.js +0 -1
  113. package/dist/runtime/locale.d.ts +0 -1
  114. package/dist/runtime/locale.js +0 -1
  115. package/dist/runtime/lru.d.ts +0 -1
  116. package/dist/runtime/lru.js +0 -1
  117. package/dist/runtime/rich.d.ts +0 -1
  118. package/dist/runtime/rich.js +0 -1
  119. package/dist/runtime/sanctioned-units.d.ts +0 -1
  120. package/dist/runtime/sanctioned-units.js +0 -1
  121. package/dist/runtime/translate-issues.d.ts +0 -1
  122. package/dist/runtime/translate-issues.js +0 -1
  123. package/dist/server/alternates.d.ts +0 -1
  124. package/dist/server/alternates.js +0 -1
  125. package/dist/server/index.d.ts +0 -1
  126. package/dist/server/index.js +0 -1
  127. package/dist/server/locale-preference.d.ts +0 -1
  128. package/dist/server/locale-preference.js +0 -1
  129. package/dist/testing/index.d.ts +0 -1
  130. package/dist/testing/index.js +0 -1
  131. package/package.json +27 -2
  132. package/dist/cli/check-types.d.ts.map +0 -1
  133. package/dist/cli/check-types.js.map +0 -1
  134. package/dist/cli/check.d.ts.map +0 -1
  135. package/dist/cli/check.js.map +0 -1
  136. package/dist/cli/export-import.d.ts.map +0 -1
  137. package/dist/cli/export-import.js.map +0 -1
  138. package/dist/cli/extract.d.ts.map +0 -1
  139. package/dist/cli/extract.js.map +0 -1
  140. package/dist/cli/index.d.ts.map +0 -1
  141. package/dist/cli/index.js.map +0 -1
  142. package/dist/cli/init.d.ts.map +0 -1
  143. package/dist/cli/init.js.map +0 -1
  144. package/dist/cli/migrate.d.ts.map +0 -1
  145. package/dist/cli/migrate.js.map +0 -1
  146. package/dist/cli/report.d.ts.map +0 -1
  147. package/dist/cli/report.js.map +0 -1
  148. package/dist/cli/reporters.d.ts.map +0 -1
  149. package/dist/cli/reporters.js.map +0 -1
  150. package/dist/cli/safe-path.d.ts.map +0 -1
  151. package/dist/cli/safe-path.js.map +0 -1
  152. package/dist/cli/translate.d.ts.map +0 -1
  153. package/dist/cli/translate.js.map +0 -1
  154. package/dist/client/dev-overlay-gate.d.ts.map +0 -1
  155. package/dist/client/dev-overlay-gate.js.map +0 -1
  156. package/dist/client/dev-overlay.d.ts.map +0 -1
  157. package/dist/client/dev-overlay.js.map +0 -1
  158. package/dist/client/dev-registry.d.ts.map +0 -1
  159. package/dist/client/dev-registry.js.map +0 -1
  160. package/dist/client/editor-url.d.ts.map +0 -1
  161. package/dist/client/editor-url.js.map +0 -1
  162. package/dist/client/index.d.ts.map +0 -1
  163. package/dist/client/index.js.map +0 -1
  164. package/dist/compiler/ast.d.ts.map +0 -1
  165. package/dist/compiler/ast.js.map +0 -1
  166. package/dist/compiler/build.d.ts.map +0 -1
  167. package/dist/compiler/build.js.map +0 -1
  168. package/dist/compiler/codegen/emit-js.d.ts.map +0 -1
  169. package/dist/compiler/codegen/emit-js.js.map +0 -1
  170. package/dist/compiler/codegen/emit-types.d.ts.map +0 -1
  171. package/dist/compiler/codegen/emit-types.js.map +0 -1
  172. package/dist/compiler/fallback.d.ts.map +0 -1
  173. package/dist/compiler/fallback.js.map +0 -1
  174. package/dist/compiler/index.d.ts.map +0 -1
  175. package/dist/compiler/index.js.map +0 -1
  176. package/dist/compiler/json-locations.d.ts.map +0 -1
  177. package/dist/compiler/json-locations.js.map +0 -1
  178. package/dist/compiler/load-messages.d.ts.map +0 -1
  179. package/dist/compiler/load-messages.js.map +0 -1
  180. package/dist/compiler/parse/icu-parser.d.ts.map +0 -1
  181. package/dist/compiler/parse/icu-parser.js.map +0 -1
  182. package/dist/compiler/pseudo.d.ts.map +0 -1
  183. package/dist/compiler/pseudo.js.map +0 -1
  184. package/dist/compiler/scan-keys.d.ts.map +0 -1
  185. package/dist/compiler/scan-keys.js.map +0 -1
  186. package/dist/compiler/scan-routes.d.ts.map +0 -1
  187. package/dist/compiler/scan-routes.js.map +0 -1
  188. package/dist/compiler/sources.d.ts.map +0 -1
  189. package/dist/compiler/sources.js.map +0 -1
  190. package/dist/compiler/validate/a11y.d.ts.map +0 -1
  191. package/dist/compiler/validate/a11y.js.map +0 -1
  192. package/dist/compiler/validate/bidi.d.ts.map +0 -1
  193. package/dist/compiler/validate/bidi.js.map +0 -1
  194. package/dist/compiler/validate/catalog.d.ts.map +0 -1
  195. package/dist/compiler/validate/catalog.js.map +0 -1
  196. package/dist/compiler/validate/length.d.ts.map +0 -1
  197. package/dist/compiler/validate/length.js.map +0 -1
  198. package/dist/compiler/validate/plurals.d.ts.map +0 -1
  199. package/dist/compiler/validate/plurals.js.map +0 -1
  200. package/dist/compiler/validate/usage.d.ts.map +0 -1
  201. package/dist/compiler/validate/usage.js.map +0 -1
  202. package/dist/config/define-config.d.ts.map +0 -1
  203. package/dist/config/define-config.js.map +0 -1
  204. package/dist/config/index.d.ts.map +0 -1
  205. package/dist/config/index.js.map +0 -1
  206. package/dist/config/load-config.d.ts.map +0 -1
  207. package/dist/config/load-config.js.map +0 -1
  208. package/dist/config/types.d.ts.map +0 -1
  209. package/dist/config/types.js.map +0 -1
  210. package/dist/config/validate.d.ts.map +0 -1
  211. package/dist/config/validate.js.map +0 -1
  212. package/dist/errors.d.ts.map +0 -1
  213. package/dist/errors.js.map +0 -1
  214. package/dist/index.d.ts.map +0 -1
  215. package/dist/index.js.map +0 -1
  216. package/dist/navigation/index.d.ts.map +0 -1
  217. package/dist/navigation/index.js.map +0 -1
  218. package/dist/navigation/locale-switcher.d.ts.map +0 -1
  219. package/dist/navigation/locale-switcher.js.map +0 -1
  220. package/dist/navigation/pathname.d.ts.map +0 -1
  221. package/dist/navigation/pathname.js.map +0 -1
  222. package/dist/next/index.d.ts.map +0 -1
  223. package/dist/next/index.js.map +0 -1
  224. package/dist/next/loader.d.ts.map +0 -1
  225. package/dist/next/loader.js.map +0 -1
  226. package/dist/next/watcher.d.ts.map +0 -1
  227. package/dist/next/watcher.js.map +0 -1
  228. package/dist/next/with-tongue.d.ts.map +0 -1
  229. package/dist/next/with-tongue.js.map +0 -1
  230. package/dist/proxy/index.d.ts.map +0 -1
  231. package/dist/proxy/index.js.map +0 -1
  232. package/dist/proxy/locale-matcher.d.ts.map +0 -1
  233. package/dist/proxy/locale-matcher.js.map +0 -1
  234. package/dist/runtime/create-t.d.ts.map +0 -1
  235. package/dist/runtime/create-t.js.map +0 -1
  236. package/dist/runtime/format-message.d.ts.map +0 -1
  237. package/dist/runtime/format-message.js.map +0 -1
  238. package/dist/runtime/format.d.ts.map +0 -1
  239. package/dist/runtime/format.js.map +0 -1
  240. package/dist/runtime/locale-preference.d.ts.map +0 -1
  241. package/dist/runtime/locale-preference.js.map +0 -1
  242. package/dist/runtime/locale.d.ts.map +0 -1
  243. package/dist/runtime/locale.js.map +0 -1
  244. package/dist/runtime/lru.d.ts.map +0 -1
  245. package/dist/runtime/lru.js.map +0 -1
  246. package/dist/runtime/rich.d.ts.map +0 -1
  247. package/dist/runtime/rich.js.map +0 -1
  248. package/dist/runtime/sanctioned-units.d.ts.map +0 -1
  249. package/dist/runtime/sanctioned-units.js.map +0 -1
  250. package/dist/runtime/translate-issues.d.ts.map +0 -1
  251. package/dist/runtime/translate-issues.js.map +0 -1
  252. package/dist/server/alternates.d.ts.map +0 -1
  253. package/dist/server/alternates.js.map +0 -1
  254. package/dist/server/index.d.ts.map +0 -1
  255. package/dist/server/index.js.map +0 -1
  256. package/dist/server/locale-preference.d.ts.map +0 -1
  257. package/dist/server/locale-preference.js.map +0 -1
  258. package/dist/testing/index.d.ts.map +0 -1
  259. package/dist/testing/index.js.map +0 -1
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Louis Wright
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,90 @@
1
+ # next-tongue
2
+
3
+ **Compiler-first, type-safe i18n for the Next.js 16 App Router.** Works with Turbopack, keeps the locale in route params, zero dependencies beyond `next` and `react`.
4
+
5
+ [![npm](https://img.shields.io/npm/v/next-tongue.svg)](https://www.npmjs.com/package/next-tongue)
6
+ [![license: MIT](https://img.shields.io/badge/license-MIT-blue)](./LICENSE)
7
+
8
+ > **Beta 0.9** — public API is frozen. See [API freeze](https://github.com/MrLouisWright/next-tongue/blob/main/docs/api-freeze.md).
9
+
10
+ ## Install
11
+
12
+ ```bash
13
+ npm install next-tongue
14
+ npx tongue init
15
+ ```
16
+
17
+ Requires **Next.js ≥ 16** (App Router) and **React ≥ 19**.
18
+
19
+ ## Quick start
20
+
21
+ ```ts
22
+ // tongue.config.ts
23
+ import { defineConfig } from 'next-tongue/config';
24
+
25
+ export default defineConfig({
26
+ locales: ['en', 'de'],
27
+ defaultLocale: 'en',
28
+ messages: './messages/{locale}.json',
29
+ });
30
+ ```
31
+
32
+ ```ts
33
+ // next.config.ts
34
+ import { withTongue } from 'next-tongue/next';
35
+
36
+ export default withTongue({ cacheComponents: true });
37
+ ```
38
+
39
+ ```ts
40
+ // proxy.ts — locales + defaultLocale are required
41
+ import { createProxy } from 'next-tongue/proxy';
42
+
43
+ export const proxy = createProxy({
44
+ locales: ['en', 'de'],
45
+ defaultLocale: 'en',
46
+ prefix: 'as-needed',
47
+ });
48
+ export const config = { matcher: ['/((?!api|_next|.*\\..*).*)'] };
49
+ ```
50
+
51
+ ```tsx
52
+ // app/[locale]/page.tsx
53
+ import { getT } from 'next-tongue/server';
54
+
55
+ export default async function Page({
56
+ params,
57
+ }: {
58
+ params: Promise<{ locale: string }>;
59
+ }) {
60
+ const { locale } = await params;
61
+ const t = await getT(locale, 'home');
62
+ return <h1>{t('title')}</h1>;
63
+ }
64
+ ```
65
+
66
+ ## Package exports
67
+
68
+ | Import | Use |
69
+ |---|---|
70
+ | `next-tongue/config` | `defineConfig` |
71
+ | `next-tongue/next` | `withTongue` |
72
+ | `next-tongue/server` | `getT`, `getFormat`, `localeParams`, … |
73
+ | `next-tongue/client` | `TongueProvider`, `useT`, … |
74
+ | `next-tongue/proxy` | `createProxy` |
75
+ | `next-tongue/navigation` | `createNavigation` |
76
+ | `next-tongue/testing` | test helpers |
77
+
78
+ CLI: `tongue build | check | extract | init | export | import | report | translate | migrate`
79
+
80
+ ## Docs
81
+
82
+ - [Getting started](https://github.com/MrLouisWright/next-tongue/blob/main/docs/getting-started.md)
83
+ - [Configuration](https://github.com/MrLouisWright/next-tongue/blob/main/docs/configuration.md)
84
+ - [CLI](https://github.com/MrLouisWright/next-tongue/blob/main/docs/cli.md)
85
+ - [Migration from next-intl](https://github.com/MrLouisWright/next-tongue/blob/main/docs/migration/next-intl.md)
86
+ - [Roadmap](https://github.com/MrLouisWright/next-tongue/blob/main/ROADMAP.md)
87
+
88
+ ## License
89
+
90
+ MIT © Louis Wright
@@ -14,4 +14,3 @@ export type CheckResult = {
14
14
  errorCount: number;
15
15
  warningCount: number;
16
16
  };
17
- //# sourceMappingURL=check-types.d.ts.map
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=check-types.js.map
@@ -7,4 +7,3 @@ export type CheckCliOptions = {
7
7
  quiet?: boolean;
8
8
  };
9
9
  export declare function cmdCheck(opts: CheckCliOptions): Promise<void>;
10
- //# sourceMappingURL=check.d.ts.map
package/dist/cli/check.js CHANGED
@@ -57,4 +57,3 @@ export async function cmdCheck(opts) {
57
57
  process.exitCode = 1;
58
58
  }
59
59
  }
60
- //# sourceMappingURL=check.js.map
@@ -29,4 +29,3 @@ export declare function csvToUnits(raw: string): Unit[];
29
29
  export declare function unitsToXliff(units: Unit[], srcLang: string, trgLang: string): string;
30
30
  export declare function xliffToUnits(raw: string): Unit[];
31
31
  export {};
32
- //# sourceMappingURL=export-import.d.ts.map
@@ -420,4 +420,3 @@ function unescapeXml(s) {
420
420
  .replace(/&quot;/g, '"')
421
421
  .replace(/&amp;/g, '&');
422
422
  }
423
- //# sourceMappingURL=export-import.js.map
@@ -10,4 +10,3 @@ export type ExtractCliOptions = {
10
10
  quiet?: boolean;
11
11
  };
12
12
  export declare function cmdExtract(opts: ExtractCliOptions): Promise<void>;
13
- //# sourceMappingURL=extract.d.ts.map
@@ -157,4 +157,3 @@ function confirm(prompt) {
157
157
  });
158
158
  });
159
159
  }
160
- //# sourceMappingURL=extract.js.map
@@ -1,2 +1 @@
1
1
  export declare function runCli(argv: string[]): Promise<void>;
2
- //# sourceMappingURL=index.d.ts.map
package/dist/cli/index.js CHANGED
@@ -280,4 +280,3 @@ Usage:
280
280
  Exit codes: 0 ok, 1 check/build failures, 2 usage/config error
281
281
  `);
282
282
  }
283
- //# sourceMappingURL=index.js.map
@@ -10,4 +10,10 @@ export type InitCliOptions = {
10
10
  quiet?: boolean;
11
11
  };
12
12
  export declare function cmdInit(opts: InitCliOptions): Promise<void>;
13
- //# sourceMappingURL=init.d.ts.map
13
+ /** Prefer src/app when present; otherwise app/. */
14
+ export declare function detectAppRoot(cwd: string): Promise<'app' | 'src/app'>;
15
+ /**
16
+ * Where to write proxy.ts. Returns null when the project already has proxy/middleware
17
+ * (caller should compose manually).
18
+ */
19
+ export declare function detectProxyPath(cwd: string, appRoot: 'app' | 'src/app'): Promise<string | null>;
package/dist/cli/init.js CHANGED
@@ -31,6 +31,9 @@ export async function cmdInit(opts) {
31
31
  process.exitCode = 2;
32
32
  return;
33
33
  }
34
+ const appRoot = await detectAppRoot(cwd);
35
+ const hasRootLayout = await hasFile(cwd, `${appRoot}/layout.tsx`, `${appRoot}/layout.ts`, `${appRoot}/layout.jsx`, `${appRoot}/layout.js`);
36
+ const proxyPath = await detectProxyPath(cwd, appRoot);
34
37
  const plans = [];
35
38
  plans.push({
36
39
  path: 'tongue.config.ts',
@@ -46,68 +49,38 @@ export default defineConfig({
46
49
  `,
47
50
  });
48
51
  for (const locale of locales) {
49
- const sample = locale === defaultLocale
50
- ? {
51
- home: {
52
- title: 'Welcome, {name}!',
53
- body: 'Scaffolded by tongue init.',
54
- },
55
- }
56
- : {
57
- home: {
58
- title: 'Welcome, {name}!',
59
- body: 'Scaffolded by tongue init.',
60
- },
61
- };
52
+ const sample = {
53
+ home: {
54
+ title: 'Welcome, {name}!',
55
+ body: 'Scaffolded by tongue init.',
56
+ },
57
+ };
62
58
  plans.push({
63
59
  path: `messages/${locale}.json`,
64
60
  kind: 'create',
65
61
  content: `${JSON.stringify(sample, null, 2)}\n`,
66
62
  });
67
63
  }
64
+ if (proxyPath) {
65
+ plans.push({
66
+ path: proxyPath,
67
+ kind: 'create',
68
+ content: proxyScaffold(locales, defaultLocale, prefix),
69
+ });
70
+ }
71
+ else if (!opts.quiet) {
72
+ console.log('tongue init: existing proxy/middleware detected — compose createProxy({ locales, defaultLocale, … }) yourself (see docs/routing-and-proxy.md).');
73
+ }
74
+ const layoutPath = `${appRoot}/[locale]/layout.tsx`;
68
75
  plans.push({
69
- path: 'proxy.ts',
76
+ path: layoutPath,
70
77
  kind: 'create',
71
- content: `import { createProxy } from 'next-tongue/proxy';
72
-
73
- export const proxy = createProxy();
74
- export const config = {
75
- matcher: ['/((?!api|_next|.*\\\\..*).*)'],
76
- };
77
- `,
78
+ content: hasRootLayout
79
+ ? nestedLocaleLayout()
80
+ : rootLocaleLayout(),
78
81
  });
79
82
  plans.push({
80
- path: 'app/[locale]/layout.tsx',
81
- kind: 'create',
82
- content: `import { notFound } from 'next/navigation';
83
- import { TongueProvider } from 'next-tongue/client';
84
- import { getDir, isLocale, localeParams } from 'next-tongue/server';
85
- import { ensureTongue } from '#tongue/runtime';
86
-
87
- ensureTongue();
88
- export const generateStaticParams = localeParams;
89
-
90
- export default async function RootLayout({
91
- children,
92
- params,
93
- }: {
94
- children: React.ReactNode;
95
- params: Promise<{ locale: string }>;
96
- }) {
97
- const { locale } = await params;
98
- if (!isLocale(locale)) notFound();
99
- return (
100
- <html lang={locale} dir={getDir(locale)}>
101
- <body>
102
- <TongueProvider locale={locale}>{children}</TongueProvider>
103
- </body>
104
- </html>
105
- );
106
- }
107
- `,
108
- });
109
- plans.push({
110
- path: 'app/[locale]/page.tsx',
83
+ path: `${appRoot}/[locale]/page.tsx`,
111
84
  kind: 'create',
112
85
  content: `import { getT } from 'next-tongue/server';
113
86
  import { ensureTongue } from '#tongue/runtime';
@@ -160,7 +133,7 @@ export default withTongue(nextConfig);
160
133
  `,
161
134
  });
162
135
  }
163
- // tsconfig include
136
+ // tsconfig: include + paths for #tongue/* (tsc does not resolve package.json imports)
164
137
  if (await exists(join(cwd, 'tsconfig.json'))) {
165
138
  const abs = join(cwd, 'tsconfig.json');
166
139
  const raw = await readFile(abs, 'utf8');
@@ -169,6 +142,12 @@ export default withTongue(nextConfig);
169
142
  const include = new Set(ts.include ?? ['**/*.ts', '**/*.tsx']);
170
143
  include.add('.tongue/types.d.ts');
171
144
  ts.include = [...include];
145
+ ts.compilerOptions = ts.compilerOptions ?? {};
146
+ const paths = { ...(ts.compilerOptions.paths ?? {}) };
147
+ if (!paths['#tongue/*']) {
148
+ paths['#tongue/*'] = ['./.tongue/*'];
149
+ }
150
+ ts.compilerOptions.paths = paths;
172
151
  const next = `${JSON.stringify(ts, null, 2)}\n`;
173
152
  if (next !== raw) {
174
153
  plans.push({ path: 'tsconfig.json', kind: 'merge', content: next });
@@ -242,9 +221,114 @@ export default withTongue(nextConfig);
242
221
  }
243
222
  }
244
223
  if (!opts.quiet) {
224
+ if (hasRootLayout) {
225
+ console.log('tongue init: existing root layout detected — set <html lang={locale} dir={…}> on the root layout (or a client HtmlLang), not under [locale].');
226
+ }
245
227
  console.log('tongue init: done. Run `npx tongue build` (or start next) so `.tongue/` is generated.');
246
228
  }
247
229
  }
230
+ function proxyScaffold(locales, defaultLocale, prefix) {
231
+ return `import { createProxy } from 'next-tongue/proxy';
232
+
233
+ // locales/defaultLocale must match tongue.config.ts (or import from '#tongue/runtime' after \`tongue build\`).
234
+ export const proxy = createProxy({
235
+ locales: ${JSON.stringify(locales)},
236
+ defaultLocale: ${JSON.stringify(defaultLocale)},
237
+ prefix: ${JSON.stringify(prefix)},
238
+ });
239
+
240
+ export const config = {
241
+ matcher: ['/((?!api|_next|.*\\\\..*).*)'],
242
+ };
243
+ `;
244
+ }
245
+ /** Greenfield: [locale] is the root layout and owns <html>. */
246
+ function rootLocaleLayout() {
247
+ return `import { notFound } from 'next/navigation';
248
+ import { TongueProvider } from 'next-tongue/client';
249
+ import { getDir, isLocale, localeParams } from 'next-tongue/server';
250
+ import { ensureTongue } from '#tongue/runtime';
251
+
252
+ ensureTongue();
253
+ export const generateStaticParams = localeParams;
254
+
255
+ export default async function LocaleLayout({
256
+ children,
257
+ params,
258
+ }: {
259
+ children: React.ReactNode;
260
+ params: Promise<{ locale: string }>;
261
+ }) {
262
+ const { locale } = await params;
263
+ if (!isLocale(locale)) notFound();
264
+ return (
265
+ <html lang={locale} dir={getDir(locale)}>
266
+ <body>
267
+ <TongueProvider locale={locale}>{children}</TongueProvider>
268
+ </body>
269
+ </html>
270
+ );
271
+ }
272
+ `;
273
+ }
274
+ /**
275
+ * App already has app/layout.tsx — Next only allows <html> there.
276
+ * [locale] layout wraps children only.
277
+ */
278
+ function nestedLocaleLayout() {
279
+ return `import { notFound } from 'next/navigation';
280
+ import { TongueProvider } from 'next-tongue/client';
281
+ import { isLocale, localeParams } from 'next-tongue/server';
282
+ import { ensureTongue } from '#tongue/runtime';
283
+
284
+ ensureTongue();
285
+ export const generateStaticParams = localeParams;
286
+
287
+ export default async function LocaleLayout({
288
+ children,
289
+ params,
290
+ }: {
291
+ children: React.ReactNode;
292
+ params: Promise<{ locale: string }>;
293
+ }) {
294
+ const { locale } = await params;
295
+ if (!isLocale(locale)) notFound();
296
+ // Keep html lang/dir on the root layout (or sync via a client helper).
297
+ return <TongueProvider locale={locale}>{children}</TongueProvider>;
298
+ }
299
+ `;
300
+ }
301
+ /** Prefer src/app when present; otherwise app/. */
302
+ export async function detectAppRoot(cwd) {
303
+ if (await exists(join(cwd, 'src', 'app')))
304
+ return 'src/app';
305
+ if (await exists(join(cwd, 'app')))
306
+ return 'app';
307
+ if (await exists(join(cwd, 'src')))
308
+ return 'src/app';
309
+ return 'app';
310
+ }
311
+ /**
312
+ * Where to write proxy.ts. Returns null when the project already has proxy/middleware
313
+ * (caller should compose manually).
314
+ */
315
+ export async function detectProxyPath(cwd, appRoot) {
316
+ const existing = [
317
+ 'proxy.ts',
318
+ 'proxy.js',
319
+ 'src/proxy.ts',
320
+ 'src/proxy.js',
321
+ 'middleware.ts',
322
+ 'middleware.js',
323
+ 'src/middleware.ts',
324
+ 'src/middleware.js',
325
+ ];
326
+ for (const p of existing) {
327
+ if (await exists(join(cwd, p)))
328
+ return null;
329
+ }
330
+ return appRoot.startsWith('src/') ? 'src/proxy.ts' : 'proxy.ts';
331
+ }
248
332
  function wrapNextConfig(src, staticExport) {
249
333
  let out = src;
250
334
  if (!/withTongue/.test(out)) {
@@ -258,6 +342,13 @@ function wrapNextConfig(src, staticExport) {
258
342
  }
259
343
  return out;
260
344
  }
345
+ async function hasFile(cwd, ...rels) {
346
+ for (const rel of rels) {
347
+ if (await exists(join(cwd, rel)))
348
+ return true;
349
+ }
350
+ return false;
351
+ }
261
352
  async function exists(path) {
262
353
  try {
263
354
  await access(path);
@@ -280,4 +371,3 @@ function ask(prompt, fallback) {
280
371
  });
281
372
  });
282
373
  }
283
- //# sourceMappingURL=init.js.map
@@ -33,4 +33,3 @@ export declare function transformNextIntl(source: string, _file: string): {
33
33
  };
34
34
  /** Heuristic: `locale` is a binding from params, props, or a nearby const. */
35
35
  export declare function hasLocaleInScope(source: string): boolean;
36
- //# sourceMappingURL=migrate.d.ts.map
@@ -200,4 +200,3 @@ async function walkSource(dir) {
200
200
  await walk(dir);
201
201
  return out;
202
202
  }
203
- //# sourceMappingURL=migrate.js.map
@@ -15,4 +15,3 @@ export type RouteReport = {
15
15
  };
16
16
  export declare function cmdReport(opts: ReportCliOptions): Promise<void>;
17
17
  export declare function parseMaxBytes(raw: string): number;
18
- //# sourceMappingURL=report.d.ts.map
@@ -140,4 +140,3 @@ export function parseMaxBytes(raw) {
140
140
  return Math.round(n * 1024 * 1024);
141
141
  return Math.round(n);
142
142
  }
143
- //# sourceMappingURL=report.js.map
@@ -4,4 +4,3 @@ export declare function reportPretty(result: CheckResult): void;
4
4
  export declare function reportJson(result: CheckResult): void;
5
5
  /** GitHub Actions workflow commands. */
6
6
  export declare function reportGithub(result: CheckResult): void;
7
- //# sourceMappingURL=reporters.d.ts.map
@@ -53,4 +53,3 @@ function escapeProp(s) {
53
53
  function escapeData(s) {
54
54
  return s.replace(/%/g, '%25').replace(/\r/g, '%0D').replace(/\n/g, '%0A');
55
55
  }
56
- //# sourceMappingURL=reporters.js.map
@@ -3,4 +3,3 @@
3
3
  * Used by every CLI write path (ADR threat model / v0.9 CLI security review).
4
4
  */
5
5
  export declare function resolveInsideProject(cwd: string, target: string): string;
6
- //# sourceMappingURL=safe-path.d.ts.map
@@ -13,4 +13,3 @@ export function resolveInsideProject(cwd, target) {
13
13
  }
14
14
  return abs;
15
15
  }
16
- //# sourceMappingURL=safe-path.js.map
@@ -23,4 +23,3 @@ export declare function maskIcu(source: string): {
23
23
  export declare function estimateTokens(text: string): number;
24
24
  export declare function cmdTranslate(opts: TranslateCliOptions): Promise<void>;
25
25
  export declare function validateParity(source: string, target: string, locale: string): void;
26
- //# sourceMappingURL=translate.d.ts.map
@@ -409,4 +409,3 @@ function setNested(root, fullKey, value) {
409
409
  }
410
410
  cur[parts[parts.length - 1]] = value;
411
411
  }
412
- //# sourceMappingURL=translate.js.map
@@ -8,4 +8,3 @@ export declare function DevOverlayGate({ locale, timeZone, editor, }: {
8
8
  timeZone: string;
9
9
  editor?: string;
10
10
  }): ReactNode;
11
- //# sourceMappingURL=dev-overlay-gate.d.ts.map
@@ -11,4 +11,3 @@ installTongueDevReporter();
11
11
  export function DevOverlayGate({ locale, timeZone, editor, }) {
12
12
  return (_jsx(DevOverlay, { locale: locale, timeZone: timeZone, ...(editor != null ? { editor } : {}) }));
13
13
  }
14
- //# sourceMappingURL=dev-overlay-gate.js.map
@@ -10,4 +10,3 @@ export type DevOverlayProps = {
10
10
  * Toggle with Alt+Shift+T.
11
11
  */
12
12
  export declare function DevOverlay({ locale, timeZone, editor, }: DevOverlayProps): ReactNode;
13
- //# sourceMappingURL=dev-overlay.d.ts.map
@@ -116,4 +116,3 @@ function Section({ title, children, }) {
116
116
  function Empty() {
117
117
  return _jsx("p", { style: { margin: 0, opacity: 0.55 }, children: "\u2014" });
118
118
  }
119
- //# sourceMappingURL=dev-overlay.js.map
@@ -46,4 +46,3 @@ export declare function getTongueDevSnapshot(): Snapshot;
46
46
  export declare function __resetTongueDev(): void;
47
47
  export declare function lookupRenderedByText(text: string): DevRendered | undefined;
48
48
  export {};
49
- //# sourceMappingURL=dev-registry.d.ts.map
@@ -99,4 +99,3 @@ export function lookupRenderedByText(text) {
99
99
  }
100
100
  return undefined;
101
101
  }
102
- //# sourceMappingURL=dev-registry.js.map
@@ -8,4 +8,3 @@ export declare function parseSourceRef(src: string | undefined): {
8
8
  file: string;
9
9
  line: number;
10
10
  } | null;
11
- //# sourceMappingURL=editor-url.d.ts.map
@@ -30,4 +30,3 @@ export function parseSourceRef(src) {
30
30
  return null;
31
31
  return { file: m[1], line: Number(m[2]) };
32
32
  }
33
- //# sourceMappingURL=editor-url.js.map
@@ -41,4 +41,3 @@ export type { SanctionedUnit, SimpleUnit, DisplayNameType, } from '../runtime/fo
41
41
  export { isSanctionedUnit, SIMPLE_UNITS } from '../runtime/format.js';
42
42
  export { translateIssues, defaultFormatPath, } from '../runtime/translate-issues.js';
43
43
  export type { TranslateIssue, TranslateIssuesOptions, IssuePathSegment, } from '../runtime/translate-issues.js';
44
- //# sourceMappingURL=index.d.ts.map
@@ -96,4 +96,3 @@ export const defaultLocale = {
96
96
  };
97
97
  export { isSanctionedUnit, SIMPLE_UNITS } from '../runtime/format.js';
98
98
  export { translateIssues, defaultFormatPath, } from '../runtime/translate-issues.js';
99
- //# sourceMappingURL=index.js.map
@@ -96,4 +96,3 @@ export type ArgKind = {
96
96
  };
97
97
  export type InferredArgs = Record<string, ArgKind>;
98
98
  export declare function collectArgs(ast: MessageAst, into?: InferredArgs): InferredArgs;
99
- //# sourceMappingURL=ast.d.ts.map
@@ -63,4 +63,3 @@ function mergeArg(into, name, next) {
63
63
  if (rank[next.kind] > rank[prev.kind])
64
64
  into[name] = next;
65
65
  }
66
- //# sourceMappingURL=ast.js.map
@@ -16,4 +16,3 @@ export declare function buildMessages(options: BuildOptions): Promise<BuildResul
16
16
  /** Locales written into message modules / types (includes pseudo when enabled). */
17
17
  export declare function localesForEmit(config: ResolvedTongueConfig): readonly string[];
18
18
  export declare function ensureDir(path: string): Promise<void>;
19
- //# sourceMappingURL=build.d.ts.map
@@ -434,4 +434,3 @@ function summarizeConfig(config) {
434
434
  export async function ensureDir(path) {
435
435
  await mkdir(dirname(path), { recursive: true });
436
436
  }
437
- //# sourceMappingURL=build.js.map
@@ -28,4 +28,3 @@ export declare function emitRichMessageFunction(exportName: string, ast: Message
28
28
  export declare function hasTags(ast: MessageAst): boolean;
29
29
  /** Safe JS identifier from a message key. */
30
30
  export declare function safeIdent(key: string): string;
31
- //# sourceMappingURL=emit-js.d.ts.map
@@ -349,4 +349,3 @@ export function safeIdent(key) {
349
349
  return `_${cleaned}`;
350
350
  return cleaned || '_';
351
351
  }
352
- //# sourceMappingURL=emit-js.js.map
@@ -5,4 +5,3 @@ export declare function emitTypesFile(opts: {
5
5
  namespaces: NamespaceTypes;
6
6
  pathnames?: string[];
7
7
  }): string;
8
- //# sourceMappingURL=emit-types.d.ts.map
@@ -52,4 +52,3 @@ function argsToType(args) {
52
52
  });
53
53
  return `{ ${fields.join('; ')} }`;
54
54
  }
55
- //# sourceMappingURL=emit-types.js.map
@@ -4,4 +4,3 @@
4
4
  */
5
5
  export declare function cldrParents(locale: string): string[];
6
6
  export declare function resolveFallbackChain(locale: string, defaultLocale: string, explicit: Partial<Record<string, string>>): string[];
7
- //# sourceMappingURL=fallback.d.ts.map
@@ -40,4 +40,3 @@ export function resolveFallbackChain(locale, defaultLocale, explicit) {
40
40
  }
41
41
  return chain;
42
42
  }
43
- //# sourceMappingURL=fallback.js.map
@@ -8,4 +8,3 @@ export { resolveFallbackChain, cldrParents } from './fallback.js';
8
8
  export { pluralCategoriesFor, checkPluralCategories } from './validate/plurals.js';
9
9
  export { emitMessageFunction, safeIdent } from './codegen/emit-js.js';
10
10
  export { emitTypesFile } from './codegen/emit-types.js';
11
- //# sourceMappingURL=index.d.ts.map
@@ -6,4 +6,3 @@ export { resolveFallbackChain, cldrParents } from './fallback.js';
6
6
  export { pluralCategoriesFor, checkPluralCategories } from './validate/plurals.js';
7
7
  export { emitMessageFunction, safeIdent } from './codegen/emit-js.js';
8
8
  export { emitTypesFile } from './codegen/emit-types.js';
9
- //# sourceMappingURL=index.js.map
@@ -3,4 +3,3 @@
3
3
  * Used for overlay click-to-key (`file:line`).
4
4
  */
5
5
  export declare function locateMessageKeys(raw: string, flatKeys: Iterable<string>): Record<string, number>;
6
- //# sourceMappingURL=json-locations.d.ts.map
@@ -119,4 +119,3 @@ export function locateMessageKeys(raw, flatKeys) {
119
119
  parseObject();
120
120
  return out;
121
121
  }
122
- //# sourceMappingURL=json-locations.js.map