canopy-i18n 0.9.0 → 0.9.1
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 +27 -1
- package/package.json +7 -2
package/README.md
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
# canopy-i18n
|
|
2
2
|
|
|
3
|
-
A tiny, type-safe i18n library for building localized messages with builder pattern and applying locales across nested data structures.
|
|
3
|
+
A tiny, type-safe i18n library for building localized messages with builder pattern and applying locales across nested data structures — with optional AI translation for missing locales and runtime user input.
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
|
+
- **AI translation**: Write only your source locale and let AI fill in the rest. Built-in OpenAI / Claude / Gemini adapters, runtime translation of user input with caching. See [AI Translation](#ai-translation).
|
|
6
7
|
- **AI-friendly**: Full type safety and single-file colocation give AI assistants complete context for accurate code generation.
|
|
7
8
|
- **Type-safe**: Compile-time safety for locale keys with full TypeScript IntelliSense support.
|
|
8
9
|
- **Flexible templating**: Plain functions support any JavaScript logic, template literals, or formatting library.
|
|
@@ -10,6 +11,8 @@ A tiny, type-safe i18n library for building localized messages with builder patt
|
|
|
10
11
|
- **React-ready**: Provider, hooks, and built-in source wrappers for URL hash / search param / pathname / localStorage / Cookie. See [React Integration](#react-integration).
|
|
11
12
|
|
|
12
13
|
> **Using React?** Jump straight to [React Integration](#react-integration) — the Provider, hooks, and ready-made source wrappers cover most app setups out of the box.
|
|
14
|
+
>
|
|
15
|
+
> **Tired of writing every locale by hand?** See [AI Translation](#ai-translation) — write `ja` only and let AI complete the rest, or translate user input at runtime.
|
|
13
16
|
## Why Canopy i18n?
|
|
14
17
|
|
|
15
18
|
Traditional i18n libraries require separate JSON files and string-based key lookups:
|
|
@@ -54,9 +57,32 @@ const messages = createI18n(['en', 'ja'] as const)
|
|
|
54
57
|
console.log(messages.welcome({ name: 'Alice' })); // "Welcome, Alice!"
|
|
55
58
|
```
|
|
56
59
|
|
|
60
|
+
**With AI translation** — write only your source locale:
|
|
61
|
+
```ts
|
|
62
|
+
import { createAITranslator, openAIAdapter, memoryCache } from 'canopy-i18n/ai';
|
|
63
|
+
|
|
64
|
+
const translator = createAITranslator({
|
|
65
|
+
adapter: openAIAdapter({ model: 'gpt-4o-mini', apiKey: process.env.OPENAI_API_KEY! }),
|
|
66
|
+
sourceLocale: 'ja',
|
|
67
|
+
cache: memoryCache(),
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const messages = createI18n(['ja', 'en'] as const)
|
|
71
|
+
.add(await translator.completeEntries(['ja', 'en'] as const, {
|
|
72
|
+
greeting: { ja: 'こんにちは' }, // en is filled in by AI
|
|
73
|
+
}))
|
|
74
|
+
.build('en');
|
|
75
|
+
|
|
76
|
+
console.log(messages.greeting()); // "Hello"
|
|
77
|
+
|
|
78
|
+
// It also translates dynamic text (e.g. user input) at runtime, with caching
|
|
79
|
+
await translator.translate(userComment, { to: 'en' });
|
|
80
|
+
```
|
|
81
|
+
|
|
57
82
|
**Benefits:**
|
|
58
83
|
- 🔒 **Type safety**: Typos caught at compile time, full autocomplete support
|
|
59
84
|
- 📁 **Colocation**: All translations in one place, no file jumping
|
|
85
|
+
- 🤖 **AI translation**: Missing locales and user input translated by AI — OpenAI / Claude / Gemini or your own adapter
|
|
60
86
|
- ⚡ **Zero config**: No loaders, plugins, or initialization required
|
|
61
87
|
- 🚀 **Framework agnostic**: Works anywhere JavaScript runs
|
|
62
88
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "canopy-i18n",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "The Type-Safe i18n library that your IDE will Love",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -72,7 +72,12 @@
|
|
|
72
72
|
"localization",
|
|
73
73
|
"l10n",
|
|
74
74
|
"messages",
|
|
75
|
-
"template"
|
|
75
|
+
"template",
|
|
76
|
+
"ai",
|
|
77
|
+
"translation",
|
|
78
|
+
"openai",
|
|
79
|
+
"claude",
|
|
80
|
+
"gemini"
|
|
76
81
|
],
|
|
77
82
|
"engines": {
|
|
78
83
|
"node": ">=20"
|