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.
- package/.turbo/turbo-build.log +6 -6
- package/.turbo/turbo-changelog.log +27 -0
- package/CHANGELOG.md +10 -0
- package/README.md +192 -0
- package/package.json +14 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
> sheet-i18n@0.1.
|
|
3
|
+
> sheet-i18n@0.1.2 build /Users/choeucheol/Documents/dev/project/sheet-i18n/packages/sheet-i18n
|
|
4
4
|
> tsup
|
|
5
5
|
|
|
6
6
|
[34mCLI[39m Building entry: src/index.ts, src/exporter/index.ts
|
|
@@ -11,14 +11,14 @@
|
|
|
11
11
|
[34mCLI[39m Cleaning output folder
|
|
12
12
|
[34mCJS[39m Build start
|
|
13
13
|
[34mESM[39m Build start
|
|
14
|
-
[32mCJS[39m [1mdist/index.js [22m[32m1.28 KB[39m
|
|
15
|
-
[32mCJS[39m [1mdist/exporter/index.js [22m[32m1.10 KB[39m
|
|
16
|
-
[32mCJS[39m ⚡️ Build success in 6ms
|
|
17
|
-
[32mESM[39m [1mdist/chunk-7AQPNLGW.mjs [22m[32m122.00 B[39m
|
|
18
14
|
[32mESM[39m [1mdist/index.mjs [22m[32m102.00 B[39m
|
|
19
15
|
[32mESM[39m [1mdist/exporter/index.mjs [22m[32m32.00 B[39m
|
|
16
|
+
[32mESM[39m [1mdist/chunk-7AQPNLGW.mjs [22m[32m122.00 B[39m
|
|
20
17
|
[32mESM[39m ⚡️ Build success in 6ms
|
|
18
|
+
[32mCJS[39m [1mdist/index.js [22m[32m1.28 KB[39m
|
|
19
|
+
[32mCJS[39m [1mdist/exporter/index.js [22m[32m1.10 KB[39m
|
|
20
|
+
[32mCJS[39m ⚡️ Build success in 6ms
|
|
21
21
|
[34mDTS[39m Build start
|
|
22
|
-
[32mDTS[39m ⚡️ Build success in
|
|
22
|
+
[32mDTS[39m ⚡️ Build success in 364ms
|
|
23
23
|
[32mDTS[39m [1mdist/exporter/index.d.ts [22m[32m592.00 B[39m
|
|
24
24
|
[32mDTS[39m [1mdist/index.d.ts [22m[32m84.00 B[39m
|
|
@@ -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
|
+
[32m✔[39m bumping version in package.json from [1m0.1.0[22m to [1m0.1.1[22m
|
|
7
|
+
[32m✔[39m created [1mCHANGELOG.md[22m
|
|
8
|
+
[32m✔[39m outputting changes to [1mCHANGELOG.md[22m
|
|
9
|
+
[32m✔[39m committing [1mpackage.json[22m and [1mCHANGELOG.md[22m
|
|
10
|
+
[31mfatal: Unable to create '/Users/choeucheol/Documents/dev/project/sheet-i18n/.git/index.lock': File exists.[39m
|
|
11
|
+
[31m[39m
|
|
12
|
+
[31mAnother git process seems to be running in this repository, e.g.[39m
|
|
13
|
+
[31man editor opened by 'git commit'. Please make sure all processes[39m
|
|
14
|
+
[31mare terminated then try again. If it still fails, a git process[39m
|
|
15
|
+
[31mmay have crashed in this repository earlier:[39m
|
|
16
|
+
[31mremove the file manually to continue.[39m
|
|
17
|
+
[31m[39m
|
|
18
|
+
[31mCommand failed: git add CHANGELOG.md package.json[39m
|
|
19
|
+
[31mfatal: Unable to create '/Users/choeucheol/Documents/dev/project/sheet-i18n/.git/index.lock': File exists.[39m
|
|
20
|
+
[31m[39m
|
|
21
|
+
[31mAnother git process seems to be running in this repository, e.g.[39m
|
|
22
|
+
[31man editor opened by 'git commit'. Please make sure all processes[39m
|
|
23
|
+
[31mare terminated then try again. If it still fails, a git process[39m
|
|
24
|
+
[31mmay have crashed in this repository earlier:[39m
|
|
25
|
+
[31mremove the file manually to continue.[39m
|
|
26
|
+
[31m[39m
|
|
27
|
+
[41m[30m ELIFECYCLE [39m[49m [31mCommand failed with exit code 1.[39m
|
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
|
+
[](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.
|
|
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
|
},
|