canopy-i18n 0.0.3 → 0.0.5

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/README.md CHANGED
@@ -175,3 +175,20 @@ console.log(m.home.title.render()); // "Title"
175
175
  ```
176
176
 
177
177
  Note: Module namespace objects are read-only; `applyLocaleDeep` returns a cloned plain object while updating each `I18nMessage` instance's locale in place.
178
+
179
+ ## Example: Next.js App Router
180
+
181
+ An example Next.js App Router project lives under `examples/next-app`.
182
+
183
+ - Server-side usage: `/{locale}/server` renders messages using `applyLocaleDeep` in a server component
184
+ - Client-side usage: `/{locale}/client` renders messages using hooks (`useLocale`, `useApplyLocaleDeep`)
185
+
186
+ How to run:
187
+
188
+ ```bash
189
+ cd examples/next-app
190
+ pnpm install
191
+ pnpm dev
192
+ ```
193
+
194
+ Open `http://localhost:3000` and you will be redirected to `/{locale}` based on `Accept-Language`.
@@ -1,2 +1 @@
1
- export declare function applyLocaleDeep<T extends Record<string, unknown>>(obj: T, locale: string): T;
2
- export declare function applyLocaleDeep<T extends unknown[]>(obj: T, locale: string): T;
1
+ export declare function applyLocaleDeep<T extends object>(obj: T, locale: string): T;
package/dist/test.js CHANGED
@@ -7,4 +7,6 @@ for (const locale of ['ja', 'en']) {
7
7
  console.log(msg.render({ name: '田中', age: 20 }));
8
8
  console.log(title.render());
9
9
  console.log(nested.hello.render());
10
+ const hs = (0, index_1.applyLocaleDeep)(trs.hasSentMsg, locale);
11
+ console.log(hs.render({ email: 'test@example.com' }));
10
12
  }
@@ -7,3 +7,6 @@ export declare const nested: {
7
7
  hello: import("./message").LocalizedMessage<readonly ["ja", "en"], unknown>;
8
8
  world: import("./message").LocalizedMessage<readonly ["ja", "en"], unknown>;
9
9
  };
10
+ export declare const hasSentMsg: import("./message").LocalizedMessage<readonly ["ja", "en"], {
11
+ email: string;
12
+ }>;
package/dist/testData.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.nested = exports.msg = exports.title = void 0;
3
+ exports.hasSentMsg = exports.nested = exports.msg = exports.title = void 0;
4
4
  const index_1 = require("./index");
5
5
  const builder = (0, index_1.createMessageBuilder)(['ja', 'en'], 'ja');
6
6
  exports.title = builder({
@@ -21,3 +21,7 @@ exports.nested = {
21
21
  en: 'World'
22
22
  })
23
23
  };
24
+ exports.hasSentMsg = builder({
25
+ ja: o => `${o.email}にメールを送信しました。確認の上、処理を進めて下さい。`,
26
+ en: o => `Email sent to ${o.email}. Please check and proceed with the process.`
27
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "canopy-i18n",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "A tiny, type-safe i18n helper",
5
5
  "type": "commonjs",
6
6
  "main": "dist/index.js",