Skip to content

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

--config-format

(alias: -cf)

(default: env)

Where to store config (refresh token) env/json.

--format

(alias: -f)

(default: json)

Format type (android/ios/json/yml/xlf).

--path

(alias: -p)

(default: .)

Path for saving files.

--language

(alias: -l)

Language code for generating translations only in given language.

--filename

(alias: -n)

(default: translations)

Filename of final translation file.

--base

(default: EN)

Base language for translations. Base.lproj folder on iOS format and values folder on android format.

--merge

Creates one file with all languages.

--client_id

Client id received from Google. Overwrite .env.babelsheet BABELSHEET_CLIENT_ID value. (see how to obtain)

--client_secret

Client secret received from Google. Overwrite .env.babelsheet BABELSHEET_CLIENT_SECRET value. (see how to obtain)

--spreadsheet_id

Spreadsheet ID from spreadsheet URL. Overwrite .env.babelsheet BABELSHEET_SPREADSHEET_ID value. (see how to obtain)

--spreadsheet_name

Sheet name. Overwrite .env.babelsheet BABELSHEET_SPREADSHEET_NAME value. (see how to obtain)

--spreadsheet_name

Url to which user should be redirected after receiving refresh token. Overwrite .env.babelsheet BABELSHEET_REDIRECT_URI value. (see how to obtain)

--help

Help menu.

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:

  1. npm run dev-install

  2. 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 for en_US locale and section CORE. 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:

  1. npm run dev-install

  2. 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'