sheet-i18n 0.2.5-canary.0 β†’ 0.2.5-canary.10

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 CHANGED
@@ -22,15 +22,15 @@ npm install sheet-i18n
22
22
 
23
23
  This is the core package for sheet-based translations. You can use it to work with Google Sheets and export translations.
24
24
 
25
- <details open>
26
- <summary>πŸ“„ Server export function - `sheet-i18n/exporter`</summary>
25
+ <details>
26
+ <summary>πŸ“„ Server export function - sheet-i18n/exporter</summary>
27
27
 
28
28
  #### `sheet-i18n/exporter`
29
29
 
30
30
  The **server-side exporter** subpackage allows you to interact with Google Sheets and export translations directly into your project. This is primarily used in server-side environments, such as Next.js API routes or other backend frameworks, where you want to fetch and store translations from a Google Spreadsheet to be served to clients or used within your server application.
31
31
 
32
32
  ```jsx
33
- import { googleSheetExporter } from 'sheet-i18n';
33
+ import { googleSheetExporter } from 'sheet-i18n/exporter';
34
34
 
35
35
  const exporter = await googleSheetExporter({
36
36
  credentials: {
@@ -38,7 +38,7 @@ const exporter = await googleSheetExporter({
38
38
  clientEmail: 'your-client-email',
39
39
  privateKey: 'your-private-key',
40
40
  },
41
- defaultLocale: 'default-language',
41
+ defaultLocale: 'default-language-in-sheet-header',
42
42
  });
43
43
 
44
44
  await exporter.exportTranslations();
@@ -136,3 +136,261 @@ This package provides a streamlined way to export data using sheets API. It is d
136
136
  The exported translations will be saved in a format that is easy to use for localization purposes. Each translation is stored in its respective locale folder, with a structured format.
137
137
 
138
138
  </details>
139
+
140
+ ---
141
+
142
+ <details>
143
+ <summary>πŸ“„ Client export function - sheet-i18n/react</summary>
144
+
145
+ #### `sheet-i18n/react`
146
+
147
+ The **client-side i18n library** subpackage.
148
+
149
+ This package provides tools to handle translations in React applications using context and hooks. It simplifies internationalization workflows by offering functions and components to manage, access, and use locale-specific translation data.
150
+
151
+ ## ✨ Package Introduction
152
+
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.
157
+
158
+ ## πŸš€ Getting Started
159
+
160
+ ### Package list
161
+
162
+ ```bash
163
+ import { createI18nStore, createI18nContext, useTranslation } from '@sheet-i18n/react';
164
+ ```
165
+
166
+ ### Basic Usage
167
+
168
+ #### 1. Define Translation Data
169
+
170
+ Prepare locale JSON files:
171
+
172
+ ```json
173
+ // en.json
174
+ {
175
+ "header": {
176
+ "login": "Login",
177
+ "logout": "Logout"
178
+ }
179
+ }
180
+
181
+ // ko.json
182
+ {
183
+ "header": {
184
+ "login": "둜그인",
185
+ "logout": "λ‘œκ·Έμ•„μ›ƒ"
186
+ }
187
+ }
188
+ ```
189
+
190
+ #### 2. Create i18n Store
191
+
192
+ this store will be used as a core translations module.
193
+
194
+ ```tsx
195
+ import en from './en.json';
196
+ import ko from './ko.json';
197
+
198
+ import { createI18nStore } from '@sheet-i18n/react';
199
+
200
+ export const i18nStore = createI18nStore({
201
+ supportedLocales: ['ko', 'en'],
202
+ defaultLocale: 'ko',
203
+ localeSet: {
204
+ ko,
205
+ en,
206
+ },
207
+ });
208
+ ```
209
+
210
+ #### 3. Create i18n Context
211
+
212
+ ```tsx
213
+ import { i18nStore } from './file-path-of-i18nStore-initiated';
214
+ import { createI18nContext } from '@sheet-i18n/react';
215
+
216
+ export const { IntlProvider, useTranslation } = createI18nContext(i18nStore);
217
+ ```
218
+
219
+ #### 4. Mount Intl Context Provider in your App
220
+
221
+ ```tsx
222
+ import React from 'react';
223
+ import { IntlProvider } from './i18nContext';
224
+
225
+ const App = (currentLocale: string) => {
226
+ return (
227
+ <IntlProvider currentLocale={currentLocale}>
228
+ <YourComponent />
229
+ </IntlProvider>
230
+ );
231
+ };
232
+ ```
233
+
234
+ #### 5. Use Translations
235
+
236
+ ```tsx
237
+ import React from 'react';
238
+ import { useTranslation } from './i18nContext';
239
+
240
+ const YourComponent = () => {
241
+ const { t } = useTranslation('header');
242
+
243
+ return (
244
+ <div>
245
+ <button>{t('login')}</button>
246
+ <button>{t('logout')}</button>
247
+ </div>
248
+ );
249
+ };
250
+ ```
251
+
252
+ ---
253
+
254
+ ## πŸ“¦ API Reference
255
+
256
+ ### `createI18nStore`
257
+
258
+ Creates a store for managing translations.
259
+
260
+ #### Parameters:
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.
265
+
266
+ #### Example:
267
+
268
+ ```tsx
269
+ const i18nStore = createI18nStore({
270
+ supportedLocales: ['ko', 'en'],
271
+ defaultLocale: 'ko',
272
+ localeSet: { ko, en },
273
+ });
274
+ ```
275
+
276
+ ---
277
+
278
+ ### `createI18nContext`
279
+
280
+ Generates React context, including the `IntlProvider` and `useTranslation`.
281
+
282
+ #### Parameters:
283
+
284
+ - **`i18nStore`**: Output of `createI18nStore`.
285
+
286
+ #### Example:
287
+
288
+ ```tsx
289
+ const { IntlProvider, useTranslation } = createI18nContext(i18nStore);
290
+ ```
291
+
292
+ ---
293
+
294
+ ### `IntlProvider`
295
+
296
+ A React component to provide translations to child components.
297
+
298
+ #### Props:
299
+
300
+ - **`currentLocale`**: Key locale. This will determine which locale to use for translations data.
301
+ - **`children`**: React children.
302
+
303
+ #### Example:
304
+
305
+ ```tsx
306
+ <IntlProvider currentLocale="ko">{children}</IntlProvider>
307
+ ```
308
+
309
+ ---
310
+
311
+ ### `useTranslation`
312
+
313
+ A hook to access translations in your components.
314
+
315
+ #### Parameters:
316
+
317
+ - **`sheetTitle`**: The sheet title of the translation group.
318
+
319
+ #### Example:
320
+
321
+ ```tsx
322
+ const { t } = useTranslation('header');
323
+ const translatedMessage = t('login');
324
+ ```
325
+
326
+ ### `t Function`
327
+
328
+ The t function is used to retrieve a translation string based on a key and optionally interpolate variables. It provides flexibility to include dynamic values, such as plain strings or React components, for enhanced localization capabilities.
329
+
330
+ #### Parameters:
331
+
332
+ - key (string): The translation key to retrieve the localized string.
333
+
334
+ ```tsx
335
+ const translatedMessage = t('login'); // login is key
336
+ ```
337
+
338
+ - values (object, optional): An object containing key-value pairs to interpolate into the translation string.
339
+
340
+ ```tsx
341
+ // John Doe shown
342
+ const translatedMessage = t('{username} shown', { username: 'John Doe' });
343
+ ```
344
+
345
+ > πŸ’‘ Note: The values object can contain any type of data, including React components.
346
+ >
347
+ > ```tsx
348
+ > // <Username /> shown
349
+ > const translatedMessage = t('{username} shown', { username: <Username /> });
350
+ > ```
351
+
352
+ ## πŸ›  Error Handling
353
+
354
+ Custom error messages help identify misconfigurations:
355
+
356
+ 1. **Invalid Params**: Ensure `supportedLocales`, `defaultLocale`, and `localeSet` are correctly provided.
357
+ 2. **Missing Default Locale**: The `defaultLocale` must exist in `supportedLocales`.
358
+ 3. **Invalid LocaleSet**: Ensure the `localeSet` keys match `supportedLocales`.
359
+
360
+ ## 🌍 Example Usage in Applications
361
+
362
+ ```tsx
363
+ import { useTranslation } from './i18nContext';
364
+
365
+ const TableComponent = () => {
366
+ const { t } = useTranslation('header');
367
+
368
+ const columns = [
369
+ {
370
+ title: t('logout'),
371
+ dataIndex: 'action',
372
+ },
373
+ ];
374
+
375
+ return <Table columns={columns} />;
376
+ };
377
+ ```
378
+
379
+ ## πŸ“œ Library Versions πŸ”’
380
+
381
+ This package supports the following library versions:
382
+
383
+ - **React**: `^19.0.0`
384
+ - **React Intl**: `^7.0.4`
385
+
386
+ ## πŸ“œ License
387
+
388
+ This project is licensed under the ISC License.
389
+
390
+ ## πŸ‘€ Author
391
+
392
+ **devAnderson**
393
+ [GitHub](https://github.com/chltjdrhd777)
394
+ [chltjdrhd777@gmail.com](mailto:chltjdrhd777@gmail.com)
395
+
396
+ </details>
@@ -0,0 +1 @@
1
+ export * from '@sheet-i18n/exporter';
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+
17
+ // src/exporter/index.ts
18
+ var exporter_exports = {};
19
+ module.exports = __toCommonJS(exporter_exports);
20
+ __reExport(exporter_exports, require("@sheet-i18n/exporter"), module.exports);
21
+ // Annotate the CommonJS export names for ESM import in node:
22
+ 0 && (module.exports = {
23
+ ...require("@sheet-i18n/exporter")
24
+ });
@@ -0,0 +1,2 @@
1
+ // src/exporter/index.ts
2
+ export * from "@sheet-i18n/exporter";
package/dist/index.d.ts CHANGED
@@ -1 +1,2 @@
1
- export * from '@sheet-i18n/exporter';
1
+ import '@sheet-i18n/react';
2
+ import '@sheet-i18n/exporter';
package/dist/index.js CHANGED
@@ -11,14 +11,8 @@ var __copyProps = (to, from, except, desc) => {
11
11
  }
12
12
  return to;
13
13
  };
14
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
14
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
15
 
17
16
  // src/index.ts
18
17
  var src_exports = {};
19
18
  module.exports = __toCommonJS(src_exports);
20
- __reExport(src_exports, require("@sheet-i18n/exporter"), module.exports);
21
- // Annotate the CommonJS export names for ESM import in node:
22
- 0 && (module.exports = {
23
- ...require("@sheet-i18n/exporter")
24
- });
package/dist/index.mjs CHANGED
@@ -1,2 +0,0 @@
1
- // src/index.ts
2
- export * from "@sheet-i18n/exporter";
@@ -0,0 +1 @@
1
+ export * from '@sheet-i18n/react';
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+
17
+ // src/react/index.ts
18
+ var react_exports = {};
19
+ module.exports = __toCommonJS(react_exports);
20
+ __reExport(react_exports, require("@sheet-i18n/react"), module.exports);
21
+ // Annotate the CommonJS export names for ESM import in node:
22
+ 0 && (module.exports = {
23
+ ...require("@sheet-i18n/react")
24
+ });
@@ -0,0 +1,2 @@
1
+ // src/react/index.ts
2
+ export * from "@sheet-i18n/react";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sheet-i18n",
3
- "version": "0.2.5-canary.0",
3
+ "version": "0.2.5-canary.10",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",
@@ -8,15 +8,15 @@
8
8
  "dist/**/*"
9
9
  ],
10
10
  "exports": {
11
- ".": {
12
- "require": "./dist/index.js",
13
- "import": "./dist/index.mjs",
14
- "types": "./dist/index.d.ts"
15
- },
16
11
  "./exporter": {
17
12
  "require": "./dist/exporter/index.js",
18
13
  "import": "./dist/exporter/index.mjs",
19
14
  "types": "./dist/exporter/index.d.ts"
15
+ },
16
+ "./react": {
17
+ "require": "./dist/react/index.js",
18
+ "import": "./dist/react/index.mjs",
19
+ "types": "./dist/react/index.d.ts"
20
20
  }
21
21
  },
22
22
  "keywords": [
@@ -32,12 +32,13 @@
32
32
  },
33
33
  "license": "ISC",
34
34
  "dependencies": {
35
- "@sheet-i18n/exporter": "0.2.1"
35
+ "@sheet-i18n/exporter": "0.2.2-canary.3",
36
+ "@sheet-i18n/react": "0.1.1-canary.5"
36
37
  },
37
38
  "devDependencies": {
38
39
  "tsup": "^6.0.0",
39
40
  "typescript": "^5.0.0",
40
- "@sheet-i18n/typescript-config": "0.2.1"
41
+ "@sheet-i18n/typescript-config": "0.2.2-canary.3"
41
42
  },
42
43
  "scripts": {
43
44
  "build": "tsup",