npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@moonshot-team/google-sheets-i18n

v0.1.1

Published

i18n using google sheets

Downloads

14

Readme

Introduction

The way for translations files to be generated using Google Spreadsheets. This tools fetches the data from the Google Spreadsheets and creates the JSON files suitable for immediate usage with the tools like i18next or later transformed to any format of the user's choice.

The project is a fork of the original google-sheet-i18n by @tanatornn96 with the following differences:

  • to handle the Google's deprecation of its G-suite API v3 the dependency google-spreadsheet is upgraded to v3,
  • Breaking: to simplify the code custom formatters are removed, the only output format is JSON which can later be transformed by any tool of the user's choice,
  • the code was modernized and simplified,
  • Babel transpilation is removed, the code works with Node.js >= 10 which supports fair amount of ES6 features,
  • Breaking: categories are now case-sensitive, as well as the language column names must exactly match the configuration.

Setup

Google Spreadsheets Configuration

Each sheet in the spreadsheet is transformed to a folder on the disc.

The first row of the sheet defines the (optional) categories, i18n keys, and the set of locales.

Each subsequent row is a single i18n record:

| Category | SubCategory | ... | Message | en_CA | en_FR | ... | | :--------: | :---------: | :-: | :-----: | :-------: | :--------: | :-: | | onboarding | landing | ... | intro | Hello! | Bonjour! | ... | | onboarding | landing | ... | exit | Good bye! | Au revior! | ... |

CLI Configuration

Configuration requires a credentials JSON file that can be obtained through Google's developer console with the following instructions (partially borrowed from node-google-spreadsheet):

  1. Go to the Google Developers Console
  2. Select your project or create a new one (and then select it)
  3. Enable the Drive API for your project
  • In the sidebar on the left, expand APIs & auth > APIs
  • Search for "drive"
  • Click on "Drive API"
  • click the blue "Enable API" button
  1. Create a service account for your project
  • In the sidebar on the left, expand APIs & auth > Credentials
  • Click blue "Add credentials" button
  • Select the "Service account" option
  • Select the "JSON" key type option
  • Click blue "Create" button
  • your JSON key file is generated and downloaded to your machine (it is the only copy!)
  • note your service account's email address (also available in the JSON key file)
  1. Share the doc (or docs) with your service account using the email noted above

Running the Translations

  1. npm install -D @moonshot-team/google-sheets-i18n
  2. Create a i18n.config.js file in the folder you wish to run the translations on.
  3. npx google-sheets-i18n fetch

i18n Configuration

var path = require("path");

module.exports = {
  categories: ["category", "subcategory", "subcategory2"],
  credentialsPath: path.join(process.cwd(), "credentials.json"),
  languages: ["en_CA", "fr_CA", "es_ES"],
  sheetId: "YOUR_SHEET_ID"
};
  • categories - (required) The columns that defined the key names, for example, with the table above the first row will correspond to the onboarding.landing.intro key in the i18n file,
  • delimiter - (optional, default - '.') The delimiter used to join different categories to build the i18n key,
  • credentialsPath - (required) Absolute path to your crendentials JSON file,
  • languages: (required) The column in the sheet defining the i18n locales, each language corresponds to a single output file,
  • sheetId - (required) The ID of the Google Spreadsheet (can be found as part of its URL),
  • output - (required) An absolute path to the folder where locale files are saved.