
Product
Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.
babelsheet-stream
Advanced tools
Rx.js observable that parses google spreadsheets that have Babelsheet compliant structure
Rx.js observable that parses google spreadsheets that have Babelsheet-compliant structure
There is cool Babelsheet project which enables straightforward way for syncing the translation files in your project by fetching them from specifically structured Google Spreadsheet file. The problem with Babelsheet however is that although it provides a nice features, it might be the case that you have a specific structure of translations that it does not handle. Possible approaches to such problem would be:
This project makes it easier to go with the 3rd way by using Rx.js abstractions.
Suppose you want to create flat JSON files per language:
import { fromBabelsheet, writeJSONFile } from 'babelsheet-stream';
import { mergeMap, groupBy } from 'rxjs/operators'
// Import your credentials.json file that you can generate in Google API console
// panel when creating Service Account.
import credentials from './.credentials.json';
fromBabelsheet({
spreadsheetId: "__YOUR_SPREADSHEET_ID__",
credentials,
}).pipe(
groupBy(
({ language }) => language,
({ path, value }) => ({ path: path.join('.'), value })
),
mergeMap(languageEntries$ => languageEntries$.pipe(
writeJSONFile(`${__dirname}/i18n/flat/${languageEntries$.key}.json`)
)),
).subscribe(
({ filePath, entryCount }) => {
console.log(`Wrote file: "${filePath}" with ${entryCount} entries`);
}
);
The above script will group the language translations by language and write JSON files per each of them. As you can see beside reading and parsing the spreadsheets, babelsheet-stream also provides some helper for writing the JSON files.
Suppose you want to group translations per language, but you also want to split the translations by the root section of the translation key path. For instance if you have translation keys like this:
common.edit
login.form.email
login.error.wrongCredentials
you would like it to end up in files like:
i18n/en/common.json
i18n/pl/common.json
i18n/en/login.json
i18n/pl/login.json
Then, the following code is an exemplary implementation of tool that can do this:
import { fromBabelsheet, writeJSONFile } from 'babelsheet-stream';
import { groupBy, mergeMap } from 'rxjs/operators'
// Import your credentials.json file that you can generate in Google API console
// panel when creating Service Account.
import credentials from './.credentials.json';
fromBabelsheet({
spreadsheetId: "__YOUR_SPREADSHEET_ID__",
credentials,
}).pipe(
groupBy(
({ language, path }) => `${language}/${path[0]}`,
({ path, value }) => ({ path: path.slice(1), value })
),
mergeMap(languageEntries$ => languageEntries$.pipe(
writeJSONFile(`${__dirname}/i18n/nested/${languageEntries$.key}.json`)
)),
).subscribe(
({ filePath, entryCount }) => {
console.log(`Wrote file: "${filePath}" with ${entryCount} entries`);
}
);
import { fromBabelsheet, writeCSVFile } from 'babelsheet-stream';
import { mergeMap, groupBy } from 'rxjs/operators'
// Import your credentials.json file that you can generate in Google API console
// panel when creating Service Account.
import credentials from './.credentials.json';
fromBabelsheet({
spreadsheetId: "10LiCKh8KRmFUQUHqMgcx70THb1xprYp5HdyQR_6zcBY",
credentials,
}).pipe(
groupBy(
({ language }) => language,
({ path, value }) => ({ translationKey: path.join('.'), value })
),
mergeMap(languageEntries$ => languageEntries$.pipe(
writeCSVFile({
filePath: `${__dirname}/i18n/csv/${languageEntries$.key}.csv`,
columnsOrder: ["translationKey", "value"],
})
)),
).subscribe(
({ filePath, entryCount }) => {
console.log(`Wrote file: "${filePath}" with ${entryCount} entries`);
}
);
FAQs
Rx.js observable that parses google spreadsheets that have Babelsheet compliant structure
We found that babelsheet-stream demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.