@cascivo/i18n 0.1.1 → 0.1.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/README.md +59 -5
- package/package.json +5 -5
- package/readme.body.md +43 -1
package/README.md
CHANGED
|
@@ -1,12 +1,64 @@
|
|
|
1
1
|
<!-- generated by scripts/readme/generate.ts — edit readme.body.md, not this file -->
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<div align="center">
|
|
4
|
+
<a href="https://cascivo.com"><img src="https://cascivo.com/favicon.svg" width="72" height="72" alt="cascivo logo"></a>
|
|
5
|
+
<h1>@cascivo/i18n</h1>
|
|
6
|
+
<p><strong>Signal-driven locale store, typed message catalogs, and Intl-based formatting for cascivo</strong></p>
|
|
4
7
|
|
|
5
|
-
|
|
8
|
+
[](https://www.npmjs.com/package/@cascivo/i18n)
|
|
9
|
+
[](https://www.npmjs.com/package/@cascivo/i18n)
|
|
10
|
+
[](https://github.com/cascivo/cascivo/blob/main/LICENSE)
|
|
11
|
+

|
|
6
12
|
|
|
7
|
-
[cascivo.com](https://cascivo.com) · [Docs](https://docs.cascivo.com) · [Storybook](https://storybook.cascivo.com) · [GitHub](https://github.com/
|
|
13
|
+
[npm](https://www.npmjs.com/package/@cascivo/i18n) · [cascivo.com](https://cascivo.com) · [Docs](https://docs.cascivo.com) · [Storybook](https://storybook.cascivo.com) · [GitHub](https://github.com/cascivo/cascivo)
|
|
8
14
|
|
|
9
|
-
|
|
15
|
+
</div>
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
A signal-driven internationalisation layer for cascivo — a reactive locale store, typed message catalogs, and `Intl`-based formatting. Every component reads its user-visible strings from the built-in catalog, so the whole system localizes from one place. Zero-config: with no setup, everything resolves against the default `'en'` locale.
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
```tsx
|
|
24
|
+
import { createLocale, t, builtin } from '@cascivo/i18n'
|
|
25
|
+
|
|
26
|
+
const i18n = createLocale({ default: 'en', supported: ['en', 'de'] })
|
|
27
|
+
i18n.registerCatalog('de', () => import('./catalogs/de'))
|
|
28
|
+
|
|
29
|
+
await i18n.set('de') // every subscribed component re-renders reactively
|
|
30
|
+
|
|
31
|
+
t(builtin.button.loading) // resolves against the active locale
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Because the active locale is a signal, changing it updates every component that reads a catalog string — no context provider, no re-mount. Catalogs are registered lazily and loaded on demand.
|
|
35
|
+
|
|
36
|
+
## Overriding strings per instance
|
|
37
|
+
|
|
38
|
+
Components default to the built-in catalog but accept a `labels` prop to override per-instance:
|
|
39
|
+
|
|
40
|
+
```tsx
|
|
41
|
+
<Pagination labels={{ next: 'Suivant', previous: 'Précédent' }} />
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Formatting
|
|
45
|
+
|
|
46
|
+
Typed helpers wrap the `Intl` APIs and follow the active locale:
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
import {
|
|
50
|
+
formatNumber,
|
|
51
|
+
formatDate,
|
|
52
|
+
formatRelativeTime,
|
|
53
|
+
formatList,
|
|
54
|
+
formatBytes,
|
|
55
|
+
} from '@cascivo/i18n'
|
|
56
|
+
|
|
57
|
+
formatNumber(1234.5, { style: 'currency', currency: 'EUR' })
|
|
58
|
+
formatRelativeTime(-2, 'day') // → "2 days ago" / "vor 2 Tagen"
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Define your own typed catalogs with `defineCatalog` / `defineMessages` for full type-safety on keys and interpolation values.
|
|
10
62
|
|
|
11
63
|
## Install
|
|
12
64
|
|
|
@@ -16,4 +68,6 @@ pnpm add @cascivo/i18n
|
|
|
16
68
|
|
|
17
69
|
---
|
|
18
70
|
|
|
19
|
-
[cascivo.com](https://cascivo.com) · [Docs](https://docs.cascivo.com) · [Storybook](https://storybook.cascivo.com) · [GitHub](https://github.com/
|
|
71
|
+
[cascivo.com](https://cascivo.com) · [Docs](https://docs.cascivo.com) · [Storybook](https://storybook.cascivo.com) · [GitHub](https://github.com/cascivo/cascivo) · AI agents: use [`@cascivo/mcp`](https://github.com/cascivo/cascivo/tree/main/packages/mcp) and [`registry.json`](https://github.com/cascivo/cascivo/blob/main/registry.json) · MIT
|
|
72
|
+
|
|
73
|
+
<div align="center"><a href="https://cascivo.com"><img src="https://cascivo.com/favicon.svg" width="28" height="28" alt="cascivo"></a></div>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cascivo/i18n",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Signal-driven locale store, typed message catalogs, and Intl-based formatting for cascivo",
|
|
6
6
|
"keywords": [
|
|
@@ -13,13 +13,13 @@
|
|
|
13
13
|
"react",
|
|
14
14
|
"signals"
|
|
15
15
|
],
|
|
16
|
-
"homepage": "https://github.com/
|
|
17
|
-
"bugs": "https://github.com/
|
|
16
|
+
"homepage": "https://github.com/cascivo/cascivo/tree/main/packages/i18n#readme",
|
|
17
|
+
"bugs": "https://github.com/cascivo/cascivo/issues",
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"author": "urbanisierung",
|
|
20
20
|
"repository": {
|
|
21
21
|
"type": "git",
|
|
22
|
-
"url": "git+https://github.com/
|
|
22
|
+
"url": "git+https://github.com/cascivo/cascivo.git",
|
|
23
23
|
"directory": "packages/i18n"
|
|
24
24
|
},
|
|
25
25
|
"files": [
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"provenance": true
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@cascivo/core": "^0.1.
|
|
42
|
+
"@cascivo/core": "^0.1.3"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@preact/signals-react": "^3",
|
package/readme.body.md
CHANGED
|
@@ -1 +1,43 @@
|
|
|
1
|
-
|
|
1
|
+
A signal-driven internationalisation layer for cascivo — a reactive locale store, typed message catalogs, and `Intl`-based formatting. Every component reads its user-visible strings from the built-in catalog, so the whole system localizes from one place. Zero-config: with no setup, everything resolves against the default `'en'` locale.
|
|
2
|
+
|
|
3
|
+
## Usage
|
|
4
|
+
|
|
5
|
+
```tsx
|
|
6
|
+
import { createLocale, t, builtin } from '@cascivo/i18n'
|
|
7
|
+
|
|
8
|
+
const i18n = createLocale({ default: 'en', supported: ['en', 'de'] })
|
|
9
|
+
i18n.registerCatalog('de', () => import('./catalogs/de'))
|
|
10
|
+
|
|
11
|
+
await i18n.set('de') // every subscribed component re-renders reactively
|
|
12
|
+
|
|
13
|
+
t(builtin.button.loading) // resolves against the active locale
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Because the active locale is a signal, changing it updates every component that reads a catalog string — no context provider, no re-mount. Catalogs are registered lazily and loaded on demand.
|
|
17
|
+
|
|
18
|
+
## Overriding strings per instance
|
|
19
|
+
|
|
20
|
+
Components default to the built-in catalog but accept a `labels` prop to override per-instance:
|
|
21
|
+
|
|
22
|
+
```tsx
|
|
23
|
+
<Pagination labels={{ next: 'Suivant', previous: 'Précédent' }} />
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Formatting
|
|
27
|
+
|
|
28
|
+
Typed helpers wrap the `Intl` APIs and follow the active locale:
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import {
|
|
32
|
+
formatNumber,
|
|
33
|
+
formatDate,
|
|
34
|
+
formatRelativeTime,
|
|
35
|
+
formatList,
|
|
36
|
+
formatBytes,
|
|
37
|
+
} from '@cascivo/i18n'
|
|
38
|
+
|
|
39
|
+
formatNumber(1234.5, { style: 'currency', currency: 'EUR' })
|
|
40
|
+
formatRelativeTime(-2, 'day') // → "2 days ago" / "vor 2 Tagen"
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Define your own typed catalogs with `defineCatalog` / `defineMessages` for full type-safety on keys and interpolation values.
|