kotori 6.1.1 → 6.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 +13 -7
- package/dist/index.cjs +2 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +2 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -61,7 +61,7 @@ const Component = () => {
|
|
|
61
61
|
- Variables typed and inferred from string literals — no more string typos
|
|
62
62
|
- Maximum type safety with minimum types
|
|
63
63
|
|
|
64
|
-
Demo: <https://
|
|
64
|
+
Demo: <https://github.com/tylim88/kotori-demo>
|
|
65
65
|
|
|
66
66
|
## Installation
|
|
67
67
|
|
|
@@ -81,7 +81,7 @@ export const { useT, d, setLanguage } = kotori({
|
|
|
81
81
|
secondaries: ['zh', 'ja', 'ms'],
|
|
82
82
|
})
|
|
83
83
|
|
|
84
|
-
// you can define your dicts in the same file or separate them by component, it's up to you
|
|
84
|
+
// you can define your dicts in the same file/folder or separate them by component, it's up to you
|
|
85
85
|
export const intro = d({
|
|
86
86
|
en: 'my name is {{name}}, I am {{age}} years old.',
|
|
87
87
|
zh: '我叫{{name}},我今年{{age}}岁了。',
|
|
@@ -248,9 +248,16 @@ Detects the user's preferred language from browser settings and sets it on the k
|
|
|
248
248
|
|
|
249
249
|
```ts
|
|
250
250
|
import { detectLanguage } from 'kotori'
|
|
251
|
-
import {
|
|
251
|
+
import { kotori } from 'kotori'
|
|
252
|
+
|
|
253
|
+
const i18n = kotori({
|
|
254
|
+
primary: 'en',
|
|
255
|
+
secondaries: ['zh', 'ja', 'ms'],
|
|
256
|
+
})
|
|
252
257
|
|
|
253
258
|
detectLanguage(i18n)
|
|
259
|
+
|
|
260
|
+
export const { useT, d, setLanguage } = i18n
|
|
254
261
|
```
|
|
255
262
|
|
|
256
263
|
| option | type | default | description |
|
|
@@ -288,10 +295,9 @@ kotori({ primary: 'klingon', secondaries: ['zh'] }) // ❌ compile error
|
|
|
288
295
|
|
|
289
296
|
## Tips
|
|
290
297
|
|
|
291
|
-
- If you plan to add new languages frequently, consider colocating all your dicts in a single file or multiple files in one folder. It is easier to copy the entire
|
|
292
|
-
- If your supported languages are fixed, consider splitting dicts by page or component.
|
|
293
|
-
-
|
|
294
|
-
- The `primary` language is the source of truth for variable inference and validation. Write your primary language strings carefully — a variable rename in the primary string becomes a compile error across every secondary language, which is intentional.
|
|
298
|
+
- If you plan to add new languages frequently, consider colocating all your dicts in a single file or multiple files in one folder. It is easier to copy the entire files and hand it to an AI to translate.
|
|
299
|
+
- If your supported languages are fixed, consider splitting dicts by page or component. This keeps translations close to the code that uses them and makes them easier to maintain.
|
|
300
|
+
- For large or rarely used components, you can also reduce your bundle size by dynamically importing them only when they are needed on the page.
|
|
295
301
|
|
|
296
302
|
## Roadmap
|
|
297
303
|
|
package/dist/index.cjs
CHANGED
package/dist/index.d.cts
CHANGED
|
@@ -208,6 +208,8 @@ declare const kotori: <const Primary extends BCP47LanguageTagNameWithSubTag, con
|
|
|
208
208
|
*
|
|
209
209
|
* detectLanguage(i18n, { fallbackToSubtag: false })
|
|
210
210
|
* // browser: ['zh-CN'] → no exact match → no-op, stays 'en'
|
|
211
|
+
*
|
|
212
|
+
* export const { useT, d, setLanguage } = i18n
|
|
211
213
|
* ```
|
|
212
214
|
*
|
|
213
215
|
* @example
|
package/dist/index.d.mts
CHANGED
|
@@ -208,6 +208,8 @@ declare const kotori: <const Primary extends BCP47LanguageTagNameWithSubTag, con
|
|
|
208
208
|
*
|
|
209
209
|
* detectLanguage(i18n, { fallbackToSubtag: false })
|
|
210
210
|
* // browser: ['zh-CN'] → no exact match → no-op, stays 'en'
|
|
211
|
+
*
|
|
212
|
+
* export const { useT, d, setLanguage } = i18n
|
|
211
213
|
* ```
|
|
212
214
|
*
|
|
213
215
|
* @example
|
package/dist/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kotori",
|
|
3
|
-
"description": "0.
|
|
4
|
-
"version": "6.1.
|
|
3
|
+
"description": "0.29kB Strongly-typed and tree-shakeable internationalization library for React",
|
|
4
|
+
"version": "6.1.3",
|
|
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",
|