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

i18n-gs

v1.1.0

Published

Support Google Sheets push and fetch into i18n json file.

Downloads

55

Readme

i18n-gs

This tool is to support Google Sheets upload and download i18n json file.

Installation

As a dependency in a package

npm install i18n-gs --save-dev
# or
yarn add i18n-gs --dev

Globally with npm

npm install i18n-gs -g

Usage

On-demand:

You can use npx to run it without installation

npx i18n-gs

Installed as a dependency:

npx i18n-gs
# or
yarn i18n-gs

Installed globally:

i18n-gs

Commands

Init

Initialize the project with config file

i18n-gs init

Upload

Upload the files to google sheet (only support flat key style)

i18n-gs upload [namespaces...]

Options:
  -l, --locales <locales...>  locales to be included
  • Example:
i18n-gs upload
i18n-gs upload common
i18n-gs upload common --locales en

Download

Download the files from google sheet

i18n-gs download [namespaces...]

Options:
  -l, --locales <locales...>  locales to be included
  • Example:
i18n-gs download
i18n-gs download common
i18n-gs download common --locales en

Authentication

Service Account:

Setup a service account and share sheet's editor permission to the service account

  1. Go to Google Cloud Console
  2. Select or create a project
  3. Search for "Google Sheets API" and enable it
  4. Search for "Service Accounts"
  5. Click "+ Create Service Account" and follow the steps to create service account
  6. Save the generated JSON credential file to local (or your project root folder)
  7. Update the configuration file
  8. Go to the Google Spreadsheet you plan to use
  9. Share Editor permission to the service account in your Google Spreadsheet

Spreadsheet Format

The first row must contain the following header keys

  1. Column A must be named 'key'
  2. The following columns must be named by language code

You can check the template here

Configuration

Create a file i18n-gs.config.js in the project root

Example

module.exports = {
  spreadsheet: {
    sheetId: "<your sheet id>",
    credential: {
      type: "serviceAccount",
      path: "<your credential file path>",
    },
  },
  i18n: {
    path: "<your locale directory path>",
    keyStyle: "nested",
    locales: {
      includes: ["en"],
      excludes: [],
    },
    namespaces: {
      includes: ["common"],
      excludes: [],
    },
  },
  logging: {
    level: "info",
  },
};

i18n-gs.config.js fields

spreadsheet.sheetId

Specifies the id of your google sheet

  • Type: string
  • Example:
module.exports = {
  spreadsheet: {
    sheetId: "<your sheet id>",
  },
};

spreadsheet.credential.type

Specifies the method to connect google sheet (Only support service account for now)

  • Type: 'serviceAccount'
  • Example:
module.exports = {
  spreadsheet: {
    credential: {
      type: "serviceAccount",
    },
  },
};

spreadsheet.credential.path

Specifies the path to your credential file (Applicable to service account)

  • Type: string
  • Example:
module.exports = {
  spreadsheet: {
    credential: {
      path: "<your credential file path>",
    },
  },
};

i18n.path

Specifies the path to store your locales files

  • Type: string
  • Example:
module.exports = {
  i18n: {
    path: "<your locale directory path>",
  },
};

i18n.keyStyle

Style of the i18n key on local file

  • Type: 'nested' | 'flat'
  • Example:
module.exports = {
  i18n: {
    keyStyle: "nested",
  },
};

The key style is as follows:

{
  // nested:
  blog: {
    section: {
      title: "My first blog";
    }
  },
  // flat:
  blog.section.title: "My first blog"
}

i18n.locales.includes

Specifies the locales to include when upload / download

Note: If the provided array is empty, nothing will be included when performing action

  • Type: string[]
  • Example:
module.exports = {
  i18n: {
    locales: {
      includes: ["en", "ja"],
    },
  },
};

i18n.locales.excludes

Specifies the locales to exclude when upload / download

  • Type: string[]
  • Example:
module.exports = {
  i18n: {
    locales: {
      excludes: ["de", "fr"],
    },
  },
};

i18n.namespaces.includes

Specifies the namespaces to include when upload / download

Note: If the provided array is empty, nothing will be included when performing action

  • Type: string[]
  • Example:
module.exports = {
  i18n: {
    namespaces: {
      includes: ["common", "glossary"],
    },
  },
};

i18n.namespaces.excludes

Specifies the namespaces to exclude when upload / download

  • Type: string[]
  • Example:
module.exports = {
  i18n: {
    namespaces: {
      excludes: ["local", "debug"],
    },
  },
};

logging.level

Specifies the log level

  • Type: 'silent' | 'error' | 'warn' | 'info' | 'debug'
  • Example:
module.exports = {
  logging: {
    level: "info",
  },
};