json-from-gsheet

Extract i18n translations from Google Spreadsheet to json files

Usage no npm install needed!

<script type="module">
  import jsonFromGsheet from 'https://cdn.skypack.dev/json-from-gsheet';
</script>

README

Sheet template: https://docs.google.com/spreadsheets/d/1TA79qZ0TVai4XwFH4OUbmxIfxndnp9p09x7lh9MweqQ/edit?usp=sharing

Installation

yarn add json-from-gsheet   

or

npm i json-from-gsheet

Usage:

spreadsheetId - You can get it from the spreadsheet url which is placed after /spreadsheets/d/. Ex: spreadsheets/d/{YOUR_SPREADSHEET_ID}.
apiKey - get it from your Google Console. Learn more.
tabName - tab name in your spreadsheet, which is shown on the bottom of the page. Ex: Sheet1.
savePath - the path where you want to store your translation files.

const { sheetToJSON } = require('json-from-gsheet')


sheetToJSON({
    spreadsheetId: 'SPREADSHEET_ID',
    apiKey: 'API_KEY',
    tabName: 'TAB_NAME',
    savePath: 'PATH_TO_SAVE_FILES'
})

Example:

sheetToJSON({
    spreadsheetId: 'SPREADSHEET_ID',
    apiKey: 'API_KEY',
    tabName: 'TAB_NAME',
    savePath: './src/i18n/locales'
})

Output:

It outputs languages.json file in the root folder of the path you passed.
Screen Shot 2021-10-12 at 08 23 17

Then it outputs all [language].json files in the passed path.

Screen Shot 2021-10-12 at 08 22 46

Here is how [language].json looks like after it is parsed from the sheet Screen Shot 2021-10-12 at 08 27 13