@better-i18n/next 0.2.0 → 0.2.2

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 (2) hide show
  1. package/README.md +82 -25
  2. package/package.json +2 -3
package/README.md CHANGED
@@ -1,11 +1,20 @@
1
1
  # @better-i18n/next
2
2
 
3
- Next.js integration for [Better i18n](https://better-i18n.com). Handles `next-intl` wiring, middleware, and CDN-based translation fetching.
3
+ Next.js integration for [Better i18n](https://better-i18n.com). Provides seamless `next-intl` integration with CDN-powered translation fetching.
4
4
 
5
- ## Install
5
+ ## Features
6
+
7
+ - **Zero-Config Sync** - Connects to your project via `i18n.config.ts`
8
+ - **Edge-Ready Caching** - Built-in ISR support for manifest and messages
9
+ - **Type-Safe** - Full TypeScript support
10
+ - **next-intl First** - Designed as a message provider for `next-intl`
11
+
12
+ ## Installation
6
13
 
7
14
  ```bash
8
- npm i @better-i18n/next next-intl
15
+ npm install @better-i18n/next next-intl
16
+ # or
17
+ bun add @better-i18n/next next-intl
9
18
  ```
10
19
 
11
20
  ## Quick Start
@@ -13,21 +22,20 @@ npm i @better-i18n/next next-intl
13
22
  ### 1. Create i18n config
14
23
 
15
24
  ```ts
16
- // i18n.ts
25
+ // i18n.config.ts
17
26
  import { createI18n } from "@better-i18n/next";
18
27
 
19
28
  export const i18n = createI18n({
20
- project: "your-org/your-project", // Format: "org-slug/project-slug"
29
+ project: "your-org/your-project", // Format: "org-slug/project-slug"
21
30
  defaultLocale: "en",
22
- debug: process.env.NODE_ENV !== "production",
23
31
  });
24
32
  ```
25
33
 
26
34
  ### 2. Setup request config
27
35
 
28
36
  ```ts
29
- // app/i18n/request.ts
30
- import { i18n } from "./i18n";
37
+ // src/i18n/request.ts
38
+ import { i18n } from "../i18n.config";
31
39
 
32
40
  export default i18n.requestConfig;
33
41
  ```
@@ -36,15 +44,49 @@ export default i18n.requestConfig;
36
44
 
37
45
  ```ts
38
46
  // middleware.ts
39
- import { i18n } from "./i18n";
47
+ import { i18n } from "./i18n.config";
40
48
 
41
49
  export default i18n.middleware;
42
50
 
43
51
  export const config = {
44
- matcher: ["/", "/((?!api|_next|_vercel|.*\\..*).*)" ],
52
+ matcher: ["/((?!api|_next|.*\\..*).*)"],
45
53
  };
46
54
  ```
47
55
 
56
+ ### 4. Use translations
57
+
58
+ ```tsx
59
+ // app/page.tsx
60
+ import { useTranslations } from "next-intl";
61
+
62
+ export default function Home() {
63
+ const t = useTranslations("common");
64
+ return <h1>{t("welcome")}</h1>;
65
+ }
66
+ ```
67
+
68
+ ## Advanced Middleware
69
+
70
+ For more control, use `createBetterI18nMiddleware`:
71
+
72
+ ```ts
73
+ import { createBetterI18nMiddleware, composeMiddleware } from "@better-i18n/next/middleware";
74
+
75
+ const i18nMiddleware = createBetterI18nMiddleware({
76
+ project: "org/project",
77
+ defaultLocale: "en",
78
+ detection: {
79
+ cookie: true,
80
+ browserLanguage: true,
81
+ cookieName: "locale",
82
+ cookieMaxAge: 31536000, // 1 year
83
+ },
84
+ });
85
+
86
+ // Compose with other middleware
87
+ export default composeMiddleware(i18nMiddleware, authMiddleware);
88
+ ```
89
+
48
90
  ## Client Hook
49
91
 
50
92
  ```tsx
@@ -58,46 +100,61 @@ export function LanguageSwitcher() {
58
100
  defaultLocale: "en",
59
101
  });
60
102
 
61
- if (error) throw error;
62
- if (isLoading) return null;
103
+ if (isLoading) return <span>Loading...</span>;
104
+ if (error) return <span>Error: {error.message}</span>;
63
105
 
64
106
  return (
65
- <ul>
107
+ <select>
66
108
  {languages.map((lang) => (
67
- <li key={lang.code}>{lang.nativeName ?? lang.code}</li>
109
+ <option key={lang.code} value={lang.code}>
110
+ {lang.nativeName || lang.name || lang.code}
111
+ </option>
68
112
  ))}
69
- </ul>
113
+ </select>
70
114
  );
71
115
  }
72
116
  ```
73
117
 
74
- ## Server Helpers
118
+ ## Server Utilities
75
119
 
76
120
  ```ts
77
- import { getLocales, getMessages } from "@better-i18n/next/server";
121
+ import {
122
+ getMessages,
123
+ getLocales,
124
+ getManifestLanguages,
125
+ } from "@better-i18n/next/server";
78
126
 
79
- const config = { project: "your-org/your-project", defaultLocale: "en" };
127
+ const config = { project: "org/project", defaultLocale: "en" };
80
128
 
81
129
  const locales = await getLocales(config);
82
130
  const messages = await getMessages(config, "tr");
131
+ const languages = await getManifestLanguages(config);
83
132
  ```
84
133
 
85
134
  ## Configuration Options
86
135
 
87
- | Option | Type | Description |
88
- |--------|------|-------------|
89
- | `project` | `string` | **Required.** Format: `"org-slug/project-slug"` |
90
- | `defaultLocale` | `string` | **Required.** Default locale code (e.g., `"en"`) |
91
- | `cdnBaseUrl` | `string` | CDN URL (default: `https://cdn.better-i18n.com`) |
92
- | `debug` | `boolean` | Enable verbose logging |
93
- | `localePrefix` | `"as-needed" \| "always" \| "never"` | URL prefix strategy |
136
+ | Option | Type | Default | Description |
137
+ |--------|------|---------|-------------|
138
+ | `project` | `string` | required | Project identifier (`org/project` format) |
139
+ | `defaultLocale` | `string` | required | Default/fallback locale code |
140
+ | `cdnBaseUrl` | `string` | auto | CDN base URL (auto-detected) |
141
+ | `localePrefix` | `"as-needed"` \| `"always"` \| `"never"` | `"as-needed"` | URL locale prefix behavior |
142
+ | `manifestRevalidateSeconds` | `number` | `3600` | Next.js ISR revalidation for manifest |
143
+ | `messagesRevalidateSeconds` | `number` | `30` | Next.js ISR revalidation for messages |
144
+ | `debug` | `boolean` | `false` | Enable debug logging |
145
+ | `logLevel` | `LogLevel` | `"warn"` | Logging verbosity |
94
146
 
95
147
  ## Debug Logging
96
148
 
97
149
  Enable with environment variables:
150
+
98
151
  - `BETTER_I18N_DEBUG=1`
99
152
  - `BETTER_I18N_LOG_LEVEL=debug|info|warn|error|silent`
100
153
 
154
+ ## Documentation
155
+
156
+ Full documentation available at [docs.better-i18n.com/next](https://docs.better-i18n.com/docs/next)
157
+
101
158
  ## License
102
159
 
103
160
  MIT © [Better i18n](https://better-i18n.com)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@better-i18n/next",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Better-i18n Next.js integration",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -57,7 +57,7 @@
57
57
  "typecheck": "tsc --noEmit"
58
58
  },
59
59
  "dependencies": {
60
- "@better-i18n/core": "workspace:*"
60
+ "@better-i18n/core": "0.1.3"
61
61
  },
62
62
  "peerDependencies": {
63
63
  "next": ">=15.0.0",
@@ -68,7 +68,6 @@
68
68
  "devDependencies": {
69
69
  "next": "^15.4.4",
70
70
  "next-intl": "^4.5.8",
71
- "@better-i18n/typescript-config": "workspace:*",
72
71
  "@types/node": "^20.0.0",
73
72
  "@types/react": "^19.0.0",
74
73
  "typescript": "~5.9.2"