kotori 3.0.0 → 3.0.2
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 +19 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -61,7 +61,7 @@ npm i kotori
|
|
|
61
61
|
**utils.ts**
|
|
62
62
|
|
|
63
63
|
```ts
|
|
64
|
-
import { kotori } from '
|
|
64
|
+
import { kotori } from 'kotori'
|
|
65
65
|
|
|
66
66
|
export const { useT, dict, setLanguage } = kotori({
|
|
67
67
|
primaryLanguageTag: 'en',
|
|
@@ -166,16 +166,29 @@ export const Page2 = () => {
|
|
|
166
166
|
|
|
167
167
|
Creates a scoped i18n instance.
|
|
168
168
|
|
|
169
|
+
```ts
|
|
170
|
+
import { kotori } from 'kotori'
|
|
171
|
+
|
|
172
|
+
export const { useT, dict, setLanguage } = kotori({
|
|
173
|
+
primaryLanguageTag: 'en',
|
|
174
|
+
secondaryLanguageTags: ['zh', 'ja', 'ms'],
|
|
175
|
+
})
|
|
176
|
+
```
|
|
177
|
+
|
|
169
178
|
| option | type | description |
|
|
170
179
|
| --- | --- | --- |
|
|
171
|
-
| `primaryLanguageTag` | `
|
|
172
|
-
| `secondaryLanguageTags` | `
|
|
180
|
+
| `primaryLanguageTag` | `BCP47LanguageTag` | The source language. Drives variable inference. |
|
|
181
|
+
| `secondaryLanguageTags` | `BCP47LanguageTag[]` | Additional supported languages. |
|
|
173
182
|
|
|
174
183
|
Returns `{ dict, useT, setLanguage }`.
|
|
175
184
|
|
|
176
|
-
### `dict(
|
|
185
|
+
### `dict(Record<primaryLanguageTag | secondaryLanguageTags, string>)<argsType?>`
|
|
186
|
+
|
|
187
|
+
Defines a translation unit. Takes one string per language.
|
|
177
188
|
|
|
178
|
-
|
|
189
|
+
```ts
|
|
190
|
+
const time = dict({ en: '{{hour}}:{{minute}}' })
|
|
191
|
+
```
|
|
179
192
|
|
|
180
193
|
By default, variables are typed as `string | number`. Pass a generic to narrow them:
|
|
181
194
|
|
|
@@ -198,7 +211,7 @@ React hook. Returns `{ t, language, setLanguage }`.
|
|
|
198
211
|
| --- | --- | --- |
|
|
199
212
|
| `t(dict, args?)` | `string` | Returns the translated string for the current language. `args` is required if the string has variables, omitted if it doesn't. |
|
|
200
213
|
| `language` | `primaryLanguageTag` \| `secondaryLanguageTags` | The current language tag as a reactive value. Updates when `setLanguage` is called. |
|
|
201
|
-
| `setLanguage(
|
|
214
|
+
| `setLanguage(primaryLanguageTag \| secondaryLanguageTags)` | `void` | Updates the language and rerenders all active `useT` consumers. |
|
|
202
215
|
|
|
203
216
|
## Language Tags
|
|
204
217
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kotori",
|
|
3
3
|
"description": "Strongly-typed and composable internationalization library for React",
|
|
4
|
-
"version": "3.0.
|
|
4
|
+
"version": "3.0.2",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"setup": "rm -rf node_modules && npm i && git init && husky",
|
|
7
7
|
"prepublishOnly": "npm i && npx tsc && npm run build",
|