GTranslate is a tool for managing static translations using Google Sheets. This helps buisness team to manage translations using sheets which can then be synced with local translation (json) files using cli command.
npm install --global https://github.com/oozou/gtranslate
This will install gtranslate
globally so that it may be run from the command line anywhere.
npm install https://github.com/oozou/gtranslate --save-dev
gtranslate
./node-modules/.bin/gtranslate.js
OR
yarn sync
- Visit Google developers console and create a project
- Enable Google Sheets API ( Visit Library > Google Sheets API > Enable )
- Configure OAuth consent screen
- Create "Oauth client ID" credentials for Desktop app
- Download secret file for created credentials and save it as "credentials.json" under project root
- Anyone with edit access to this file can update it using this package
[en.json]
{
"homepage": {
"hello": "Hello",
"goodMorning": "Good morning"
}
}
[th.json]
{
"homepage": {
"hello": "สวัสดี",
"goodMorning": "กริ้งมอหนูด"
}
}
- For first run, setup some sample translations to be set to google sheet
In the project npm root path create file "translate-config.json"
{
"sheetId": "<sheetId>",
"sheetName": "<sheetName>",
"locales": ["th", "en"],
"translationsPath": "src/lang"
}
Key | Description |
---|---|
sheetId |
Google sheet ID (Can be found in google sheet URL) |
sheetName |
Google sheet Name (Can be found on the bottom left tabs under google sheet UI) |
locales |
(array) In case your translation file is split into multiple files (en.json, th.json) |
translationsPath |
(optional) Output folder of localization files |
- Run the script following steps in
Usage
section - When running this first time, you will be prompted to visit an external url
- Copy that url, open in browser and authorize the application
- Finally, you will be prompted with a code in browser
- Copy over the code to previous terminal
- NOTE : This will run the sync translations script as well
- Translations in google sheet will always be prioritized
- To add a new key to translation, add it to local "translations.json" file with mock data and run the script
- To remove a key, remove keys from both sheet and local "translations.json" file and run the script
- For multiple translation files each .json will be combined and flattened to translations.json