New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@ace-de/eua-translations-sync

Package Overview
Dependencies
Maintainers
0
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ace-de/eua-translations-sync

EUA sync local translate with Google sheet

  • 2.1.4
  • npm
  • Socket score

Version published
Weekly downloads
132
decreased by-24.14%
Maintainers
0
Weekly downloads
 
Created
Source

Translation sync package (@ace-de/eua-wa-lib/eua-translation-sync)

This package allows us to sync translations in relation: local translation files <-> corresponding Google Spreadsheet. Sync can be triggered manually or automatically.

We're using two types of scripts:

  1. Push script
$ npm run push:i18n # add new translation tokens with their values, wouldn't chane existing tokens and their values
$ npm run push:i18n --replace-modified # changed token value from JSON file update in GSheet document 
$ npm run push:i18n --cleanup-tokens # remove tokens from GSheet document if don't exist in JSON file 
  1. Pull script
$ npm run pull:i18n # overwrite JSON token value with value from GSheet, don't change token keys in local JSON 
$ npm run pull:i18n --get-new-tokens # add tokens to local JSON if GSheet document has a new tokens

Manually triggered sync

In order to manually start translation sync, app's package.json must contain following scripts:

"push:i18n": "translations-sync push",
"pull:i18n": "translations-sync pull"

Also, we need Google Sheet API and spreadsheet credentials stored in .env file:

GOOGLE_SPREADSHEET_ID= can be extracted from the URL --> https://docs.google.com/spreadsheets/d/spreadsheetId/edit#gid=0
GOOGLE_SHEET_ID= can be extracetd from the URL --> https://docs.google.com/spreadsheets/d/aBC-123_xYz/edit#gid=sheetId 
GOOGLE_SHEET_NAME= name of sheet that corresponds to sheetId
GOOGLE_SERVICE_ACCOUNT_EMAIL= service account's email, created on Google Cloud (https://cloud.google.com/iam/docs/service-account-overview) and specific for each app
GOOGLE_PRIVATE_KEY= private key of the created service account
LOCALE_TRANSLATION_EN_US_PATH=
LOCALE_TRANSLATION_DE_DE_PATH=

For manual sync we should follow these steps in the specified order:

  1. If we have new translation keys with values in local files, execute push script
npm run push:i18n
  1. Run pull script for getting and writing all changes from defined sheet into local files
npm run pull:i18n --get-new-tokens
  1. Go through changes in local files (created after pull script completion) and carefully determine what changes should be preserved and what should be reverted
  2. If some translation keys' values were changed, run following command in order to make the same changes in the sheet:
npm run push:i18n --replace-modified
  1. If we removed some translation keys from the local files, we should reflect it on corresponding sheet by running:
npm run push:i18n --cleanup-tokens

At this point everything should be synced and local files should be 1:1 with the corresponding sheet.

Automatically triggered sync

On each app's version change, automatic sync can be triggered by extending package.json's scripts with:

"preversion": "translations-sync",

For the automation to work, we need reduced version of the .env file, with no specified sheets' IDs and names, as we're getting those from spreadsheet itself:

GOOGLE_SPREADSHEET_ID=
GOOGLE_SERVICE_ACCOUNT_EMAIL=
GOOGLE_PRIVATE_KEY=
LOCALE_TRANSLATION_EN_US_PATH=
LOCALE_TRANSLATION_DE_DE_PATH=
LOCALE_TRANSLATIONS_PATH= path to the directory of the local translation files

The consequence is that on each version increase with command npm version some-version translation sync is triggered and following is executed:

  • getting current (new) app version
  • determining sheet that should be updated --> if version is alpha version, sync is done for DEV and INT sheets, otherwise we're syncing with PP sheet
  • getting git differences between current and previous version --> all translation changes found within git diff have priority over changes in spreadsheet
  • if new translation keys are found within git diff, push script for adding new keys with its values into specified sheet is triggered
  • running pull script for getting all changes from the specified sheet and writing those changes into local files (this step is always triggered) --> local values are replaced only in a case when those changes are not in a conflict with changes from git diff (local changes made between the last two versions have priority)
  • if git diff detects removed translation keys or changes of their values, push script for removing tokens and changing tokens' values (--replace-modified and --cleanup-tokens) on specified sheet is triggered
  • checking if pull script made some changes within local files
  • commiting and pushing changes to the origin/current-branch, if changes exist

At this point local files should be 1:1 with the corresponding sheet and changes commited and pushed to the origin.

FAQs

Package last updated on 18 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc