Services
CLI
Command line tool is used to obtain BABELSHEET_REFRESH_TOKEN
, as well as to generate translations files.
Translations files are possible to generate in given formats:
- Android
- iOS
- JSON
- YML
To run command line tools, you need to install it first:
npm i -g babelsheet
If you want to obtain BABELSHEET_REFRESH_TOKEN
then see generating refresh token section.
Generating translations files
To generate translations type:
babelsheet generate [options]
Remember to create .env.babelsheet file before generating translations.
If you wont provide BABELSHEET_REFRESH_TOKEN
in .env.babelsheet
file or data.json
file, babelsheet will automatically open browser to create such token, and will save it in right storage - you can change read and write storages, check it here.
Options
(alias:
(default:
Where to store config (refresh token) env/json.
(alias:
(default:
Format type (android/ios/json/yml/xlf).
(alias:
(default:
Path for saving files.
(alias:
Language code for generating translations only in given language.
(alias:
(default:
Filename of final translation file.
(default:
Base language for translations.
Creates one file with all languages.
Client id received from Google. Overwrite .env.babelsheet
Client secret received from Google. Overwrite .env.babelsheet
Spreadsheet ID from spreadsheet URL. Overwrite .env.babelsheet
Sheet name. Overwrite .env.babelsheet
Url to which user should be redirected after receiving refresh token. Overwrite .env.babelsheet
Help menu.
--config-format
-cf
)
env
)
--format
-f
)
json
)
--path
-p
)
.
)
--language
-l
)
--filename
-n
)
translations
)
--base
EN
)
Base.lproj
folder on iOS format and values
folder on android format.
--merge
--client_id
BABELSHEET_CLIENT_ID
value. (see how to obtain)
--client_secret
BABELSHEET_CLIENT_SECRET
value. (see how to obtain)
--spreadsheet_id
BABELSHEET_SPREADSHEET_ID
value. (see how to obtain)
--spreadsheet_name
BABELSHEET_SPREADSHEET_NAME
value. (see how to obtain)
--spreadsheet_name
BABELSHEET_REDIRECT_URI
value. (see how to obtain)
--help
Examples
babelsheet generate -f json -n my-own-en-translations -l en_US -p ./my-folder
- generates english translations in my-own-en-translations.json
file inside ./my-folder
folder.
babelsheet generate --format ios --path ./translations
- generates translations in iOS format in ./translations
folder.
Producer
Producer is used to fetch translations file, convert it and then store it in a database. The process is wrapped in a scheduler which repeats the whole operation continuously every 5 minutes by default. Please note that if there are no proper environment variables such as BABELSHEET_CLIENT_ID
, BABELSHEET_CLIENT_SECRET
and BABELSHEET_REFRESH_TOKEN
then producer wont be able to work properly. In such case it runs a command responsible for obtaining those keys.
You can run Producer in docker container - see Docker.
If you want to run producer locally, first remember about setting environment variables and running redis, next type:
-
npm run dev-install
-
npm run dev-start-producer
Producer should be working now.
You can change BABELSHEET_REFRESH_TOKEN
read and write providers, check it here.
You can also change translations storage from redis to file, check it here.
API
API is a web server built on top of express.js
which serves translations. There is one endpoint available to obtain translations, which is /translations
.
Translations can be filtered by using:
-
filters[]
- e.g. calling/translations?filters[]=en_US.CORE
will result in getting translations foren_US
locale and sectionCORE
. Other possibility is to use tag as a filter, e.g./translations?filters[]=en_US.tag1
. -
format
- translations can be served in json/android/ios/yml/xlf formats, just add adtitional parameter e.g./translations?filters[]=en_US.CORE&format=android
.
You can run API in docker container - see Docker.
If you want to run API locally, first remember about setting environment variables and running redis, next type:
-
npm run dev-install
-
npm run dev-start-api
API should be working now.
Usage
curl -X GET -g 'http://localhost:3000/translations'
curl -X GET -g 'http://localhost:3000/translations?filters[]=en_US.CORE'
curl -X GET -g 'http://localhost:3000/translations?filters[]=en_US.CORE.LABELS&format=android'