@el-j/google-sheet-translations 1.0.0
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/LICENSE +21 -0
- package/README.md +258 -0
- package/dist/constants.d.ts +6 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +9 -0
- package/dist/constants.js.map +1 -0
- package/dist/getSpreadSheetData.d.ts +7 -0
- package/dist/getSpreadSheetData.d.ts.map +1 -0
- package/dist/getSpreadSheetData.js +121 -0
- package/dist/getSpreadSheetData.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +22 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/auth.d.ts +8 -0
- package/dist/utils/auth.d.ts.map +1 -0
- package/dist/utils/auth.js +19 -0
- package/dist/utils/auth.js.map +1 -0
- package/dist/utils/configurationHandler.d.ts +29 -0
- package/dist/utils/configurationHandler.d.ts.map +1 -0
- package/dist/utils/configurationHandler.js +23 -0
- package/dist/utils/configurationHandler.js.map +1 -0
- package/dist/utils/dataConverter/convertFromDataJsonFormat.d.ts +8 -0
- package/dist/utils/dataConverter/convertFromDataJsonFormat.d.ts.map +1 -0
- package/dist/utils/dataConverter/convertFromDataJsonFormat.js +47 -0
- package/dist/utils/dataConverter/convertFromDataJsonFormat.js.map +1 -0
- package/dist/utils/dataConverter/convertToDataJsonFormat.d.ts +10 -0
- package/dist/utils/dataConverter/convertToDataJsonFormat.d.ts.map +1 -0
- package/dist/utils/dataConverter/convertToDataJsonFormat.js +51 -0
- package/dist/utils/dataConverter/convertToDataJsonFormat.js.map +1 -0
- package/dist/utils/dataConverter/findLocalChanges.d.ts +9 -0
- package/dist/utils/dataConverter/findLocalChanges.d.ts.map +1 -0
- package/dist/utils/dataConverter/findLocalChanges.js +39 -0
- package/dist/utils/dataConverter/findLocalChanges.js.map +1 -0
- package/dist/utils/fileWriter.d.ts +23 -0
- package/dist/utils/fileWriter.d.ts.map +1 -0
- package/dist/utils/fileWriter.js +119 -0
- package/dist/utils/fileWriter.js.map +1 -0
- package/dist/utils/getFileLastModified.d.ts +7 -0
- package/dist/utils/getFileLastModified.d.ts.map +1 -0
- package/dist/utils/getFileLastModified.js +23 -0
- package/dist/utils/getFileLastModified.js.map +1 -0
- package/dist/utils/isDataJsonNewer.d.ts +8 -0
- package/dist/utils/isDataJsonNewer.d.ts.map +1 -0
- package/dist/utils/isDataJsonNewer.js +40 -0
- package/dist/utils/isDataJsonNewer.js.map +1 -0
- package/dist/utils/localeFilter.d.ts +17 -0
- package/dist/utils/localeFilter.d.ts.map +1 -0
- package/dist/utils/localeFilter.js +49 -0
- package/dist/utils/localeFilter.js.map +1 -0
- package/dist/utils/localeNormalizer.d.ts +37 -0
- package/dist/utils/localeNormalizer.d.ts.map +1 -0
- package/dist/utils/localeNormalizer.js +145 -0
- package/dist/utils/localeNormalizer.js.map +1 -0
- package/dist/utils/readDataJson.d.ts +8 -0
- package/dist/utils/readDataJson.d.ts.map +1 -0
- package/dist/utils/readDataJson.js +29 -0
- package/dist/utils/readDataJson.js.map +1 -0
- package/dist/utils/sheetProcessor.d.ts +22 -0
- package/dist/utils/sheetProcessor.d.ts.map +1 -0
- package/dist/utils/sheetProcessor.js +86 -0
- package/dist/utils/sheetProcessor.js.map +1 -0
- package/dist/utils/spreadsheetUpdater.d.ts +25 -0
- package/dist/utils/spreadsheetUpdater.d.ts.map +1 -0
- package/dist/utils/spreadsheetUpdater.js +196 -0
- package/dist/utils/spreadsheetUpdater.js.map +1 -0
- package/dist/utils/syncManager.d.ts +23 -0
- package/dist/utils/syncManager.d.ts.map +1 -0
- package/dist/utils/syncManager.js +62 -0
- package/dist/utils/syncManager.js.map +1 -0
- package/dist/utils/validateEnv.d.ts +9 -0
- package/dist/utils/validateEnv.d.ts.map +1 -0
- package/dist/utils/validateEnv.js +29 -0
- package/dist/utils/validateEnv.js.map +1 -0
- package/dist/utils/wait.d.ts +9 -0
- package/dist/utils/wait.d.ts.map +1 -0
- package/dist/utils/wait.js +21 -0
- package/dist/utils/wait.js.map +1 -0
- package/package.json +91 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
# Google Sheet Translations
|
|
2
|
+
|
|
3
|
+
A Node.js package for managing translations stored in Google Sheets.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- ✅ **Bidirectional Sync**: Sync changes from local files back to Google Sheets
|
|
8
|
+
- ✅ **Auto-Translation**: Automatic Google Translate formula generation for missing translations
|
|
9
|
+
- ✅ **Smart Locale Filtering**: Only locales with actual translations in content sheets are included in output files
|
|
10
|
+
- ✅ **TypeScript Support**: Full TypeScript definitions included
|
|
11
|
+
- ✅ **Modular Architecture**: Well-tested, maintainable codebase with clear separation of concerns
|
|
12
|
+
- ✅ **Next.js Integration**: Built-in support for Next.js static export workflows
|
|
13
|
+
- ✅ **Flexible Configuration**: Customizable paths, wait times, and processing options
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @el-j/google-sheet-translations
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Prepare Google Spreadsheet
|
|
22
|
+
1. Create Google Spreadsheet(s) with the following structure:
|
|
23
|
+
- **First Row**: Header Row with Key | [language(-country)] | [language(-country)] | ...
|
|
24
|
+
- **Subsequent Rows**: Translation Rows with Key used as variable name and corresponding translations.
|
|
25
|
+
|
|
26
|
+
2. Auto-translation for missing translations can be managed in two ways:
|
|
27
|
+
- Manually, by using the `=GOOGLETRANSLATE()` function in the spreadsheet
|
|
28
|
+
- Automatically, by enabling the `autoTranslate` option when using this package (see API Reference)
|
|
29
|
+
|
|
30
|
+
## Environment Variables
|
|
31
|
+
|
|
32
|
+
Make sure to set the following environment variables:
|
|
33
|
+
|
|
34
|
+
- `GOOGLE_CLIENT_EMAIL`: Your Google service account email
|
|
35
|
+
- `GOOGLE_PRIVATE_KEY`: Your Google service account private key
|
|
36
|
+
- `GOOGLE_SPREADSHEET_ID`: ID of the Google Spreadsheet containing translations
|
|
37
|
+
|
|
38
|
+
## Usage
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
import { getSpreadSheetData, validateEnv } from '@el-j/google-sheet-translations';
|
|
42
|
+
|
|
43
|
+
// Ensure environment variables are set
|
|
44
|
+
validateEnv();
|
|
45
|
+
|
|
46
|
+
// Fetch translations
|
|
47
|
+
async function fetchTranslations() {
|
|
48
|
+
try {
|
|
49
|
+
const translations = await getSpreadSheetData(
|
|
50
|
+
['sheet1', 'sheet2'], // Array of sheet names to process
|
|
51
|
+
{
|
|
52
|
+
rowLimit: 100, // Optional: rowLimit parameter (default is 100)
|
|
53
|
+
waitSeconds: 3, // Optional: Time to wait between API calls (default is 1)
|
|
54
|
+
dataJsonPath: 'path/to/languageData.json', // Optional: Custom path for languageData.json
|
|
55
|
+
localesOutputPath: 'path/to/locales.ts', // Optional: Custom path for locales.ts
|
|
56
|
+
translationsOutputDir: 'path/to/translations', // Optional: Custom translations output directory
|
|
57
|
+
}
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
console.log('Translations fetched successfully');
|
|
61
|
+
} catch (error) {
|
|
62
|
+
console.error('Error fetching translations:', error);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
fetchTranslations();
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Usage with NEXTJS
|
|
70
|
+
|
|
71
|
+
for nextjs, you can use the package in your `instrumentation.ts` file. This is useful for pre-fetching translations during the build process
|
|
72
|
+
and storing them in a JSON file. Practically for `static:export` in `next build`
|
|
73
|
+
|
|
74
|
+
```typescript:instrumentation.ts
|
|
75
|
+
export async function register() {
|
|
76
|
+
if (process.env.NEXT_RUNTIME === "nodejs") {
|
|
77
|
+
const getData = await import("@el-j/google-sheet-translations");
|
|
78
|
+
await getData.getSpreadSheetData(["Index"]);
|
|
79
|
+
console.log("register done");
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
read more [internationalization with nextjs](https://nextjs.org/docs/pages/building-your-application/routing/internationalization)
|
|
85
|
+
|
|
86
|
+
## API Reference
|
|
87
|
+
|
|
88
|
+
### `getSpreadSheetData(sheetTitles?, options?)`
|
|
89
|
+
|
|
90
|
+
Fetches and processes data from a Google Spreadsheet.
|
|
91
|
+
|
|
92
|
+
#### Parameters
|
|
93
|
+
|
|
94
|
+
- `sheetTitles`: (Optional) Array of sheet titles to process. If not provided, only the "i18n" sheet will be processed.
|
|
95
|
+
- `options`: (Optional) Configuration object
|
|
96
|
+
- `rowLimit`: Number - Maximum number of rows to fetch (default: 100)
|
|
97
|
+
- `waitSeconds`: Number - Time to wait between API calls (default: 1)
|
|
98
|
+
- `dataJsonPath`: String - Path for languageData.json file (default: 'src/lib/languageData.json')
|
|
99
|
+
- `localesOutputPath`: String - Path for locales.ts file (default: 'src/i18n/locales.ts')
|
|
100
|
+
- `translationsOutputDir`: String - Directory for translations output (default: 'translations')
|
|
101
|
+
- `syncLocalChanges`: Boolean - Whether to sync local changes back to the spreadsheet (default: true)
|
|
102
|
+
- `autoTranslate`: Boolean - Whether to auto-generate Google Translate formulas for missing translations (default: false)
|
|
103
|
+
|
|
104
|
+
#### Returns
|
|
105
|
+
|
|
106
|
+
A Promise resolving to the processed translation data object.
|
|
107
|
+
|
|
108
|
+
### `validateEnv()`
|
|
109
|
+
|
|
110
|
+
Validates that all required environment variables are set.
|
|
111
|
+
|
|
112
|
+
#### Returns
|
|
113
|
+
|
|
114
|
+
An object containing the validated environment variables.
|
|
115
|
+
|
|
116
|
+
#### Throws
|
|
117
|
+
|
|
118
|
+
Error if any required environment variable is missing.
|
|
119
|
+
|
|
120
|
+
## Locale Filtering
|
|
121
|
+
|
|
122
|
+
The package includes intelligent locale filtering to ensure only valid locale identifiers with actual translation content are included in the generated `locales.ts` file.
|
|
123
|
+
|
|
124
|
+
### Smart Content-Based Filtering
|
|
125
|
+
|
|
126
|
+
The `locales.ts` file will **only include locales that have actual translations in non-i18n sheets**. This means:
|
|
127
|
+
|
|
128
|
+
- ✅ Locales with translations in content sheets (like 'home', 'products', etc.) are included
|
|
129
|
+
- ❌ Locales that only exist in the 'i18n' configuration sheet are excluded
|
|
130
|
+
- ❌ Locales with empty translations in content sheets are excluded
|
|
131
|
+
- ❌ Common spreadsheet column names are filtered out
|
|
132
|
+
|
|
133
|
+
**Example:**
|
|
134
|
+
```
|
|
135
|
+
Spreadsheet structure:
|
|
136
|
+
- Sheet "content": key | en | de | fr | es
|
|
137
|
+
- Row: "welcome" | "Welcome" | "Willkommen" | "" | ""
|
|
138
|
+
- Sheet "i18n": key | en | de | fr | es
|
|
139
|
+
- Row: "config" | "Config" | "Konfiguration" | "Configuration" | "Configuración"
|
|
140
|
+
|
|
141
|
+
Result: locales.ts will only contain ["en", "de"]
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
This ensures your application only includes locales that have meaningful content for users.
|
|
145
|
+
|
|
146
|
+
### Supported Locale Formats
|
|
147
|
+
|
|
148
|
+
- Two-letter language codes: `en`, `de`, `fr`, `ja`
|
|
149
|
+
- Language-country codes with hyphens: `en-us`, `de-de`, `fr-ca`
|
|
150
|
+
- Language-country codes with underscores: `en_us`, `de_de`, `zh_cn`
|
|
151
|
+
- Extended locale codes: `en-us-traditional`, `zh-cn-simplified`
|
|
152
|
+
|
|
153
|
+
### Filtered Keywords
|
|
154
|
+
|
|
155
|
+
The following common spreadsheet column names are automatically filtered out:
|
|
156
|
+
- `key`, `keys`, `id`, `identifier`, `name`, `title`, `label`
|
|
157
|
+
- `description`, `comment`, `note`, `context`, `category`, `type`
|
|
158
|
+
- `status`, `updated`, `created`, `modified`, `version`, `source`
|
|
159
|
+
- `i18n`, `translation`, `namespace`, `section`
|
|
160
|
+
|
|
161
|
+
## Additional Utilities
|
|
162
|
+
|
|
163
|
+
The package exports several utility functions that can be used independently:
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
import {
|
|
167
|
+
validateEnv,
|
|
168
|
+
isValidLocale,
|
|
169
|
+
filterValidLocales,
|
|
170
|
+
normalizeConfig,
|
|
171
|
+
processSheet,
|
|
172
|
+
writeTranslationFiles,
|
|
173
|
+
convertToDataJsonFormat,
|
|
174
|
+
convertFromDataJsonFormat,
|
|
175
|
+
findLocalChanges
|
|
176
|
+
} from '@el-j/google-sheet-translations';
|
|
177
|
+
|
|
178
|
+
// Validate locale identifiers
|
|
179
|
+
console.log(isValidLocale('en-us')); // true
|
|
180
|
+
console.log(isValidLocale('description')); // false
|
|
181
|
+
|
|
182
|
+
// Filter valid locales from header row
|
|
183
|
+
const validLocales = filterValidLocales(['key', 'en', 'description', 'de'], 'key');
|
|
184
|
+
console.log(validLocales); // ['en', 'de']
|
|
185
|
+
|
|
186
|
+
// Normalize configuration with defaults
|
|
187
|
+
const config = normalizeConfig({ waitSeconds: 2 });
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## Bidirectional Sync Feature
|
|
191
|
+
|
|
192
|
+
This package supports bidirectional synchronization between local translation files and the Google Spreadsheet:
|
|
193
|
+
|
|
194
|
+
1. **Pull from Spreadsheet**: Fetches translations from Google Sheets and saves them to local JSON files.
|
|
195
|
+
2. **Push to Spreadsheet**: Detects changes in local files and pushes them back to the spreadsheet.
|
|
196
|
+
|
|
197
|
+
### How Bidirectional Sync Works
|
|
198
|
+
|
|
199
|
+
1. The system checks if `languageData.json` has been modified more recently than the translation output files.
|
|
200
|
+
2. If so, it compares the local `languageData.json` content with the data fetched from the spreadsheet.
|
|
201
|
+
3. Any new keys found in the local data that don't exist in the spreadsheet will be added to the spreadsheet.
|
|
202
|
+
4. If auto-translation is enabled, Google Translate formulas will be automatically added for missing translations when new keys are added.
|
|
203
|
+
|
|
204
|
+
This workflow allows developers to:
|
|
205
|
+
|
|
206
|
+
1. Add new translation keys in local files during development.
|
|
207
|
+
2. Run `getSpreadSheetData()` to push those new keys to the shared spreadsheet.
|
|
208
|
+
3. Run it again later to pull the completed translations once they're filled in by translators.
|
|
209
|
+
|
|
210
|
+
### Auto-Translation Feature
|
|
211
|
+
|
|
212
|
+
When enabled, the auto-translation feature automatically adds Google Translate formulas for missing translations when new keys are added to the spreadsheet. This helps translators by providing initial machine translations as a starting point.
|
|
213
|
+
|
|
214
|
+
The formula follows this format:
|
|
215
|
+
```
|
|
216
|
+
=GOOGLETRANSLATE(INDIRECT(sourceColumn&ROW());$sourceColumn$1;targetColumn$1)
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
For example, if you add a new key with an English translation in column B but no German translation in column C, the system will automatically add:
|
|
220
|
+
```
|
|
221
|
+
=GOOGLETRANSLATE(INDIRECT("B"&ROW());$B$1;C$1)
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
Where:
|
|
225
|
+
- `INDIRECT("B"&ROW())` dynamically references the source text cell in the same row
|
|
226
|
+
- `$B$1` references the header cell containing the source language code
|
|
227
|
+
- `C$1` references the header cell containing the target language code
|
|
228
|
+
|
|
229
|
+
[View the complete Auto-Translation Guide](docs/auto-translation-guide.md) for more details and best practices.
|
|
230
|
+
|
|
231
|
+
### Example Workflow
|
|
232
|
+
|
|
233
|
+
```typescript
|
|
234
|
+
// During development: add new keys to local translation files
|
|
235
|
+
|
|
236
|
+
// Then run this to sync changes back to the spreadsheet
|
|
237
|
+
await getSpreadSheetData(['sheet1'], {
|
|
238
|
+
syncLocalChanges: true // This is true by default
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
// Later, run again to pull completed translations
|
|
242
|
+
await getSpreadSheetData(['sheet1']);
|
|
243
|
+
|
|
244
|
+
// Example with auto-translation enabled
|
|
245
|
+
await getSpreadSheetData(['sheet1'], {
|
|
246
|
+
autoTranslate: true // Automatically generate Google Translate formulas for missing translations
|
|
247
|
+
});
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
For more detailed examples, check out the [examples directory](examples) where you'll find working code samples for all features including:
|
|
251
|
+
- Basic usage
|
|
252
|
+
- Bidirectional sync
|
|
253
|
+
- Auto-translation
|
|
254
|
+
- Next.js integration
|
|
255
|
+
|
|
256
|
+
## License
|
|
257
|
+
|
|
258
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,qEAAqE;AACrE,eAAO,MAAM,oBAAoB,IAAI,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Package-wide constants
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DEFAULT_WAIT_SECONDS = void 0;
|
|
7
|
+
/** Default wait time between Google Sheets API calls (in seconds) */
|
|
8
|
+
exports.DEFAULT_WAIT_SECONDS = 1;
|
|
9
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,qEAAqE;AACxD,QAAA,oBAAoB,GAAG,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { TranslationData } from "./types";
|
|
2
|
+
import { type SpreadsheetOptions } from "./utils/configurationHandler";
|
|
3
|
+
import { DEFAULT_WAIT_SECONDS } from "./constants";
|
|
4
|
+
export { DEFAULT_WAIT_SECONDS };
|
|
5
|
+
export declare function getSpreadSheetData(_docTitle?: string[], options?: SpreadsheetOptions, _refreshDepth?: number): Promise<TranslationData>;
|
|
6
|
+
export default getSpreadSheetData;
|
|
7
|
+
//# sourceMappingURL=getSpreadSheetData.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getSpreadSheetData.d.ts","sourceRoot":"","sources":["../src/getSpreadSheetData.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAI/C,OAAO,EAAmB,KAAK,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAIxF,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,CAAC;AAUhC,wBAAsB,kBAAkB,CACvC,SAAS,CAAC,EAAE,MAAM,EAAE,EACpB,OAAO,GAAE,kBAAuB,EAChC,aAAa,SAAI,GACf,OAAO,CAAC,eAAe,CAAC,CAiI1B;AAED,eAAe,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_WAIT_SECONDS = void 0;
|
|
4
|
+
exports.getSpreadSheetData = getSpreadSheetData;
|
|
5
|
+
const google_spreadsheet_1 = require("google-spreadsheet");
|
|
6
|
+
const wait_1 = require("./utils/wait");
|
|
7
|
+
const auth_1 = require("./utils/auth");
|
|
8
|
+
const validateEnv_1 = require("./utils/validateEnv");
|
|
9
|
+
const configurationHandler_1 = require("./utils/configurationHandler");
|
|
10
|
+
const sheetProcessor_1 = require("./utils/sheetProcessor");
|
|
11
|
+
const fileWriter_1 = require("./utils/fileWriter");
|
|
12
|
+
const syncManager_1 = require("./utils/syncManager");
|
|
13
|
+
const constants_1 = require("./constants");
|
|
14
|
+
Object.defineProperty(exports, "DEFAULT_WAIT_SECONDS", { enumerable: true, get: function () { return constants_1.DEFAULT_WAIT_SECONDS; } });
|
|
15
|
+
/**
|
|
16
|
+
* Fetches and processes data from a Google Spreadsheet
|
|
17
|
+
* @param _docTitle - Array of sheet titles to process
|
|
18
|
+
* @param options - Additional options for fetching data
|
|
19
|
+
* @returns Processed translation data
|
|
20
|
+
*/
|
|
21
|
+
const MAX_SYNC_REFRESH_DEPTH = 1;
|
|
22
|
+
async function getSpreadSheetData(_docTitle, options = {}, _refreshDepth = 0) {
|
|
23
|
+
// Normalize configuration with defaults
|
|
24
|
+
const config = (0, configurationHandler_1.normalizeConfig)(options);
|
|
25
|
+
// Get spreadsheet ID from environment variables
|
|
26
|
+
const { GOOGLE_SPREADSHEET_ID } = (0, validateEnv_1.validateEnv)();
|
|
27
|
+
// Initialize Google Spreadsheet connection
|
|
28
|
+
const serviceAuthClient = (0, auth_1.createAuthClient)();
|
|
29
|
+
const doc = new google_spreadsheet_1.GoogleSpreadsheet(GOOGLE_SPREADSHEET_ID, serviceAuthClient);
|
|
30
|
+
try {
|
|
31
|
+
await doc.loadInfo(true);
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
throw new Error(`Failed to load spreadsheet "${GOOGLE_SPREADSHEET_ID}"`, { cause: err });
|
|
35
|
+
}
|
|
36
|
+
// Prepare sheet titles to process
|
|
37
|
+
const docTitle = _docTitle ?? [];
|
|
38
|
+
if (docTitle.length === 0) {
|
|
39
|
+
console.warn("No sheet titles provided, cannot process spreadsheet data");
|
|
40
|
+
return {};
|
|
41
|
+
}
|
|
42
|
+
// Always include i18n sheet if not already present
|
|
43
|
+
if (!docTitle.includes("i18n")) {
|
|
44
|
+
docTitle.push("i18n");
|
|
45
|
+
}
|
|
46
|
+
console.log(`Processing ${docTitle.length} sheets: ${docTitle.join(", ")}`);
|
|
47
|
+
// Initialize result containers
|
|
48
|
+
const finalTranslations = {};
|
|
49
|
+
const allLocales = new Set();
|
|
50
|
+
const localesWithContent = new Set(); // Track locales with actual translations in non-i18n sheets
|
|
51
|
+
const globalLocaleMapping = {}; // normalized -> original header
|
|
52
|
+
const globalOriginalMapping = {}; // original header -> normalized
|
|
53
|
+
// Process each sheet in parallel
|
|
54
|
+
await Promise.all(docTitle.map(async (title) => {
|
|
55
|
+
await (0, wait_1.wait)(config.waitSeconds, `before get cells for sheet: ${title}`);
|
|
56
|
+
const sheet = doc.sheetsByTitle[title];
|
|
57
|
+
if (!sheet) {
|
|
58
|
+
console.warn(`Sheet "${title}" not found in the document`);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const result = await (0, sheetProcessor_1.processSheet)(sheet, title, config.rowLimit, config.waitSeconds);
|
|
62
|
+
if (result.success) {
|
|
63
|
+
// Merge locale mappings - prioritize first occurrence for consistency
|
|
64
|
+
for (const [normalized, original] of Object.entries(result.localeMapping)) {
|
|
65
|
+
if (!globalLocaleMapping[normalized]) {
|
|
66
|
+
globalLocaleMapping[normalized] = original;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
for (const [original, normalized] of Object.entries(result.originalMapping)) {
|
|
70
|
+
if (!globalOriginalMapping[original]) {
|
|
71
|
+
globalOriginalMapping[original] = normalized;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// Merge translations from this sheet into final result
|
|
75
|
+
for (const locale of result.locales) {
|
|
76
|
+
if (finalTranslations[locale]) {
|
|
77
|
+
finalTranslations[locale] = {
|
|
78
|
+
...finalTranslations[locale],
|
|
79
|
+
...result.translations[locale]
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
finalTranslations[locale] = result.translations[locale];
|
|
84
|
+
}
|
|
85
|
+
allLocales.add(locale);
|
|
86
|
+
// Only track locales with content from non-i18n sheets
|
|
87
|
+
if (title !== "i18n" && result.translations[locale] && Object.keys(result.translations[locale]).length > 0) {
|
|
88
|
+
// Check if this locale actually has translation content (not just empty objects)
|
|
89
|
+
const hasActualTranslations = Object.values(result.translations[locale]).some(sheetTranslations => Object.keys(sheetTranslations).length > 0);
|
|
90
|
+
if (hasActualTranslations) {
|
|
91
|
+
localesWithContent.add(locale);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}));
|
|
97
|
+
// Use locales with actual content for the locales file, fall back to all locales if none found
|
|
98
|
+
const localesForOutput = localesWithContent.size > 0 ? Array.from(localesWithContent) : Array.from(allLocales);
|
|
99
|
+
const allLocalesArray = Array.from(allLocales);
|
|
100
|
+
// Handle bidirectional sync if needed
|
|
101
|
+
const syncResult = await (0, syncManager_1.handleBidirectionalSync)(doc, config.dataJsonPath, config.translationsOutputDir, config.syncLocalChanges, config.autoTranslate, finalTranslations, config.waitSeconds, globalLocaleMapping);
|
|
102
|
+
// If sync requested a refresh, recursively call with updated data (depth-limited)
|
|
103
|
+
if (syncResult.shouldRefresh && _refreshDepth < MAX_SYNC_REFRESH_DEPTH) {
|
|
104
|
+
return getSpreadSheetData(_docTitle, {
|
|
105
|
+
...options,
|
|
106
|
+
syncLocalChanges: false,
|
|
107
|
+
}, _refreshDepth + 1);
|
|
108
|
+
}
|
|
109
|
+
// Write output files - use all locales for translation files but filtered locales for locales.ts
|
|
110
|
+
(0, fileWriter_1.writeTranslationFiles)(finalTranslations, allLocalesArray, config.translationsOutputDir);
|
|
111
|
+
(0, fileWriter_1.writeLocalesFile)(localesForOutput, globalLocaleMapping, config.localesOutputPath);
|
|
112
|
+
console.log(`Writing locales file with ${localesForOutput.length} locales that have actual translations:`, localesForOutput);
|
|
113
|
+
// Write languageData.json if we have fresh data or it doesn't exist
|
|
114
|
+
const hasData = Object.keys(finalTranslations).length > 0;
|
|
115
|
+
if (hasData) {
|
|
116
|
+
(0, fileWriter_1.writeLanguageDataFile)(finalTranslations, allLocalesArray, config.dataJsonPath);
|
|
117
|
+
}
|
|
118
|
+
return finalTranslations;
|
|
119
|
+
}
|
|
120
|
+
exports.default = getSpreadSheetData;
|
|
121
|
+
//# sourceMappingURL=getSpreadSheetData.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getSpreadSheetData.js","sourceRoot":"","sources":["../src/getSpreadSheetData.ts"],"names":[],"mappings":";;;AAoBA,gDAqIC;AAzJD,2DAAuD;AAEvD,uCAAoC;AACpC,uCAAgD;AAChD,qDAAkD;AAClD,uEAAwF;AACxF,2DAAsD;AACtD,mDAAoG;AACpG,qDAA8D;AAC9D,2CAAmD;AAC1C,qGADA,gCAAoB,OACA;AAE7B;;;;;GAKG;AACH,MAAM,sBAAsB,GAAG,CAAC,CAAC;AAE1B,KAAK,UAAU,kBAAkB,CACvC,SAAoB,EACpB,UAA8B,EAAE,EAChC,aAAa,GAAG,CAAC;IAEjB,wCAAwC;IACxC,MAAM,MAAM,GAAG,IAAA,sCAAe,EAAC,OAAO,CAAC,CAAC;IAExC,gDAAgD;IAChD,MAAM,EAAE,qBAAqB,EAAE,GAAG,I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AiB,EACjB,MAAM,CAAC,WAAW,EAClB,mBAAmB,CACnB,CAAC;IAEF,kFAAkF;IAClF,IAAI,UAAU,CAAC,aAAa,IAAI,aAAa,GAAG,sBAAsB,EAAE,CAAC;QACxE,OAAO,kBAAkB,CAAC,SAAS,EAAE;YACpC,GAAG,OAAO;YACV,gBAAgB,EAAE,KAAK;SACvB,EAAE,aAAa,GAAG,CAAC,CAAC,CAAC;IACvB,CAAC;IAED,iGAAiG;IACjG,IAAA,kCAAqB,EAAC,iBAAiB,EAAE,eAAe,EAAE,MAAM,CAAC,qBAAqB,CAAC,CAAC;IACxF,IAAA,6BAAgB,EAAC,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,CAAC,iBAAiB,CAAC,CAAC;IAElF,OAAO,CAAC,GAAG,CAAC,6BAA6B,gBAAgB,CAAC,MAAM,yCAAyC,EAAE,gBAAgB,CAAC,CAAC;IAE7H,oEAAoE;IACpE,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IAC1D,IAAI,OAAO,EAAE,CAAC;QACb,IAAA,kCAAqB,EAAC,iBAAiB,EAAE,eAAe,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC;IAChF,CAAC;IAED,OAAO,iBAAiB,CAAC;AAC1B,CAAC;AAED,kBAAe,kBAAkB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Google Sheet Translation Manager Package
|
|
3
|
+
* v2.0.0 – public API surface
|
|
4
|
+
*/
|
|
5
|
+
export { getSpreadSheetData, DEFAULT_WAIT_SECONDS } from './getSpreadSheetData';
|
|
6
|
+
export type { SpreadsheetOptions } from './utils/configurationHandler';
|
|
7
|
+
export { wait } from './utils/wait';
|
|
8
|
+
export { validateEnv } from './utils/validateEnv';
|
|
9
|
+
export { createAuthClient } from './utils/auth';
|
|
10
|
+
export { convertToDataJsonFormat } from './utils/dataConverter/convertToDataJsonFormat';
|
|
11
|
+
export { convertFromDataJsonFormat } from './utils/dataConverter/convertFromDataJsonFormat';
|
|
12
|
+
export { findLocalChanges } from './utils/dataConverter/findLocalChanges';
|
|
13
|
+
export { updateSpreadsheetWithLocalChanges } from './utils/spreadsheetUpdater';
|
|
14
|
+
export { isValidLocale, filterValidLocales } from './utils/localeFilter';
|
|
15
|
+
export type { TranslationData, TranslationValue, SheetRow, GoogleEnvVars, } from './types';
|
|
16
|
+
import { getSpreadSheetData } from './getSpreadSheetData';
|
|
17
|
+
export default getSpreadSheetData;
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAGhF,YAAY,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAGvE,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,uBAAuB,EAAE,MAAM,+CAA+C,CAAC;AACxF,OAAO,EAAE,yBAAyB,EAAE,MAAM,iDAAiD,CAAC;AAC5F,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AAC1E,OAAO,EAAE,iCAAiC,EAAE,MAAM,4BAA4B,CAAC;AAG/E,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAGzE,YAAY,EACV,eAAe,EACf,gBAAgB,EAChB,QAAQ,EACR,aAAa,GACd,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,eAAe,kBAAkB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Google Sheet Translation Manager Package
|
|
4
|
+
* v2.0.0 – public API surface
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.filterValidLocales = exports.isValidLocale = exports.updateSpreadsheetWithLocalChanges = exports.findLocalChanges = exports.convertFromDataJsonFormat = exports.convertToDataJsonFormat = exports.createAuthClient = exports.validateEnv = exports.wait = exports.DEFAULT_WAIT_SECONDS = exports.getSpreadSheetData = void 0;
|
|
8
|
+
// Main entry point
|
|
9
|
+
var getSpreadSheetData_1 = require("./getSpreadSheetData");
|
|
10
|
+
Object.defineProperty(exports, "getSpreadSheetData", { enumerable: true, get: function () { return getSpreadSheetData_1.getSpreadSheetData; } });
|
|
11
|
+
Object.defineProperty(exports, "DEFAULT_WAIT_SECONDS", { enumerable: true, get: function () { return getSpreadSheetData_1.DEFAULT_WAIT_SECONDS; } });
|
|
12
|
+
// Utility functions required by dependents
|
|
13
|
+
var wait_1 = require("./utils/wait");
|
|
14
|
+
Object.defineProperty(exports, "wait", { enumerable: true, get: function () { return wait_1.wait; } });
|
|
15
|
+
var validateEnv_1 = require("./utils/validateEnv");
|
|
16
|
+
Object.defineProperty(exports, "validateEnv", { enumerable: true, get: function () { return validateEnv_1.validateEnv; } });
|
|
17
|
+
var auth_1 = require("./utils/auth");
|
|
18
|
+
Object.defineProperty(exports, "createAuthClient", { enumerable: true, get: function () { return auth_1.createAuthClient; } });
|
|
19
|
+
var convertToDataJsonFormat_1 = require("./utils/dataConverter/convertToDataJsonFormat");
|
|
20
|
+
Object.defineProperty(exports, "convertToDataJsonFormat", { enumerable: true, get: function () { return convertToDataJsonFormat_1.convertToDataJsonFormat; } });
|
|
21
|
+
var convertFromDataJsonFormat_1 = require("./utils/dataConverter/convertFromDataJsonFormat");
|
|
22
|
+
Object.defineProperty(exports, "convertFromDataJsonFormat", { enumerable: true, get: function () { return convertFromDataJsonFormat_1.convertFromDataJsonFormat; } });
|
|
23
|
+
var findLocalChanges_1 = require("./utils/dataConverter/findLocalChanges");
|
|
24
|
+
Object.defineProperty(exports, "findLocalChanges", { enumerable: true, get: function () { return findLocalChanges_1.findLocalChanges; } });
|
|
25
|
+
var spreadsheetUpdater_1 = require("./utils/spreadsheetUpdater");
|
|
26
|
+
Object.defineProperty(exports, "updateSpreadsheetWithLocalChanges", { enumerable: true, get: function () { return spreadsheetUpdater_1.updateSpreadsheetWithLocalChanges; } });
|
|
27
|
+
// Locale validation utilities (useful standalone)
|
|
28
|
+
var localeFilter_1 = require("./utils/localeFilter");
|
|
29
|
+
Object.defineProperty(exports, "isValidLocale", { enumerable: true, get: function () { return localeFilter_1.isValidLocale; } });
|
|
30
|
+
Object.defineProperty(exports, "filterValidLocales", { enumerable: true, get: function () { return localeFilter_1.filterValidLocales; } });
|
|
31
|
+
// Default export
|
|
32
|
+
const getSpreadSheetData_2 = require("./getSpreadSheetData");
|
|
33
|
+
exports.default = getSpreadSheetData_2.getSpreadSheetData;
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,mBAAmB;AACnB,2DAAgF;AAAvE,wHAAA,kBAAkB,OAAA;AAAE,0HAAA,oBAAoB,OAAA;AAKjD,2CAA2C;AAC3C,qCAAoC;AAA3B,4FAAA,IAAI,OAAA;AACb,mDAAkD;AAAzC,0GAAA,WAAW,OAAA;AACpB,qCAAgD;AAAvC,wGAAA,gBAAgB,OAAA;AACzB,yFAAwF;AAA/E,kIAAA,uBAAuB,OAAA;AAChC,6FAA4F;AAAnF,sIAAA,yBAAyB,OAAA;AAClC,2EAA0E;AAAjE,oHAAA,gBAAgB,OAAA;AACzB,iEAA+E;AAAtE,uIAAA,iCAAiC,OAAA;AAE1C,kDAAkD;AAClD,qDAAyE;AAAhE,6GAAA,aAAa,OAAA;AAAE,kHAAA,kBAAkB,OAAA;AAU1C,iBAAiB;AACjB,6DAA0D;AAC1D,kBAAe,uCAAkB,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for translation values
|
|
3
|
+
*/
|
|
4
|
+
export type TranslationValue = string | number | boolean | Record<string, unknown> | unknown[];
|
|
5
|
+
/**
|
|
6
|
+
* Structure of translation data
|
|
7
|
+
* locale -> sheet -> key -> value
|
|
8
|
+
*/
|
|
9
|
+
export type TranslationData = Record<string, Record<string, Record<string, TranslationValue>>>;
|
|
10
|
+
/**
|
|
11
|
+
* Structure for a Google Sheet row
|
|
12
|
+
*/
|
|
13
|
+
export type SheetRow = Record<string, string>;
|
|
14
|
+
/**
|
|
15
|
+
* Environment variables required by the package
|
|
16
|
+
*/
|
|
17
|
+
export interface GoogleEnvVars {
|
|
18
|
+
GOOGLE_CLIENT_EMAIL: string;
|
|
19
|
+
GOOGLE_PRIVATE_KEY: string;
|
|
20
|
+
GOOGLE_SPREADSHEET_ID: string;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,gBAAgB,GACzB,MAAM,GACN,MAAM,GACN,OAAO,GACP,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACvB,OAAO,EAAE,CAAC;AAEb;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,CACnC,MAAM,EACN,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAChD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAE9C;;GAEG;AACH,MAAM,WAAW,aAAa;IAC7B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,qBAAqB,EAAE,MAAM,CAAC;CAC9B"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { JWT } from "google-auth-library";
|
|
2
|
+
/**
|
|
3
|
+
* Creates and returns a JWT auth client for Google Sheets API
|
|
4
|
+
* @returns JWT authentication client
|
|
5
|
+
*/
|
|
6
|
+
export declare function createAuthClient(): JWT;
|
|
7
|
+
export default createAuthClient;
|
|
8
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/utils/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAG1C;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,GAAG,CAQtC;AAED,eAAe,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createAuthClient = createAuthClient;
|
|
4
|
+
const google_auth_library_1 = require("google-auth-library");
|
|
5
|
+
const validateEnv_1 = require("./validateEnv");
|
|
6
|
+
/**
|
|
7
|
+
* Creates and returns a JWT auth client for Google Sheets API
|
|
8
|
+
* @returns JWT authentication client
|
|
9
|
+
*/
|
|
10
|
+
function createAuthClient() {
|
|
11
|
+
const { GOOGLE_CLIENT_EMAIL, GOOGLE_PRIVATE_KEY } = (0, validateEnv_1.validateEnv)();
|
|
12
|
+
return new google_auth_library_1.JWT({
|
|
13
|
+
email: GOOGLE_CLIENT_EMAIL,
|
|
14
|
+
key: GOOGLE_PRIVATE_KEY,
|
|
15
|
+
scopes: ["https://www.googleapis.com/auth/spreadsheets"],
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
exports.default = createAuthClient;
|
|
19
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/utils/auth.ts"],"names":[],"mappings":";;AAOA,4CAQC;AAfD,6DAA0C;AAC1C,+CAA4C;AAE5C;;;GAGG;AACH,SAAgB,gBAAgB;IAC/B,MAAM,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,GAAG,IAAA,yBAAW,GAAE,CAAC;IAElE,OAAO,IAAI,yBAAG,CAAC;QACd,KAAK,EAAE,mBAAmB;QAC1B,GAAG,EAAE,kBAAkB;QACvB,MAAM,EAAE,CAAC,8CAA8C,CAAC;KACxD,CAAC,CAAC;AACJ,CAAC;AAED,kBAAe,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration options for getSpreadSheetData
|
|
3
|
+
*/
|
|
4
|
+
export interface SpreadsheetOptions {
|
|
5
|
+
rowLimit?: number;
|
|
6
|
+
waitSeconds?: number;
|
|
7
|
+
dataJsonPath?: string;
|
|
8
|
+
localesOutputPath?: string;
|
|
9
|
+
translationsOutputDir?: string;
|
|
10
|
+
syncLocalChanges?: boolean;
|
|
11
|
+
autoTranslate?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Normalized configuration with all defaults applied
|
|
15
|
+
*/
|
|
16
|
+
export interface NormalizedConfig {
|
|
17
|
+
rowLimit: number;
|
|
18
|
+
waitSeconds: number;
|
|
19
|
+
dataJsonPath: string;
|
|
20
|
+
localesOutputPath: string;
|
|
21
|
+
translationsOutputDir: string;
|
|
22
|
+
syncLocalChanges: boolean;
|
|
23
|
+
autoTranslate: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Normalizes configuration options by applying defaults
|
|
27
|
+
*/
|
|
28
|
+
export declare function normalizeConfig(options?: SpreadsheetOptions): NormalizedConfig;
|
|
29
|
+
//# sourceMappingURL=configurationHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configurationHandler.d.ts","sourceRoot":"","sources":["../../src/utils/configurationHandler.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,aAAa,CAAC,EAAE,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,gBAAgB,EAAE,OAAO,CAAC;IAC1B,aAAa,EAAE,OAAO,CAAC;CACvB;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,GAAE,kBAAuB,GAAG,gBAAgB,CAUlF"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.normalizeConfig = normalizeConfig;
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const constants_1 = require("../constants");
|
|
9
|
+
/**
|
|
10
|
+
* Normalizes configuration options by applying defaults
|
|
11
|
+
*/
|
|
12
|
+
function normalizeConfig(options = {}) {
|
|
13
|
+
return {
|
|
14
|
+
rowLimit: options.rowLimit ?? 100,
|
|
15
|
+
waitSeconds: options.waitSeconds ?? constants_1.DEFAULT_WAIT_SECONDS,
|
|
16
|
+
dataJsonPath: options.dataJsonPath ?? node_path_1.default.join(process.cwd(), "src/lib/languageData.json"),
|
|
17
|
+
localesOutputPath: options.localesOutputPath ?? "src/i18n/locales.ts",
|
|
18
|
+
translationsOutputDir: options.translationsOutputDir ?? "translations",
|
|
19
|
+
syncLocalChanges: options.syncLocalChanges !== false, // Default to true
|
|
20
|
+
autoTranslate: options.autoTranslate === true, // Default to false
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=configurationHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configurationHandler.js","sourceRoot":"","sources":["../../src/utils/configurationHandler.ts"],"names":[],"mappings":";;;;;AAgCA,0CAUC;AA1CD,0DAA6B;AAC7B,4CAAoD;AA4BpD;;GAEG;AACH,SAAgB,eAAe,CAAC,UAA8B,EAAE;IAC/D,OAAO;QACN,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,GAAG;QACjC,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,gCAAoB;QACxD,YAAY,EAAE,OAAO,CAAC,YAAY,IAAI,mBAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,2BAA2B,CAAC;QAC3F,iBAAiB,EAAE,OAAO,CAAC,iBAAiB,IAAI,qBAAqB;QACrE,qBAAqB,EAAE,OAAO,CAAC,qBAAqB,IAAI,cAAc;QACtE,gBAAgB,EAAE,OAAO,CAAC,gBAAgB,KAAK,KAAK,EAAE,kBAAkB;QACxE,aAAa,EAAE,OAAO,CAAC,aAAa,KAAK,IAAI,EAAE,mBAAmB;KAClE,CAAC;AACH,CAAC"}
|