/i18n-microservice-js

A microservice for serving up Google Spreadsheets as i18next translation data

Primary LanguageJavaScriptMIT LicenseMIT

i18n-microservice-js

This is an API for transforming Phrase projects and Google Spreadsheets into i18next translation data. The endpoints are:

/phrase/:projectId

Returns un-cached translations for the given Phrase project.

/phrase/:projectId@version

Returns permanently cached translations for the given Phrase project for each unique value of :version.

/phrase/:projectId/link

Redirects to the dashboard for the given Phrase project.

/google/:sheetId

URL parameters

  • :sheetId is the ID of the spreadsheet, which you can find in its URL between /d/ and /edit:

    https://docs.google.com/spreadsheets/d/:sheetID/edit
                                           ⬆-----⬆
                                           this part
    

Query string parameters

  • sheet filters the translations by one or more worksheet indices and/or titles. Multiple values are respected. Examples:

    • ?sheet=1 will match only the second worksheet (the first is index 0)
    • ?sheet=Generic+forms will match only the worksheet titled "Generic forms"
    • ?sheet=*forms will match all worksheets that end in "forms"
    • ?sheet=1&sheet=2 will get the 2nd and 3rd worksheets
    • ?sheet=!*wip* will match worksheets that do not contain "wip"

Worksheet formatting

Worksheets are expected to have a "key" column followed by one or more language code columns. The name of the key column isn't significant, but for consistency it should be "String" or "Key".

All of the rest of the columns should be named with IETF language tags, e.g. en for English, es for Spanish, zh for Chinese, or tl for Tagalog. For instance:

String en es
hello Hi Hola
goodbye Bye Adiós

The first ("key") column may be empty, in which case the English translation will be used as the key.

Development

  1. Copy .env.template to .env and fill in the required environment variables.

  2. Run npm run dev to start the development server, which restarts whenever you modify source files (or package.json) using nodemon.

  3. Open https://localhost:8001/google/:sheetId with a public Google spreadsheet's id in place of :sheetId, and watch what happens in the console.

Deployment

This service can be deployed pretty much anywhere, but we're deploying it on Heroku for now. You'll need to set following environment variables ("config vars" in Heroku):

  • GOOGLE_API_KEY (required) is your Google API key.