@better-intl/react 0.1.0 → 0.1.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.
Files changed (2) hide show
  1. package/README.md +89 -0
  2. package/package.json +4 -3
package/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # @better-intl/react
2
+
3
+ React bindings for **better-intl** — Provider, hooks, `<T>` component.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @better-intl/react @better-intl/core
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Provider
14
+
15
+ Wrap your app with `IntlProvider`:
16
+
17
+ ```tsx
18
+ import { IntlProvider } from "@better-intl/react";
19
+ import messages from "../locales/pt-BR.json";
20
+
21
+ function App() {
22
+ return (
23
+ <IntlProvider locale="pt-BR" messages={messages}>
24
+ <MyApp />
25
+ </IntlProvider>
26
+ );
27
+ }
28
+ ```
29
+
30
+ ### useTranslation hook
31
+
32
+ ```tsx
33
+ import { useTranslation } from "@better-intl/react";
34
+
35
+ function Greeting() {
36
+ const { t, locale } = useTranslation();
37
+
38
+ return (
39
+ <div>
40
+ <h1>{t("greeting", { name: "Alice" })}</h1>
41
+ <p>Current locale: {locale}</p>
42
+ </div>
43
+ );
44
+ }
45
+ ```
46
+
47
+ ### `<T>` component
48
+
49
+ For explicit marking of translatable text:
50
+
51
+ ```tsx
52
+ import { T } from "@better-intl/react";
53
+
54
+ function Hero() {
55
+ return (
56
+ <section>
57
+ <T>Hello world</T>
58
+ <T values={{ name: "Alice" }}>Hello {name}</T>
59
+ </section>
60
+ );
61
+ }
62
+ ```
63
+
64
+ ### Interpolation
65
+
66
+ Supports ICU-lite — variables, plurals, and select:
67
+
68
+ ```tsx
69
+ const { t } = useTranslation();
70
+
71
+ t("greeting", { name: "Alice" }); // "Hello Alice"
72
+ t("items", { count: 3 }); // "3 items"
73
+ t("pronoun", { gender: "female" }); // "She"
74
+ ```
75
+
76
+ ## API
77
+
78
+ | Export | Description |
79
+ |--------|-------------|
80
+ | `IntlProvider` | Context provider — pass `locale` and `messages` |
81
+ | `useTranslation()` | Returns `{ t, locale }` |
82
+ | `useIntlContext()` | Returns the raw `IntlRuntime` |
83
+ | `useTranslationRuntime(id, values?, default?)` | Low-level accessor used by compiler |
84
+ | `T` | Explicit translation component |
85
+ | `IntlContext` | React Context (for advanced use) |
86
+
87
+ ## License
88
+
89
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@better-intl/react",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "React bindings for better-intl — Provider, hooks, <T> component",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -14,10 +14,11 @@
14
14
  }
15
15
  },
16
16
  "files": [
17
- "dist"
17
+ "dist",
18
+ "README.md"
18
19
  ],
19
20
  "dependencies": {
20
- "@better-intl/core": "0.1.0"
21
+ "@better-intl/core": "0.1.1"
21
22
  },
22
23
  "peerDependencies": {
23
24
  "react": "^19.0.0"