sheet-i18n 0.1.0 → 0.1.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.
@@ -1,6 +1,6 @@
1
1
 
2
2
  
3
- > sheet-i18n@0.1.0 build /Users/choeucheol/Documents/dev/project/sheet-i18n/packages/sheet-i18n
3
+ > sheet-i18n@0.1.2 build /Users/choeucheol/Documents/dev/project/sheet-i18n/packages/sheet-i18n
4
4
  > tsup
5
5
 
6
6
  CLI Building entry: src/index.ts, src/exporter/index.ts
@@ -11,14 +11,14 @@
11
11
  CLI Cleaning output folder
12
12
  CJS Build start
13
13
  ESM Build start
14
- CJS dist/index.js 1.28 KB
15
- CJS dist/exporter/index.js 1.10 KB
16
- CJS ⚡️ Build success in 6ms
17
- ESM dist/chunk-7AQPNLGW.mjs 122.00 B
18
14
  ESM dist/index.mjs 102.00 B
19
15
  ESM dist/exporter/index.mjs 32.00 B
16
+ ESM dist/chunk-7AQPNLGW.mjs 122.00 B
20
17
  ESM ⚡️ Build success in 6ms
18
+ CJS dist/index.js 1.28 KB
19
+ CJS dist/exporter/index.js 1.10 KB
20
+ CJS ⚡️ Build success in 6ms
21
21
  DTS Build start
22
- DTS ⚡️ Build success in 353ms
22
+ DTS ⚡️ Build success in 364ms
23
23
  DTS dist/exporter/index.d.ts 592.00 B
24
24
  DTS dist/index.d.ts 84.00 B
@@ -0,0 +1,27 @@
1
+
2
+ 
3
+ > sheet-i18n@0.1.0 changelog /Users/choeucheol/Documents/dev/project/sheet-i18n/packages/sheet-i18n
4
+ > standard-version
5
+
6
+ ✔ bumping version in package.json from 0.1.0 to 0.1.1
7
+ ✔ created CHANGELOG.md
8
+ ✔ outputting changes to CHANGELOG.md
9
+ ✔ committing package.json and CHANGELOG.md
10
+ fatal: Unable to create '/Users/choeucheol/Documents/dev/project/sheet-i18n/.git/index.lock': File exists.
11
+ 
12
+ Another git process seems to be running in this repository, e.g.
13
+ an editor opened by 'git commit'. Please make sure all processes
14
+ are terminated then try again. If it still fails, a git process
15
+ may have crashed in this repository earlier:
16
+ remove the file manually to continue.
17
+ 
18
+ Command failed: git add CHANGELOG.md package.json
19
+ fatal: Unable to create '/Users/choeucheol/Documents/dev/project/sheet-i18n/.git/index.lock': File exists.
20
+ 
21
+ Another git process seems to be running in this repository, e.g.
22
+ an editor opened by 'git commit'. Please make sure all processes
23
+ are terminated then try again. If it still fails, a git process
24
+ may have crashed in this repository earlier:
25
+ remove the file manually to continue.
26
+ 
27
+  ELIFECYCLE  Command failed with exit code 1.
package/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
+
5
+ ### [0.1.1](https://github.com/chltjdrhd777/sheet-i18n/compare/v0.1.2...v0.1.1) (2024-12-23)
6
+
7
+
8
+ ### Features
9
+
10
+ * add changelog script in container sheet-18n package ([0f05e47](https://github.com/chltjdrhd777/sheet-i18n/commit/0f05e47dfaa2e6ddc57ff4122f3a09fa8e65f645))
package/README.md ADDED
@@ -0,0 +1,192 @@
1
+ # sheet-i18n
2
+
3
+ **An all-in-one package for sheet-based translations.**
4
+
5
+ [![npm](https://img.shields.io/npm/v/sheet-i18n)](https://www.npmjs.com/package/sheet-i18n)
6
+ <a href="https://sheet-i18n.vercel.app/en" target="_blank">
7
+
8
+ <!-- <img height="20px" src="https://img.shields.io/badge/📚-%20Docs-%23000000"/> -->
9
+ </a>
10
+
11
+ ## Installation 🛠️
12
+
13
+ You can install **sheet-i18n** via npm:
14
+
15
+ ```bash
16
+ npm install sheet-i18n
17
+ ```
18
+
19
+ ## Usage 🚀
20
+
21
+ ### 📑 Main Package - `sheet-i18n`
22
+
23
+ This is the core package for sheet-based translations. You can use it to work with Google Sheets and export translations.
24
+
25
+ <details>
26
+ <summary>📄 Server export function - `sheet-i18n/exporter`</summary>
27
+
28
+ #### `sheet-i18n/exporter`
29
+
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
+
32
+ ```jsx
33
+ import { googleSheetExporter } from 'sheet-i18n/exporter';
34
+
35
+ const exporter = await googleSheetExporter({
36
+ credentials: {
37
+ sheetId: 'your-google-sheet-id',
38
+ clientEmail: 'your-client-email',
39
+ privateKey: 'your-private-key',
40
+ },
41
+ defaultLocale: 'default-language',
42
+ });
43
+
44
+ await exporter.exportTranslations();
45
+ ```
46
+
47
+ ### Configuration ⚙️
48
+
49
+ The configuration object required for using the exporter is as follows:
50
+
51
+ #### Required 📝
52
+
53
+ - **`credentials`**: Google Sheets API credentials:
54
+ - `sheetId`: The ID of your Google Spreadsheet (extracted from the URL).
55
+ - `clientEmail`: The email of the Google Sheets API client.
56
+ - `privateKey`: The private key associated with the client.
57
+ - **`defaultLocale`**: The default locale/language specified in your Google Sheet header.
58
+
59
+ #### Optional 🔧
60
+
61
+ - **`headerStartRowNumber`**: Specifies the row number where the headers begin (if not at the top).
62
+ - **`ignoredSheets`**: A list of sheets to exclude by title. By default, sheets without the `defaultLocale` in headers will be ignored.
63
+ - **`exportPath`**: Path to save exported translations. This is the location where the exported translations will be saved. By default, it will use the current working directory (cwd). This option is only used when calling the `exportTranslations` method.
64
+
65
+ ---
66
+
67
+ ### Exporter Methods 🛠️
68
+
69
+ #### `getTranslations` 📝
70
+
71
+ - **Description**: This function retrieves the translation data, which is structured by locale keys (such as "ko", "en", etc.). It collects all translations from the specified sheet, replaces any placeholders, and prepares them to be sent to the client in the response body. Each key corresponds to a language, and the value for each key is an object containing the translated text for that locale.
72
+
73
+ - **Type**: Function
74
+ - **Parameters**: None
75
+ - **Returns**: An object where each key is a locale (e.g., "ko", "en"), and the value is the respective translation data for that locale.
76
+
77
+ #### Example:
78
+
79
+ If the headers in your Google Sheets are `["ko", "en", ...]`, the result returned by `getTranslations` will look like this:
80
+
81
+ ```json
82
+ {
83
+ "ko": {
84
+ "greeting": "안녕하세요",
85
+ "farewell": "안녕히 가세요"
86
+ },
87
+ "en": {
88
+ "greeting": "Hello",
89
+ "farewell": "Goodbye"
90
+ },
91
+ ...
92
+ }
93
+ ```
94
+
95
+ In this example:
96
+
97
+ - `"ko"` contains the translations for Korean.
98
+ - `"en"` contains the translations for English.
99
+ Each locale’s object contains key-value pairs for individual translations.
100
+
101
+ #### `exportTranslations` 📤
102
+
103
+ - **Description**: This asynchronous function is used in a Node.js environment to export translations directly into your project. It is especially useful if your project includes server-side APIs (like Next.js API routes) and you need to update the locale JSON data in your project. It can be invoked to update or create the locale files within your project, ensuring that the translation data is synced with the local environment.
104
+
105
+ - **Type**: Function
106
+ - **Parameters**: None
107
+ - **Returns**: `void`
108
+
109
+ #### Example:
110
+
111
+ If you call the `exportTranslations` function, it will update or create JSON files in your project for each locale. The result could look like this:
112
+
113
+ ```json
114
+ // ko.json
115
+ {
116
+ "greeting": "안녕하세요",
117
+ "farewell": "안녕히 가세요"
118
+ }
119
+
120
+ // en.json
121
+ {
122
+ "greeting": "Hello",
123
+ "farewell": "Goodbye"
124
+ }
125
+ ```
126
+
127
+ ---
128
+
129
+ ### API Documentation 📚
130
+
131
+ You can refer to the Google Sheets API for integration details and configuration. The following link provides extensive documentation on how to interact with Google Sheets API for accessing your spreadsheet data:
132
+
133
+ [Google Sheets API Documentation](https://developers.google.com/sheets/api)
134
+
135
+ ---
136
+
137
+ ### Exporting Data Format 🗂️
138
+
139
+ 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.
140
+
141
+ </details>
142
+
143
+ <!--
144
+ <details>
145
+ <summary>⚛️ React Component - `sheet-i18n/react`</summary>
146
+
147
+ #### `sheet-i18n/react`
148
+
149
+ The **React component** subpackage allows you to use translations within your React application. This is ideal for rendering dynamic translations on the frontend, where you may need to load and display translations from a Google Spreadsheet based on the current locale selected by the user.
150
+
151
+ ```jsx
152
+ import { useState, useEffect } from 'react';
153
+ import { googleSheetExporter } from 'sheet-i18n/react';
154
+
155
+ const TranslationProvider = ({ children }) => {
156
+ const [translations, setTranslations] = useState({});
157
+
158
+ useEffect(() => {
159
+ const fetchTranslations = async () => {
160
+ const exporter = await googleSheetExporter({
161
+ credentials: {
162
+ sheetId: 'your-google-sheet-id',
163
+ clientEmail: 'your-client-email',
164
+ privateKey: 'your-private-key',
165
+ },
166
+ defaultLocale: 'en',
167
+ });
168
+ const data = await exporter.getTranslations();
169
+ setTranslations(data);
170
+ };
171
+
172
+ fetchTranslations();
173
+ }, []);
174
+
175
+ return (
176
+ <TranslationContext.Provider value={translations}>
177
+ {children}
178
+ </TranslationContext.Provider>
179
+ );
180
+ };
181
+ ```
182
+
183
+ This is useful for applications where translations need to be loaded and displayed dynamically from a backend (e.g., Google Sheets). You can use this provider to wrap your app and pass translations to components.
184
+
185
+ </details>
186
+
187
+ ---
188
+
189
+ ## Additional Notes 📌
190
+
191
+ - **Locales**: Ensure that the first row in your Google Sheet contains the locale headers (e.g., `["ko", "en", "fr"]`).
192
+ - **Placeholders**: Any placeholders within the translation strings will be replaced during the export process. -->
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "sheet-i18n",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",
7
7
  "scripts": {
8
8
  "build": "tsup",
9
9
  "dev": "tsup --watch",
10
+ "changelog": "standard-version",
10
11
  "publish:npm": "npm publish"
11
12
  },
12
13
  "exports": {
@@ -15,6 +16,18 @@
15
16
  "import": "./dist/exporter/index.mjs"
16
17
  }
17
18
  },
19
+ "keywords": [
20
+ "sheet-i18n",
21
+ "spreadsheet",
22
+ "i18n",
23
+ "translation"
24
+ ],
25
+ "author": {
26
+ "name": "devAnderson",
27
+ "email": "chltjdrhd777@gmail.com",
28
+ "url": "https://github.com/chltjdrhd777"
29
+ },
30
+ "license": "ISC",
18
31
  "dependencies": {
19
32
  "@sheet-i18n/exporter": "workspace:*"
20
33
  },