Configuration
In order to start using babelsheet, you have to configure your .env.babelsheet
file first. If you want, you can keep envs in .env
file, all variables stored in .env
will be overwritten by those stored in .env.babelsheet
.
Configuration file
BABELSHEET_CLIENT_ID=<GOOGLE-CLIENT-ID>
BABELSHEET_CLIENT_SECRET=<GOOGLE-CLIENT-SECRET>
BABELSHEET_SPREADSHEET_ID=<SPREADSHEET-ID>
BABELSHEET_SPREADSHEET_NAME=<SPREADSHEET-NAME>
BABELSHEET_REFRESH_TOKEN=<REFRESH-TOKEN>
BABELSHEET_REDIRECT_URI=http://localhost:3000/oauth2callback
BABELSHEET_REDIS_HOST=redis
BABELSHEET_REDIS_PORT=6379
BABELSHEET_HOST=localhost
BABELSHEET_PORT=3000
NODE_ENV=dev
APP_NAME=babelsheet-node
LOGGING_LEVEL=debug
Configuration options
BABELSHEET_CLIENT_ID
* - client id received from Google (see how to config)
BABELSHEET_CLIENT_SECRET
* - client secret received from Google (see how to config)
Spreadsheet ID can be taken from spreadsheet url. It's the part after BABELSHEET_SPREADSHEET_ID
* - spreadsheet ID from spreadsheet URL
How to get spreadsheet ID
/d/
sign:
https://docs.google.com/spreadsheets/d/<spreadsheet-id>/
Spreadsheet name is the name of the tab in spreadsheet document.
BABELSHEET_SPREADSHEET_NAME
* - sheet name
How to get spreadsheet name
BABELSHEET_REFRESH_TOKEN
* - refresh token (see how to obtain)
BABELSHEET_REDIRECT_URI
- url to which user should be redirected after receiving refresh token
BABELSHEET_REDIS_HOST
- host name of redis store
BABELSHEET_REDIS_PORT
- port of redis store
BABELSHEET_HOST
- host name for winston
BABELSHEET_PORT
- API port
NODE_ENV
- environment type
APP_NAME
- name which indentify app
LOGGING_LEVEL
- Log level debug/error/info
* - required
Configuring Google Spreadsheet API
- Create account in Google Cloud Platform.
Creating account in details
Go to https://cloud.google.com/. Click Try free, then fill the form, next click Agree and continue and Submit.
- Create a project in Google Cloud Platform and enable Google Sheets API usage (section API & Services dashboard).
Creating project with enable API in details
Go to https://console.cloud.google.com. Click Select a project, then NEW PROJECT, write name of the project and click CREATE.
Choose API.
Click ENABLE APIS AND SERVICES.
Find Google sheets.
Click Enable.
- Go to section Create credendials and fill in the form with proper product name, e-mail address, redirect uri as
http://localhost:3000/oauth2callback
then click Done.Creating credentials in details
From previous view, select Create credentials.
Fill the form and click Done.
IMPORTANT! Remember to add
http://localhost:3000/oauth2callback
to 'Authorised redirect URIs', you can add any other redirect uri, later passing it asBABELSHEET_REDIRECT_URI
in .env.babelsheet file. - You will be given Client ID and Client secret keys, use them in environment variables
BABELSHEET_CLIENT_ID
andBABELSHEET_CLIENT_SECRET
in.env.babelsheet
file. - You can get your spreadsheet ID and spreadsheet name, then you will be ready to generate translations.
Generating refresh token
- To generate refresh token, you have to configure Google Spreadsheet API first.
- When
BABELSHEET_CLIENT_ID
andBABELSHEET_CLIENT_SECRET
are stored in.env.babelsheet
file, you are ready to generate refresh-token. -
Run
babelsheet init
.If babelsheet is not installed, run
npm i -g babelsheet
to install.BABELSHEET_CLIENT_ID and BABELSHEET_CLIENT_SECRET as params
You don't have to create .env.babelsheet file, you can pass BABELSHEET_CLIENT_ID and BABELSHEET_CLIENT_SECRET values as parameters to babelsheet:
npm generate --client_id <yours-client-id> --client_secret <yours-client-secret>
Config in json file
You can also generate token in
data.json
file, just by passingjson
parameter optionnpm init --config-format json
. -
Browser window will be opened automatically. Log in into you Google account and then grant your application an access for reading spreadsheets in your account. You should be given a message
Authentication successful! Please return to the console
. - Refresh token is now stored in
.env.babelsheet
file. You can change storage type here. - More actions won't be needed because tokens will be refreshed automatically if necessary.