@koine/i18n 2.0.0-beta.130 → 2.0.0-beta.131

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.
@@ -3,8 +3,8 @@
3
3
  var getI18nDictionaries_inline = require('../../adapter-js/generators/getI18nDictionaries_inline.cjs.js');
4
4
  var createAdapter = require('../../compiler/createAdapter.cjs.js');
5
5
 
6
- var m = createAdapter.createGenerator("next", (t)=>{
7
- let { options: { routes: { localeParamName: e } } } = t;
6
+ var m = createAdapter.createGenerator("next", (o)=>{
7
+ let { options: { routes: { localeParamName: e } } } = o;
8
8
  return {
9
9
  I18nLayout: {
10
10
  dir: "server",
@@ -80,11 +80,15 @@ type Configurator = {
80
80
  * @example
81
81
  *
82
82
  * \`\`\`
83
+ *
84
+ * // 1) configure and create a layout
85
+ *
86
+ * // with a simple object
83
87
  * const layout = i18nServer.layout({
84
88
  * namespaces: ["dashboard"],
85
89
  * });
86
90
  *
87
- * // or as a function (async supported):
91
+ * // or with a function (async supported)
88
92
  * type Props = { params: { slug: string; }; };
89
93
  *
90
94
  * const layout = i18nServer.layout((props: Props, locale) => {
@@ -92,6 +96,47 @@ type Configurator = {
92
96
  * namespaces: ["dashboard"],
93
97
  * };
94
98
  * });
99
+ *
100
+ * // 2) export the metadata (maybe only in /app/${e})/layout.tsx)
101
+ *
102
+ * // with a sync function
103
+ * export const generateMetadata = layout.generateMetadata((props) => {
104
+ * return {};
105
+ * });
106
+ *
107
+ * // or an async function
108
+ * export const generateMetadata = layout.generateMetadata(async (props) => {
109
+ * return {};
110
+ * });
111
+ *
112
+ * // 3) export the default component
113
+ *
114
+ * // 3a) in /app/${e})/layout.tsx)
115
+ *
116
+ * // only thing to do is to spread the i18nHtmlAttrs prop on the <html> element
117
+ * export default layout.default((props) => {
118
+ * const { i18nHtmlAttrs, children } = props;
119
+ *
120
+ * return (
121
+ * <html {...i18nHtmlAttrs}>
122
+ * <head />
123
+ * <body>{children}</body>
124
+ * </html>
125
+ * );
126
+ * });
127
+ *
128
+ * // 3b) in /app/${e})/ ...folders... /layout.tsx)
129
+ *
130
+ * // with a sync function (if you do not need to await)
131
+ * export default layout.default((props) => {
132
+ * return <>{props.route.id} {props.locale}</>;
133
+ * });
134
+ *
135
+ * // or an sync function (if you need to await)
136
+ * export default layout.default(async (props) => {
137
+ * const data = await fetch(...);
138
+ * return <>{props.route.id} {props.locale}</>;
139
+ * });
95
140
  * \`\`\`
96
141
  */
97
142
  export const createI18nLayout = <
@@ -1,8 +1,8 @@
1
1
  import { getI18nDictionaries_inline } from '../../adapter-js/generators/getI18nDictionaries_inline.esm.js';
2
2
  import { createGenerator } from '../../compiler/createAdapter.esm.js';
3
3
 
4
- var m = createGenerator("next", (t)=>{
5
- let { options: { routes: { localeParamName: e } } } = t;
4
+ var m = createGenerator("next", (o)=>{
5
+ let { options: { routes: { localeParamName: e } } } = o;
6
6
  return {
7
7
  I18nLayout: {
8
8
  dir: "server",
@@ -78,11 +78,15 @@ type Configurator = {
78
78
  * @example
79
79
  *
80
80
  * \`\`\`
81
+ *
82
+ * // 1) configure and create a layout
83
+ *
84
+ * // with a simple object
81
85
  * const layout = i18nServer.layout({
82
86
  * namespaces: ["dashboard"],
83
87
  * });
84
88
  *
85
- * // or as a function (async supported):
89
+ * // or with a function (async supported)
86
90
  * type Props = { params: { slug: string; }; };
87
91
  *
88
92
  * const layout = i18nServer.layout((props: Props, locale) => {
@@ -90,6 +94,47 @@ type Configurator = {
90
94
  * namespaces: ["dashboard"],
91
95
  * };
92
96
  * });
97
+ *
98
+ * // 2) export the metadata (maybe only in /app/${e})/layout.tsx)
99
+ *
100
+ * // with a sync function
101
+ * export const generateMetadata = layout.generateMetadata((props) => {
102
+ * return {};
103
+ * });
104
+ *
105
+ * // or an async function
106
+ * export const generateMetadata = layout.generateMetadata(async (props) => {
107
+ * return {};
108
+ * });
109
+ *
110
+ * // 3) export the default component
111
+ *
112
+ * // 3a) in /app/${e})/layout.tsx)
113
+ *
114
+ * // only thing to do is to spread the i18nHtmlAttrs prop on the <html> element
115
+ * export default layout.default((props) => {
116
+ * const { i18nHtmlAttrs, children } = props;
117
+ *
118
+ * return (
119
+ * <html {...i18nHtmlAttrs}>
120
+ * <head />
121
+ * <body>{children}</body>
122
+ * </html>
123
+ * );
124
+ * });
125
+ *
126
+ * // 3b) in /app/${e})/ ...folders... /layout.tsx)
127
+ *
128
+ * // with a sync function (if you do not need to await)
129
+ * export default layout.default((props) => {
130
+ * return <>{props.route.id} {props.locale}</>;
131
+ * });
132
+ *
133
+ * // or an sync function (if you need to await)
134
+ * export default layout.default(async (props) => {
135
+ * const data = await fetch(...);
136
+ * return <>{props.route.id} {props.locale}</>;
137
+ * });
93
138
  * \`\`\`
94
139
  */
95
140
  export const createI18nLayout = <
@@ -183,8 +183,18 @@ type Configurator<TRouteId extends I18n.RouteId> = {
183
183
  * @example
184
184
  *
185
185
  * \`\`\`
186
- * type Props = { params: { slug: string; }; };
186
+ *
187
+ * // 1) configure and create a page
188
+ *
189
+ * // with a simple object
190
+ * const page = i18nServer.page({
191
+ * route: { id: "about" },
192
+ * namespaces: ["~about"],
193
+ * });
187
194
  *
195
+ * // or with a function (async supported)
196
+ * type Props = { params: { slug: string; }; };
197
+ *
188
198
  * const page = i18nServer.page((props: Props) => {
189
199
  * return {
190
200
  * route: { id: "collection.[slug]", params: { slug: props.params.slug } },
@@ -192,20 +202,26 @@ type Configurator<TRouteId extends I18n.RouteId> = {
192
202
  * };
193
203
  * });
194
204
  *
205
+ * // 2) export the metadata
206
+ *
207
+ * // with a sync function
195
208
  * export const generateMetadata = page.generateMetadata((props) => {
196
209
  * return {};
197
210
  * });
198
211
  *
199
- * // or async:
212
+ * // or an async function
200
213
  * export const generateMetadata = page.generateMetadata(async (props) => {
201
214
  * return {};
202
215
  * });
203
216
  *
217
+ * // 3) export the default component
218
+ *
219
+ * // with a sync function (if you do not need to await)
204
220
  * export default page.default((props) => {
205
221
  * return <>{props.route.id} {props.locale}</>;
206
222
  * });
207
223
  *
208
- * // or async:
224
+ * // or an sync function (if you need to await)
209
225
  * export default page.default(async (props) => {
210
226
  * const data = await fetch(...);
211
227
  * return <>{props.route.id} {props.locale}</>;
@@ -217,10 +233,12 @@ export const createI18nPage = <
217
233
  TRouteId extends I18n.RouteId,
218
234
  TConfig extends Configurator<TRouteId>,
219
235
  >(
220
- configurator: (
221
- props: I18n.Props<TProps>,
222
- locale: I18n.Locale,
223
- ) => TConfig | Promise<TConfig>,
236
+ configurator:
237
+ | ((
238
+ props: I18n.Props<TProps>,
239
+ locale: I18n.Locale,
240
+ ) => TConfig | Promise<TConfig>)
241
+ | TConfig,
224
242
  ) => {
225
243
  return {
226
244
  generateMetadata: (
@@ -181,8 +181,18 @@ type Configurator<TRouteId extends I18n.RouteId> = {
181
181
  * @example
182
182
  *
183
183
  * \`\`\`
184
- * type Props = { params: { slug: string; }; };
184
+ *
185
+ * // 1) configure and create a page
186
+ *
187
+ * // with a simple object
188
+ * const page = i18nServer.page({
189
+ * route: { id: "about" },
190
+ * namespaces: ["~about"],
191
+ * });
185
192
  *
193
+ * // or with a function (async supported)
194
+ * type Props = { params: { slug: string; }; };
195
+ *
186
196
  * const page = i18nServer.page((props: Props) => {
187
197
  * return {
188
198
  * route: { id: "collection.[slug]", params: { slug: props.params.slug } },
@@ -190,20 +200,26 @@ type Configurator<TRouteId extends I18n.RouteId> = {
190
200
  * };
191
201
  * });
192
202
  *
203
+ * // 2) export the metadata
204
+ *
205
+ * // with a sync function
193
206
  * export const generateMetadata = page.generateMetadata((props) => {
194
207
  * return {};
195
208
  * });
196
209
  *
197
- * // or async:
210
+ * // or an async function
198
211
  * export const generateMetadata = page.generateMetadata(async (props) => {
199
212
  * return {};
200
213
  * });
201
214
  *
215
+ * // 3) export the default component
216
+ *
217
+ * // with a sync function (if you do not need to await)
202
218
  * export default page.default((props) => {
203
219
  * return <>{props.route.id} {props.locale}</>;
204
220
  * });
205
221
  *
206
- * // or async:
222
+ * // or an sync function (if you need to await)
207
223
  * export default page.default(async (props) => {
208
224
  * const data = await fetch(...);
209
225
  * return <>{props.route.id} {props.locale}</>;
@@ -215,10 +231,12 @@ export const createI18nPage = <
215
231
  TRouteId extends I18n.RouteId,
216
232
  TConfig extends Configurator<TRouteId>,
217
233
  >(
218
- configurator: (
219
- props: I18n.Props<TProps>,
220
- locale: I18n.Locale,
221
- ) => TConfig | Promise<TConfig>,
234
+ configurator:
235
+ | ((
236
+ props: I18n.Props<TProps>,
237
+ locale: I18n.Locale,
238
+ ) => TConfig | Promise<TConfig>)
239
+ | TConfig,
222
240
  ) => {
223
241
  return {
224
242
  generateMetadata: (
package/package.json CHANGED
@@ -2,8 +2,8 @@
2
2
  "name": "@koine/i18n",
3
3
  "sideEffects": false,
4
4
  "dependencies": {
5
- "@koine/node": "2.0.0-beta.130",
6
- "@koine/utils": "2.0.0-beta.130",
5
+ "@koine/node": "2.0.0-beta.131",
6
+ "@koine/utils": "2.0.0-beta.131",
7
7
  "comment-json": "^4.2.4",
8
8
  "glob": "^10.3.10",
9
9
  "minimatch": "^9.0.3",
@@ -90,5 +90,5 @@
90
90
  "module": "./index.esm.js",
91
91
  "main": "./index.cjs.js",
92
92
  "types": "./index.esm.d.ts",
93
- "version": "2.0.0-beta.130"
93
+ "version": "2.0.0-beta.131"
94
94
  }