Skip to content
Snippets Groups Projects
Commit bbdbec28 authored by esikkala's avatar esikkala
Browse files

Translations generator: support multiple ranges

parent 5de7196e
No related branches found
No related tags found
No related merge requests found
......@@ -12,8 +12,7 @@ import {
import { combineEpics, ofType } from 'redux-observable'
import intl from 'react-intl-universal'
import localeEN from '../translations/sampo/localeEN.json'
import localeFI from '../translations/sampo/localeFI'
import localeSV from '../translations/sampo/localeSV'
import localeFI from '../translations/sampo/localeFI.json'
import { stateToUrl, pickSelectedDatasets } from '../helpers/helpers'
import querystring from 'querystring'
import {
......@@ -64,8 +63,7 @@ const apiUrl = process.env.API_URL
export const availableLocales = {
en: localeEN,
fi: localeFI,
sv: localeSV
fi: localeFI
}
let backendErrorText = null
......
export default {
languageLabel: 'Suomi'
}
This diff is collapsed.
export default {
languageLabel: 'Svenska'
}
......@@ -19,8 +19,6 @@ const auth = new google.auth.GoogleAuth({
const sheets = google.sheets({ version: 'v4', auth })
const spreadsheetId = process.env.SHEETS_API_SHEET_ID
// const writeToGoogleSheet = async values => {
// try {
// const result = await sheets.spreadsheets.values.update({
......@@ -37,13 +35,13 @@ const spreadsheetId = process.env.SHEETS_API_SHEET_ID
// }
// }
const readFromGoogleSheet = async () => {
const readFromGoogleSheet = async ({ spreadsheetId, ranges }) => {
try {
const result = await sheets.spreadsheets.values.get({
const result = await sheets.spreadsheets.values.batchGet({
spreadsheetId,
range: 'A:B'
ranges
})
return result.data.values
return result.data.valueRanges
} catch (error) {
console.log(error)
}
......@@ -54,15 +52,17 @@ const writeToFile = async (path, data) => {
try {
await fs.writeFile(path, json)
console.log('Saved data to file.')
console.log(`Saved translations from Google Sheets into '${path}'`)
} catch (error) {
console.error(error)
}
}
const sheetValuesToFlatObject = values => {
return values.reduce((result, item, index) => {
result[item[0]] = item[1]
const sheetValueRangesToFlatObject = valueRanges => {
const keyArray = valueRanges[0].values
const valueArray = valueRanges[1].values
return keyArray.reduce((result, item, index) => {
result[item[0]] = valueArray[index] ? valueArray[index][0] : ''
return result
}, {})
}
......@@ -85,8 +85,14 @@ const sheetValuesToFlatObject = values => {
// writeToGoogleSheet(values)
if (readTranslationsFromGoogleSheets) {
readFromGoogleSheet().then(data => {
const flatObject = sheetValuesToFlatObject(data)
const spreadsheetId = process.env.SHEETS_API_SHEET_ID
readFromGoogleSheet({ spreadsheetId, ranges: ['Taulukko1!A:A', 'Taulukko1!B:B'] }).then(data => {
const flatObject = sheetValueRangesToFlatObject(data)
writeToFile('src/client/translations/sampo/localeEN.json', unflatten(flatObject))
})
readFromGoogleSheet({ spreadsheetId, ranges: ['Taulukko1!A:A', 'Taulukko1!C:C'] }).then(data => {
const flatObject = sheetValueRangesToFlatObject(data)
writeToFile('src/client/translations/sampo/localeFI.json', unflatten(flatObject))
})
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment