@el-j/google-sheet-translations 1.3.2 → 1.4.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/README.md +58 -55
- package/dist/action-entrypoint.d.ts +2 -0
- package/dist/action-entrypoint.d.ts.map +1 -0
- package/dist/esm/index.js +1226 -0
- package/dist/esm/package.json +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1288 -41
- package/dist/utils/dataConverter/findLocalChanges.d.ts +10 -1
- package/dist/utils/dataConverter/findLocalChanges.d.ts.map +1 -1
- package/dist/utils/localeNormalizer.d.ts +53 -2
- package/dist/utils/localeNormalizer.d.ts.map +1 -1
- package/dist/utils/spreadsheetUpdater.d.ts +6 -1
- package/dist/utils/spreadsheetUpdater.d.ts.map +1 -1
- package/dist/utils/translationHelpers.d.ts +107 -0
- package/dist/utils/translationHelpers.d.ts.map +1 -0
- package/package.json +21 -14
- package/dist/constants.js +0 -9
- package/dist/constants.js.map +0 -1
- package/dist/getSpreadSheetData.js +0 -170
- package/dist/getSpreadSheetData.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/types.js +0 -3
- package/dist/types.js.map +0 -1
- package/dist/utils/auth.js +0 -23
- package/dist/utils/auth.js.map +0 -1
- package/dist/utils/configurationHandler.js +0 -29
- package/dist/utils/configurationHandler.js.map +0 -1
- package/dist/utils/dataConverter/convertFromDataJsonFormat.js +0 -47
- package/dist/utils/dataConverter/convertFromDataJsonFormat.js.map +0 -1
- package/dist/utils/dataConverter/convertToDataJsonFormat.js +0 -51
- package/dist/utils/dataConverter/convertToDataJsonFormat.js.map +0 -1
- package/dist/utils/dataConverter/findLocalChanges.js +0 -39
- package/dist/utils/dataConverter/findLocalChanges.js.map +0 -1
- package/dist/utils/fileWriter.js +0 -119
- package/dist/utils/fileWriter.js.map +0 -1
- package/dist/utils/getFileLastModified.js +0 -23
- package/dist/utils/getFileLastModified.js.map +0 -1
- package/dist/utils/isDataJsonNewer.js +0 -40
- package/dist/utils/isDataJsonNewer.js.map +0 -1
- package/dist/utils/localeFilter.js +0 -49
- package/dist/utils/localeFilter.js.map +0 -1
- package/dist/utils/localeNormalizer.js +0 -145
- package/dist/utils/localeNormalizer.js.map +0 -1
- package/dist/utils/publicSheetReader.js +0 -109
- package/dist/utils/publicSheetReader.js.map +0 -1
- package/dist/utils/rateLimiter.js +0 -55
- package/dist/utils/rateLimiter.js.map +0 -1
- package/dist/utils/readDataJson.js +0 -29
- package/dist/utils/readDataJson.js.map +0 -1
- package/dist/utils/sheetProcessor.js +0 -121
- package/dist/utils/sheetProcessor.js.map +0 -1
- package/dist/utils/spreadsheetCreator.js +0 -121
- package/dist/utils/spreadsheetCreator.js.map +0 -1
- package/dist/utils/spreadsheetUpdater.js +0 -194
- package/dist/utils/spreadsheetUpdater.js.map +0 -1
- package/dist/utils/syncManager.js +0 -62
- package/dist/utils/syncManager.js.map +0 -1
- package/dist/utils/validateEnv.js +0 -41
- package/dist/utils/validateEnv.js.map +0 -1
- package/dist/utils/wait.js +0 -19
- package/dist/utils/wait.js.map +0 -1
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ A Node.js package for managing translations stored in Google Sheets.
|
|
|
11
11
|
- ✅ **Modular Architecture**: Well-tested, maintainable codebase with clear separation of concerns
|
|
12
12
|
- ✅ **Next.js Integration**: Built-in support for Next.js static export workflows
|
|
13
13
|
- ✅ **Flexible Configuration**: Customizable paths, wait times, and processing options
|
|
14
|
-
- ✅ **GitHub Action**: One-step CI integration via
|
|
14
|
+
- ✅ **GitHub Action**: One-step CI integration via `el-j/google-sheet-translations@v2` — see [GitHub Action](#github-action)
|
|
15
15
|
|
|
16
16
|
## Installation
|
|
17
17
|
|
|
@@ -290,96 +290,99 @@ For more detailed examples, check out the [examples directory](examples) where y
|
|
|
290
290
|
This repository ships a composite GitHub Action that lets you fetch translations
|
|
291
291
|
in any workflow **without writing any Node.js scripts yourself**.
|
|
292
292
|
|
|
293
|
-
### Quick
|
|
293
|
+
### Quick Start
|
|
294
294
|
|
|
295
295
|
Add the following step to your workflow after checking out your repository:
|
|
296
296
|
|
|
297
297
|
```yaml
|
|
298
298
|
- name: Fetch translations
|
|
299
|
-
uses: el-j/google-sheet-translations@
|
|
299
|
+
uses: el-j/google-sheet-translations@v2
|
|
300
300
|
with:
|
|
301
|
-
google-client-email:
|
|
302
|
-
google-private-key:
|
|
301
|
+
google-client-email: ${{ secrets.GOOGLE_CLIENT_EMAIL }}
|
|
302
|
+
google-private-key: ${{ secrets.GOOGLE_PRIVATE_KEY }}
|
|
303
303
|
google-spreadsheet-id: ${{ secrets.GOOGLE_SPREADSHEET_ID }}
|
|
304
|
-
sheet-titles: '
|
|
304
|
+
sheet-titles: 'home,about,pricing'
|
|
305
305
|
```
|
|
306
306
|
|
|
307
|
-
###
|
|
307
|
+
### Required Secrets
|
|
308
308
|
|
|
309
|
-
|
|
310
|
-
|-------|----------|---------|-------------|
|
|
311
|
-
| `google-client-email` | ✅ | — | Service-account e-mail (`GOOGLE_CLIENT_EMAIL`) |
|
|
312
|
-
| `google-private-key` | ✅ | — | Service-account private key (`GOOGLE_PRIVATE_KEY`) |
|
|
313
|
-
| `google-spreadsheet-id` | ✅ | — | Spreadsheet ID from the sheet URL (`GOOGLE_SPREADSHEET_ID`) |
|
|
314
|
-
| `sheet-titles` | ✅ | — | Comma-separated list of sheet tab names to process |
|
|
315
|
-
| `row-limit` | ❌ | `100` | Maximum rows to read per sheet |
|
|
316
|
-
| `wait-seconds` | ❌ | `1` | Base back-off delay in seconds for retrying rate-limited API calls (HTTP 429/503) |
|
|
317
|
-
| `translations-output-dir` | ❌ | `translations` | Directory for per-locale JSON files |
|
|
318
|
-
| `locales-output-path` | ❌ | `src/i18n/locales.ts` | Path for the generated `locales.ts` |
|
|
319
|
-
| `data-json-path` | ❌ | `src/lib/languageData.json` | Path for the `languageData.json` snapshot |
|
|
320
|
-
| `sync-local-changes` | ❌ | `true` | Push local changes back to the sheet before fetching |
|
|
321
|
-
| `node-version` | ❌ | `20` | Node.js version used to run the fetch script |
|
|
322
|
-
| `package-version` | ❌ | `latest` | Version of `@el-j/google-sheet-translations` to install |
|
|
323
|
-
|
|
324
|
-
### Outputs
|
|
309
|
+
Store these as [encrypted repository secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets) before using the action:
|
|
325
310
|
|
|
326
|
-
|
|
|
311
|
+
| Secret | Description |
|
|
327
312
|
|--------|-------------|
|
|
328
|
-
| `
|
|
329
|
-
| `
|
|
330
|
-
| `
|
|
313
|
+
| `GOOGLE_CLIENT_EMAIL` | Service-account e-mail from your Google Cloud credentials JSON |
|
|
314
|
+
| `GOOGLE_PRIVATE_KEY` | Private key from your Google Cloud credentials JSON (include the full PEM block) |
|
|
315
|
+
| `GOOGLE_SPREADSHEET_ID` | The long ID found in the spreadsheet URL: `…/spreadsheets/d/<ID>/edit` (can be left empty to trigger auto-create) |
|
|
331
316
|
|
|
332
|
-
###
|
|
317
|
+
### Complete Example
|
|
333
318
|
|
|
334
|
-
|
|
335
|
-
name: Update Translations
|
|
319
|
+
Full workflow that fetches translations on a schedule and commits the results:
|
|
336
320
|
|
|
321
|
+
```yaml
|
|
322
|
+
name: Sync Translations
|
|
337
323
|
on:
|
|
338
324
|
schedule:
|
|
339
325
|
- cron: '0 6 * * 1' # every Monday at 06:00 UTC
|
|
340
326
|
workflow_dispatch:
|
|
341
327
|
|
|
342
328
|
jobs:
|
|
343
|
-
|
|
329
|
+
sync:
|
|
344
330
|
runs-on: ubuntu-latest
|
|
345
|
-
permissions:
|
|
346
|
-
contents: write
|
|
347
|
-
|
|
348
331
|
steps:
|
|
349
|
-
-
|
|
350
|
-
uses: actions/checkout@v4
|
|
332
|
+
- uses: actions/checkout@v4
|
|
351
333
|
|
|
352
334
|
- name: Fetch translations
|
|
353
335
|
id: translations
|
|
354
|
-
uses: el-j/google-sheet-translations@
|
|
336
|
+
uses: el-j/google-sheet-translations@v2
|
|
355
337
|
with:
|
|
356
|
-
google-client-email:
|
|
357
|
-
google-private-key:
|
|
338
|
+
google-client-email: ${{ secrets.GOOGLE_CLIENT_EMAIL }}
|
|
339
|
+
google-private-key: ${{ secrets.GOOGLE_PRIVATE_KEY }}
|
|
358
340
|
google-spreadsheet-id: ${{ secrets.GOOGLE_SPREADSHEET_ID }}
|
|
359
|
-
sheet-titles:
|
|
341
|
+
sheet-titles: 'home,about,pricing'
|
|
360
342
|
translations-output-dir: 'src/translations'
|
|
361
|
-
locales-output-path:
|
|
362
|
-
data-json-path:
|
|
343
|
+
locales-output-path: 'src/i18n/locales.ts'
|
|
344
|
+
data-json-path: 'src/lib/languageData.json'
|
|
345
|
+
sync-local-changes: 'true'
|
|
363
346
|
|
|
364
347
|
- name: Commit updated translations
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
${{ steps.translations.outputs.data-json-file }}
|
|
348
|
+
run: |
|
|
349
|
+
git config user.name "github-actions[bot]"
|
|
350
|
+
git config user.email "github-actions[bot]@users.noreply.github.com"
|
|
351
|
+
git add src/translations src/i18n/locales.ts src/lib/languageData.json
|
|
352
|
+
git diff --staged --quiet || git commit -m "chore(i18n): sync translations from Google Sheets [skip ci]"
|
|
353
|
+
git push
|
|
372
354
|
```
|
|
373
355
|
|
|
374
|
-
###
|
|
356
|
+
### All Inputs
|
|
357
|
+
|
|
358
|
+
| Input | Required | Default | Description |
|
|
359
|
+
|-------|----------|---------|-------------|
|
|
360
|
+
| `google-client-email` | ✅ | — | Service-account e-mail (`GOOGLE_CLIENT_EMAIL`) |
|
|
361
|
+
| `google-private-key` | ✅ | — | Service-account private key (`GOOGLE_PRIVATE_KEY`) |
|
|
362
|
+
| `google-spreadsheet-id` | ❌ | `''` | Spreadsheet ID from the sheet URL; if empty and `auto-create` is `true`, a new spreadsheet is auto-created |
|
|
363
|
+
| `sheet-titles` | ✅ | — | Comma-separated list of sheet tab names to process (`i18n` is always auto-included) |
|
|
364
|
+
| `row-limit` | ❌ | `100` | Maximum rows to read per sheet |
|
|
365
|
+
| `wait-seconds` | ❌ | `1` | Base back-off delay in seconds for retrying rate-limited API calls (HTTP 429/503) |
|
|
366
|
+
| `translations-output-dir` | ❌ | `translations` | Directory for per-locale JSON files |
|
|
367
|
+
| `locales-output-path` | ❌ | `src/i18n/locales.ts` | Path for the generated `locales.ts` |
|
|
368
|
+
| `data-json-path` | ❌ | `src/lib/languageData.json` | Path for the `languageData.json` snapshot |
|
|
369
|
+
| `sync-local-changes` | ❌ | `true` | Push local changes back to the sheet before fetching |
|
|
370
|
+
| `auto-create` | ❌ | `true` | Automatically create a new spreadsheet when `google-spreadsheet-id` is empty |
|
|
371
|
+
| `spreadsheet-title` | ❌ | `google-sheet-translations` | Title for the auto-created spreadsheet |
|
|
372
|
+
| `source-locale` | ❌ | `en` | Source locale used as the base for auto-translate formulas |
|
|
373
|
+
| `target-locales` | ❌ | `de,fr,es,it,pt,ja,zh` | Comma-separated target locales added to the auto-created spreadsheet |
|
|
375
374
|
|
|
376
|
-
|
|
375
|
+
### Outputs
|
|
377
376
|
|
|
378
|
-
|
|
|
377
|
+
| Output | Description |
|
|
379
378
|
|--------|-------------|
|
|
380
|
-
| `
|
|
381
|
-
| `
|
|
382
|
-
| `
|
|
379
|
+
| `translations-dir` | Absolute path of the directory containing locale JSON files |
|
|
380
|
+
| `locales-file` | Absolute path of the generated `locales.ts` |
|
|
381
|
+
| `data-json-file` | Absolute path of the `languageData.json` snapshot |
|
|
382
|
+
|
|
383
|
+
### Auto-Create Feature
|
|
384
|
+
|
|
385
|
+
If `google-spreadsheet-id` is left empty and `auto-create` is `true` (the default), the action will automatically create a new Google Spreadsheet using your service-account credentials. The spreadsheet is pre-populated with an `i18n` starter sheet containing `GOOGLETRANSLATE` formulas for every locale listed in `target-locales`. The new spreadsheet ID is printed to the workflow log and written to your `.env` file (if one exists in the repository root), allowing you to commit it and reuse it in future runs.
|
|
383
386
|
|
|
384
387
|
## License
|
|
385
388
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action-entrypoint.d.ts","sourceRoot":"","sources":["../src/action-entrypoint.ts"],"names":[],"mappings":"AAKA,wBAAsB,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,CA4DzC"}
|