@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.
Files changed (62) hide show
  1. package/README.md +58 -55
  2. package/dist/action-entrypoint.d.ts +2 -0
  3. package/dist/action-entrypoint.d.ts.map +1 -0
  4. package/dist/esm/index.js +1226 -0
  5. package/dist/esm/package.json +1 -0
  6. package/dist/index.d.ts +8 -0
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +1288 -41
  9. package/dist/utils/dataConverter/findLocalChanges.d.ts +10 -1
  10. package/dist/utils/dataConverter/findLocalChanges.d.ts.map +1 -1
  11. package/dist/utils/localeNormalizer.d.ts +53 -2
  12. package/dist/utils/localeNormalizer.d.ts.map +1 -1
  13. package/dist/utils/spreadsheetUpdater.d.ts +6 -1
  14. package/dist/utils/spreadsheetUpdater.d.ts.map +1 -1
  15. package/dist/utils/translationHelpers.d.ts +107 -0
  16. package/dist/utils/translationHelpers.d.ts.map +1 -0
  17. package/package.json +21 -14
  18. package/dist/constants.js +0 -9
  19. package/dist/constants.js.map +0 -1
  20. package/dist/getSpreadSheetData.js +0 -170
  21. package/dist/getSpreadSheetData.js.map +0 -1
  22. package/dist/index.js.map +0 -1
  23. package/dist/types.js +0 -3
  24. package/dist/types.js.map +0 -1
  25. package/dist/utils/auth.js +0 -23
  26. package/dist/utils/auth.js.map +0 -1
  27. package/dist/utils/configurationHandler.js +0 -29
  28. package/dist/utils/configurationHandler.js.map +0 -1
  29. package/dist/utils/dataConverter/convertFromDataJsonFormat.js +0 -47
  30. package/dist/utils/dataConverter/convertFromDataJsonFormat.js.map +0 -1
  31. package/dist/utils/dataConverter/convertToDataJsonFormat.js +0 -51
  32. package/dist/utils/dataConverter/convertToDataJsonFormat.js.map +0 -1
  33. package/dist/utils/dataConverter/findLocalChanges.js +0 -39
  34. package/dist/utils/dataConverter/findLocalChanges.js.map +0 -1
  35. package/dist/utils/fileWriter.js +0 -119
  36. package/dist/utils/fileWriter.js.map +0 -1
  37. package/dist/utils/getFileLastModified.js +0 -23
  38. package/dist/utils/getFileLastModified.js.map +0 -1
  39. package/dist/utils/isDataJsonNewer.js +0 -40
  40. package/dist/utils/isDataJsonNewer.js.map +0 -1
  41. package/dist/utils/localeFilter.js +0 -49
  42. package/dist/utils/localeFilter.js.map +0 -1
  43. package/dist/utils/localeNormalizer.js +0 -145
  44. package/dist/utils/localeNormalizer.js.map +0 -1
  45. package/dist/utils/publicSheetReader.js +0 -109
  46. package/dist/utils/publicSheetReader.js.map +0 -1
  47. package/dist/utils/rateLimiter.js +0 -55
  48. package/dist/utils/rateLimiter.js.map +0 -1
  49. package/dist/utils/readDataJson.js +0 -29
  50. package/dist/utils/readDataJson.js.map +0 -1
  51. package/dist/utils/sheetProcessor.js +0 -121
  52. package/dist/utils/sheetProcessor.js.map +0 -1
  53. package/dist/utils/spreadsheetCreator.js +0 -121
  54. package/dist/utils/spreadsheetCreator.js.map +0 -1
  55. package/dist/utils/spreadsheetUpdater.js +0 -194
  56. package/dist/utils/spreadsheetUpdater.js.map +0 -1
  57. package/dist/utils/syncManager.js +0 -62
  58. package/dist/utils/syncManager.js.map +0 -1
  59. package/dist/utils/validateEnv.js +0 -41
  60. package/dist/utils/validateEnv.js.map +0 -1
  61. package/dist/utils/wait.js +0 -19
  62. 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 the bundled composite action
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 start
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@v1 # pin to a specific release tag for stability
299
+ uses: el-j/google-sheet-translations@v2
300
300
  with:
301
- google-client-email: ${{ secrets.GOOGLE_CLIENT_EMAIL }}
302
- google-private-key: ${{ secrets.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: 'landingPage,about' # comma-separated sheet tab names
304
+ sheet-titles: 'home,about,pricing'
305
305
  ```
306
306
 
307
- ### Inputs
307
+ ### Required Secrets
308
308
 
309
- | Input | Required | Default | Description |
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
- | Output | Description |
311
+ | Secret | Description |
327
312
  |--------|-------------|
328
- | `translations-dir` | Absolute path of the directory containing locale JSON files |
329
- | `locales-file` | Absolute path of the generated `locales.ts` |
330
- | `data-json-file` | Absolute path of the `languageData.json` snapshot |
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
- ### Full workflow example
317
+ ### Complete Example
333
318
 
334
- ```yaml
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
- update-translations:
329
+ sync:
344
330
  runs-on: ubuntu-latest
345
- permissions:
346
- contents: write
347
-
348
331
  steps:
349
- - name: Checkout
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@v1
336
+ uses: el-j/google-sheet-translations@v2
355
337
  with:
356
- google-client-email: ${{ secrets.GOOGLE_CLIENT_EMAIL }}
357
- google-private-key: ${{ secrets.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: 'landingPage,about'
341
+ sheet-titles: 'home,about,pricing'
360
342
  translations-output-dir: 'src/translations'
361
- locales-output-path: 'src/i18n/locales.ts'
362
- data-json-path: 'src/lib/languageData.json'
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
- uses: stefanzweifel/git-auto-commit-action@v5
366
- with:
367
- commit_message: 'chore(i18n): update translations from Google Sheets'
368
- file_pattern: |
369
- ${{ steps.translations.outputs.translations-dir }}/**
370
- ${{ steps.translations.outputs.locales-file }}
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
- ### Required secrets
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
- Store these as [encrypted repository secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets):
375
+ ### Outputs
377
376
 
378
- | Secret | Description |
377
+ | Output | Description |
379
378
  |--------|-------------|
380
- | `GOOGLE_CLIENT_EMAIL` | Service-account e-mail from your Google Cloud credentials JSON |
381
- | `GOOGLE_PRIVATE_KEY` | Private key from your Google Cloud credentials JSON (include the full PEM block) |
382
- | `GOOGLE_SPREADSHEET_ID` | The long ID found in the spreadsheet URL: `…/spreadsheets/d/<ID>/edit` |
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,2 @@
1
+ export declare function run(): Promise<void>;
2
+ //# sourceMappingURL=action-entrypoint.d.ts.map
@@ -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"}