sheet-i18n 0.2.6-canary.2 → 0.2.6-canary.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.
Files changed (2) hide show
  1. package/README.md +44 -32
  2. package/package.json +4 -4
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # sheet-i18n
2
2
 
3
- **An all-in-one package for sheet-based translations.**
3
+ **An all-in-one package for sheet-based translation**
4
4
 
5
5
  [![npm](https://img.shields.io/npm/v/sheet-i18n)](https://www.npmjs.com/package/sheet-i18n)
6
6
  <a href="https://sheet-i18n.vercel.app/en" target="_blank">
@@ -20,10 +20,16 @@ npm install sheet-i18n
20
20
 
21
21
  ### 📑 Main Package - `sheet-i18n`
22
22
 
23
- This is the core package for sheet-based translations. You can use it to work with Google Sheets and export translations.
23
+ `sheet-i18n` is a **powerful and flexible library** designed to streamline the process of managing and utilizing translations stored in **Google Sheets** _(planned to support other spreadsheets soon)_.
24
24
 
25
- <details>
26
- <summary>📄 Server export function - sheet-i18n/exporter</summary>
25
+ It serves as a bridge between your translation data and your application, offering an **end-to-end solution** for exporting, managing, and integrating translations into your projects.
26
+
27
+ The `sheet-i18n` ecosystem is divided into two main packages:
28
+
29
+ ---
30
+
31
+ <details open>
32
+ <summary><h3>🌍 Server Export Function - sheet-i18n/exporter</h3></summary>
27
33
 
28
34
  #### `sheet-i18n/exporter`
29
35
 
@@ -139,8 +145,8 @@ The exported translations will be saved in a format that is easy to use for loca
139
145
 
140
146
  ---
141
147
 
142
- <details>
143
- <summary>📄 Client export function - sheet-i18n/react</summary>
148
+ <details open>
149
+ <summary><h3>⚛️ Frontend Translation Provider - sheet-i18n/react</h3></summary>
144
150
 
145
151
  #### `sheet-i18n/react`
146
152
 
@@ -150,19 +156,13 @@ This package provides tools to handle translations in React applications using c
150
156
 
151
157
  ## ✨ Package Introduction
152
158
 
153
- - **createI18nStore**: `Store Creation` for managing translation data.
154
- - **createI18nContext**: `React Context` to generate providers and hooks for translations.
155
- - **IntlProvider**: `Translation Provider` for managing current locale.
156
- - **useTranslation**: `Translation Hook` for easy access to translation messages.
159
+ - **`I18nStore`**: _Store Creation Class_ for managing translation data.
160
+ - **`createI18nContext`**: _React Context_ to generate providers and hooks for translation.
161
+ - **`IntlProvider`**: _React Translation Provider_ for managing current locale.
162
+ - **`useTranslation`**: _Translation Hook_ for easy access to translation messages.
157
163
 
158
164
  ## 🚀 Getting Started
159
165
 
160
- ### Package list
161
-
162
- ```bash
163
- import { createI18nStore, createI18nContext, useTranslation } from '@sheet-i18n/react';
164
- ```
165
-
166
166
  ### Basic Usage
167
167
 
168
168
  #### 1. Define Translation Data
@@ -187,7 +187,7 @@ Prepare locale JSON files:
187
187
  }
188
188
  ```
189
189
 
190
- #### 2. Create i18n Store
190
+ #### 2. Initialize i18n Store
191
191
 
192
192
  this store will be used as a core translations module.
193
193
 
@@ -195,9 +195,9 @@ this store will be used as a core translations module.
195
195
  import en from './en.json';
196
196
  import ko from './ko.json';
197
197
 
198
- import { createI18nStore } from '@sheet-i18n/react';
198
+ import { I18nStore } from '@sheet-i18n/react';
199
199
 
200
- export const i18nStore = createI18nStore({
200
+ export const i18nStore = new I18nStore({
201
201
  supportedLocales: ['ko', 'en'],
202
202
  defaultLocale: 'ko',
203
203
  localeSet: {
@@ -253,27 +253,38 @@ const YourComponent = () => {
253
253
 
254
254
  ## 📦 API Reference
255
255
 
256
- ### `createI18nStore`
256
+ ### `I18nStore`
257
257
 
258
- Creates a store for managing translations.
258
+ The `I18nStore` manages type-safe translation states, ensuring consistency across locales.
259
259
 
260
260
  #### Parameters:
261
261
 
262
- - **`supportedLocales`** (array): Array of supported locale strings in your project.
263
- - **`defaultLocale`** (string): Default locale to use.
264
- - **`localeSet`** (object): Object containing translations for each locale.
262
+ - **`supportedLocales`**: Array of supported locale strings.
263
+ - **`defaultLocale`**: The default locale, included in `supportedLocales`.
264
+ - **`localeSet`**: An object where keys match `supportedLocales`, and values are translation sets.
265
+
266
+ > ⚠️ Caveats:
267
+
268
+ 1. `supportedLocales` must be an array of locale strings.
269
+ 2. `defaultLocale` must exist in `supportedLocales`.
270
+ 3. `localeSet` must be an object with keys matching `supportedLocales`.
265
271
 
266
272
  #### Example:
267
273
 
268
274
  ```tsx
269
- const i18nStore = createI18nStore({
275
+ export const i18nStore = new I18nStore({
270
276
  supportedLocales: ['ko', 'en'],
271
277
  defaultLocale: 'ko',
272
- localeSet: { ko, en },
278
+ localeSet: {
279
+ ko,
280
+ en,
281
+ },
273
282
  });
274
- ```
275
283
 
276
- ---
284
+ // Accessing properties
285
+ i18nStore.supportedLocales; // ['ko', 'en']
286
+ i18nStore.defaultLocale; // 'ko'
287
+ ```
277
288
 
278
289
  ### `createI18nContext`
279
290
 
@@ -283,14 +294,17 @@ Generates React context, including the `IntlProvider` and `useTranslation`.
283
294
 
284
295
  - **`i18nStore`**: Output of `createI18nStore`.
285
296
 
297
+ > ⚠️ Caveats:
298
+
299
+ 1. `i18nStore` passed to createI18nContext must be an instance of I18nStore.
300
+ 2. custom object is not allowed to be passed to createI18nContext.
301
+
286
302
  #### Example:
287
303
 
288
304
  ```tsx
289
305
  const { IntlProvider, useTranslation } = createI18nContext(i18nStore);
290
306
  ```
291
307
 
292
- ---
293
-
294
308
  ### `IntlProvider`
295
309
 
296
310
  A React component to provide translations to child components.
@@ -306,8 +320,6 @@ A React component to provide translations to child components.
306
320
  <IntlProvider currentLocale="ko">{children}</IntlProvider>
307
321
  ```
308
322
 
309
- ---
310
-
311
323
  ### `useTranslation`
312
324
 
313
325
  A hook to access translations in your components.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sheet-i18n",
3
- "version": "0.2.6-canary.2",
3
+ "version": "0.2.6-canary.3",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",
@@ -32,13 +32,13 @@
32
32
  },
33
33
  "license": "ISC",
34
34
  "dependencies": {
35
- "@sheet-i18n/exporter": "0.2.3-canary.0",
36
- "@sheet-i18n/react": "0.1.2-canary.2"
35
+ "@sheet-i18n/exporter": "0.2.3-canary.1",
36
+ "@sheet-i18n/react": "0.1.2-canary.3"
37
37
  },
38
38
  "devDependencies": {
39
39
  "tsup": "^6.0.0",
40
40
  "typescript": "^5.0.0",
41
- "@sheet-i18n/typescript-config": "0.2.3-canary.0"
41
+ "@sheet-i18n/typescript-config": "0.2.3-canary.1"
42
42
  },
43
43
  "scripts": {
44
44
  "build": "tsup",