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.
- package/LICENSE +21 -0
- package/README.md +90 -0
- package/dist/cli/check-types.d.ts +0 -1
- package/dist/cli/check-types.js +0 -1
- package/dist/cli/check.d.ts +0 -1
- package/dist/cli/check.js +0 -1
- package/dist/cli/export-import.d.ts +0 -1
- package/dist/cli/export-import.js +0 -1
- package/dist/cli/extract.d.ts +0 -1
- package/dist/cli/extract.js +0 -1
- package/dist/cli/index.d.ts +0 -1
- package/dist/cli/index.js +0 -1
- package/dist/cli/init.d.ts +7 -1
- package/dist/cli/init.js +144 -54
- package/dist/cli/migrate.d.ts +0 -1
- package/dist/cli/migrate.js +0 -1
- package/dist/cli/report.d.ts +0 -1
- package/dist/cli/report.js +0 -1
- package/dist/cli/reporters.d.ts +0 -1
- package/dist/cli/reporters.js +0 -1
- package/dist/cli/safe-path.d.ts +0 -1
- package/dist/cli/safe-path.js +0 -1
- package/dist/cli/translate.d.ts +0 -1
- package/dist/cli/translate.js +0 -1
- package/dist/client/dev-overlay-gate.d.ts +0 -1
- package/dist/client/dev-overlay-gate.js +0 -1
- package/dist/client/dev-overlay.d.ts +0 -1
- package/dist/client/dev-overlay.js +0 -1
- package/dist/client/dev-registry.d.ts +0 -1
- package/dist/client/dev-registry.js +0 -1
- package/dist/client/editor-url.d.ts +0 -1
- package/dist/client/editor-url.js +0 -1
- package/dist/client/index.d.ts +0 -1
- package/dist/client/index.js +0 -1
- package/dist/compiler/ast.d.ts +0 -1
- package/dist/compiler/ast.js +0 -1
- package/dist/compiler/build.d.ts +0 -1
- package/dist/compiler/build.js +0 -1
- package/dist/compiler/codegen/emit-js.d.ts +0 -1
- package/dist/compiler/codegen/emit-js.js +0 -1
- package/dist/compiler/codegen/emit-types.d.ts +0 -1
- package/dist/compiler/codegen/emit-types.js +0 -1
- package/dist/compiler/fallback.d.ts +0 -1
- package/dist/compiler/fallback.js +0 -1
- package/dist/compiler/index.d.ts +0 -1
- package/dist/compiler/index.js +0 -1
- package/dist/compiler/json-locations.d.ts +0 -1
- package/dist/compiler/json-locations.js +0 -1
- package/dist/compiler/load-messages.d.ts +0 -1
- package/dist/compiler/load-messages.js +0 -1
- package/dist/compiler/parse/icu-parser.d.ts +0 -1
- package/dist/compiler/parse/icu-parser.js +0 -1
- package/dist/compiler/pseudo.d.ts +0 -1
- package/dist/compiler/pseudo.js +0 -1
- package/dist/compiler/scan-keys.d.ts +0 -1
- package/dist/compiler/scan-keys.js +0 -1
- package/dist/compiler/scan-routes.d.ts +0 -1
- package/dist/compiler/scan-routes.js +0 -1
- package/dist/compiler/sources.d.ts +0 -1
- package/dist/compiler/sources.js +0 -1
- package/dist/compiler/validate/a11y.d.ts +7 -3
- package/dist/compiler/validate/a11y.js +99 -36
- package/dist/compiler/validate/bidi.d.ts +0 -1
- package/dist/compiler/validate/bidi.js +0 -1
- package/dist/compiler/validate/catalog.d.ts +0 -1
- package/dist/compiler/validate/catalog.js +0 -1
- package/dist/compiler/validate/length.d.ts +0 -1
- package/dist/compiler/validate/length.js +0 -1
- package/dist/compiler/validate/plurals.d.ts +0 -1
- package/dist/compiler/validate/plurals.js +0 -1
- package/dist/compiler/validate/usage.d.ts +0 -1
- package/dist/compiler/validate/usage.js +0 -1
- package/dist/config/define-config.d.ts +0 -1
- package/dist/config/define-config.js +0 -1
- package/dist/config/index.d.ts +0 -1
- package/dist/config/index.js +0 -1
- package/dist/config/load-config.d.ts +0 -1
- package/dist/config/load-config.js +0 -1
- package/dist/config/types.d.ts +0 -1
- package/dist/config/types.js +0 -1
- package/dist/config/validate.d.ts +0 -1
- package/dist/config/validate.js +0 -1
- package/dist/errors.d.ts +0 -1
- package/dist/errors.js +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/navigation/index.d.ts +0 -1
- package/dist/navigation/index.js +0 -1
- package/dist/navigation/locale-switcher.d.ts +0 -1
- package/dist/navigation/locale-switcher.js +0 -1
- package/dist/navigation/pathname.d.ts +0 -1
- package/dist/navigation/pathname.js +0 -1
- package/dist/next/index.d.ts +0 -1
- package/dist/next/index.js +0 -1
- package/dist/next/loader.d.ts +0 -1
- package/dist/next/loader.js +0 -1
- package/dist/next/watcher.d.ts +0 -1
- package/dist/next/watcher.js +0 -1
- package/dist/next/with-tongue.d.ts +0 -1
- package/dist/next/with-tongue.js +12 -4
- package/dist/proxy/index.d.ts +0 -1
- package/dist/proxy/index.js +0 -1
- package/dist/proxy/locale-matcher.d.ts +0 -1
- package/dist/proxy/locale-matcher.js +0 -1
- package/dist/runtime/create-t.d.ts +0 -1
- package/dist/runtime/create-t.js +0 -1
- package/dist/runtime/format-message.d.ts +0 -1
- package/dist/runtime/format-message.js +0 -1
- package/dist/runtime/format.d.ts +0 -1
- package/dist/runtime/format.js +0 -1
- package/dist/runtime/locale-preference.d.ts +0 -1
- package/dist/runtime/locale-preference.js +0 -1
- package/dist/runtime/locale.d.ts +0 -1
- package/dist/runtime/locale.js +0 -1
- package/dist/runtime/lru.d.ts +0 -1
- package/dist/runtime/lru.js +0 -1
- package/dist/runtime/rich.d.ts +0 -1
- package/dist/runtime/rich.js +0 -1
- package/dist/runtime/sanctioned-units.d.ts +0 -1
- package/dist/runtime/sanctioned-units.js +0 -1
- package/dist/runtime/translate-issues.d.ts +0 -1
- package/dist/runtime/translate-issues.js +0 -1
- package/dist/server/alternates.d.ts +0 -1
- package/dist/server/alternates.js +0 -1
- package/dist/server/index.d.ts +0 -1
- package/dist/server/index.js +0 -1
- package/dist/server/locale-preference.d.ts +0 -1
- package/dist/server/locale-preference.js +0 -1
- package/dist/testing/index.d.ts +0 -1
- package/dist/testing/index.js +0 -1
- package/package.json +27 -2
- package/dist/cli/check-types.d.ts.map +0 -1
- package/dist/cli/check-types.js.map +0 -1
- package/dist/cli/check.d.ts.map +0 -1
- package/dist/cli/check.js.map +0 -1
- package/dist/cli/export-import.d.ts.map +0 -1
- package/dist/cli/export-import.js.map +0 -1
- package/dist/cli/extract.d.ts.map +0 -1
- package/dist/cli/extract.js.map +0 -1
- package/dist/cli/index.d.ts.map +0 -1
- package/dist/cli/index.js.map +0 -1
- package/dist/cli/init.d.ts.map +0 -1
- package/dist/cli/init.js.map +0 -1
- package/dist/cli/migrate.d.ts.map +0 -1
- package/dist/cli/migrate.js.map +0 -1
- package/dist/cli/report.d.ts.map +0 -1
- package/dist/cli/report.js.map +0 -1
- package/dist/cli/reporters.d.ts.map +0 -1
- package/dist/cli/reporters.js.map +0 -1
- package/dist/cli/safe-path.d.ts.map +0 -1
- package/dist/cli/safe-path.js.map +0 -1
- package/dist/cli/translate.d.ts.map +0 -1
- package/dist/cli/translate.js.map +0 -1
- package/dist/client/dev-overlay-gate.d.ts.map +0 -1
- package/dist/client/dev-overlay-gate.js.map +0 -1
- package/dist/client/dev-overlay.d.ts.map +0 -1
- package/dist/client/dev-overlay.js.map +0 -1
- package/dist/client/dev-registry.d.ts.map +0 -1
- package/dist/client/dev-registry.js.map +0 -1
- package/dist/client/editor-url.d.ts.map +0 -1
- package/dist/client/editor-url.js.map +0 -1
- package/dist/client/index.d.ts.map +0 -1
- package/dist/client/index.js.map +0 -1
- package/dist/compiler/ast.d.ts.map +0 -1
- package/dist/compiler/ast.js.map +0 -1
- package/dist/compiler/build.d.ts.map +0 -1
- package/dist/compiler/build.js.map +0 -1
- package/dist/compiler/codegen/emit-js.d.ts.map +0 -1
- package/dist/compiler/codegen/emit-js.js.map +0 -1
- package/dist/compiler/codegen/emit-types.d.ts.map +0 -1
- package/dist/compiler/codegen/emit-types.js.map +0 -1
- package/dist/compiler/fallback.d.ts.map +0 -1
- package/dist/compiler/fallback.js.map +0 -1
- package/dist/compiler/index.d.ts.map +0 -1
- package/dist/compiler/index.js.map +0 -1
- package/dist/compiler/json-locations.d.ts.map +0 -1
- package/dist/compiler/json-locations.js.map +0 -1
- package/dist/compiler/load-messages.d.ts.map +0 -1
- package/dist/compiler/load-messages.js.map +0 -1
- package/dist/compiler/parse/icu-parser.d.ts.map +0 -1
- package/dist/compiler/parse/icu-parser.js.map +0 -1
- package/dist/compiler/pseudo.d.ts.map +0 -1
- package/dist/compiler/pseudo.js.map +0 -1
- package/dist/compiler/scan-keys.d.ts.map +0 -1
- package/dist/compiler/scan-keys.js.map +0 -1
- package/dist/compiler/scan-routes.d.ts.map +0 -1
- package/dist/compiler/scan-routes.js.map +0 -1
- package/dist/compiler/sources.d.ts.map +0 -1
- package/dist/compiler/sources.js.map +0 -1
- package/dist/compiler/validate/a11y.d.ts.map +0 -1
- package/dist/compiler/validate/a11y.js.map +0 -1
- package/dist/compiler/validate/bidi.d.ts.map +0 -1
- package/dist/compiler/validate/bidi.js.map +0 -1
- package/dist/compiler/validate/catalog.d.ts.map +0 -1
- package/dist/compiler/validate/catalog.js.map +0 -1
- package/dist/compiler/validate/length.d.ts.map +0 -1
- package/dist/compiler/validate/length.js.map +0 -1
- package/dist/compiler/validate/plurals.d.ts.map +0 -1
- package/dist/compiler/validate/plurals.js.map +0 -1
- package/dist/compiler/validate/usage.d.ts.map +0 -1
- package/dist/compiler/validate/usage.js.map +0 -1
- package/dist/config/define-config.d.ts.map +0 -1
- package/dist/config/define-config.js.map +0 -1
- package/dist/config/index.d.ts.map +0 -1
- package/dist/config/index.js.map +0 -1
- package/dist/config/load-config.d.ts.map +0 -1
- package/dist/config/load-config.js.map +0 -1
- package/dist/config/types.d.ts.map +0 -1
- package/dist/config/types.js.map +0 -1
- package/dist/config/validate.d.ts.map +0 -1
- package/dist/config/validate.js.map +0 -1
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/navigation/index.d.ts.map +0 -1
- package/dist/navigation/index.js.map +0 -1
- package/dist/navigation/locale-switcher.d.ts.map +0 -1
- package/dist/navigation/locale-switcher.js.map +0 -1
- package/dist/navigation/pathname.d.ts.map +0 -1
- package/dist/navigation/pathname.js.map +0 -1
- package/dist/next/index.d.ts.map +0 -1
- package/dist/next/index.js.map +0 -1
- package/dist/next/loader.d.ts.map +0 -1
- package/dist/next/loader.js.map +0 -1
- package/dist/next/watcher.d.ts.map +0 -1
- package/dist/next/watcher.js.map +0 -1
- package/dist/next/with-tongue.d.ts.map +0 -1
- package/dist/next/with-tongue.js.map +0 -1
- package/dist/proxy/index.d.ts.map +0 -1
- package/dist/proxy/index.js.map +0 -1
- package/dist/proxy/locale-matcher.d.ts.map +0 -1
- package/dist/proxy/locale-matcher.js.map +0 -1
- package/dist/runtime/create-t.d.ts.map +0 -1
- package/dist/runtime/create-t.js.map +0 -1
- package/dist/runtime/format-message.d.ts.map +0 -1
- package/dist/runtime/format-message.js.map +0 -1
- package/dist/runtime/format.d.ts.map +0 -1
- package/dist/runtime/format.js.map +0 -1
- package/dist/runtime/locale-preference.d.ts.map +0 -1
- package/dist/runtime/locale-preference.js.map +0 -1
- package/dist/runtime/locale.d.ts.map +0 -1
- package/dist/runtime/locale.js.map +0 -1
- package/dist/runtime/lru.d.ts.map +0 -1
- package/dist/runtime/lru.js.map +0 -1
- package/dist/runtime/rich.d.ts.map +0 -1
- package/dist/runtime/rich.js.map +0 -1
- package/dist/runtime/sanctioned-units.d.ts.map +0 -1
- package/dist/runtime/sanctioned-units.js.map +0 -1
- package/dist/runtime/translate-issues.d.ts.map +0 -1
- package/dist/runtime/translate-issues.js.map +0 -1
- package/dist/server/alternates.d.ts.map +0 -1
- package/dist/server/alternates.js.map +0 -1
- package/dist/server/index.d.ts.map +0 -1
- package/dist/server/index.js.map +0 -1
- package/dist/server/locale-preference.d.ts.map +0 -1
- package/dist/server/locale-preference.js.map +0 -1
- package/dist/testing/index.d.ts.map +0 -1
- 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
|
+
[](https://www.npmjs.com/package/next-tongue)
|
|
6
|
+
[](./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
|
package/dist/cli/check-types.js
CHANGED
package/dist/cli/check.d.ts
CHANGED
package/dist/cli/check.js
CHANGED
|
@@ -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
|
package/dist/cli/extract.d.ts
CHANGED
package/dist/cli/extract.js
CHANGED
package/dist/cli/index.d.ts
CHANGED
package/dist/cli/index.js
CHANGED
package/dist/cli/init.d.ts
CHANGED
|
@@ -10,4 +10,10 @@ export type InitCliOptions = {
|
|
|
10
10
|
quiet?: boolean;
|
|
11
11
|
};
|
|
12
12
|
export declare function cmdInit(opts: InitCliOptions): Promise<void>;
|
|
13
|
-
|
|
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 =
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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:
|
|
76
|
+
path: layoutPath,
|
|
70
77
|
kind: 'create',
|
|
71
|
-
content:
|
|
72
|
-
|
|
73
|
-
|
|
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:
|
|
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
|
package/dist/cli/migrate.d.ts
CHANGED
|
@@ -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
|
package/dist/cli/migrate.js
CHANGED
package/dist/cli/report.d.ts
CHANGED
package/dist/cli/report.js
CHANGED
package/dist/cli/reporters.d.ts
CHANGED
|
@@ -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
|
package/dist/cli/reporters.js
CHANGED
package/dist/cli/safe-path.d.ts
CHANGED
package/dist/cli/safe-path.js
CHANGED
package/dist/cli/translate.d.ts
CHANGED
|
@@ -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
|
package/dist/cli/translate.js
CHANGED
package/dist/client/index.d.ts
CHANGED
|
@@ -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
|
package/dist/client/index.js
CHANGED
package/dist/compiler/ast.d.ts
CHANGED
package/dist/compiler/ast.js
CHANGED
package/dist/compiler/build.d.ts
CHANGED
|
@@ -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
|
package/dist/compiler/build.js
CHANGED
|
@@ -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
|
package/dist/compiler/index.d.ts
CHANGED
|
@@ -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
|
package/dist/compiler/index.js
CHANGED
|
@@ -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
|