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

20scoops-localizer

v2.0.1

Published

Localizer is a script for retrieve locales data on google sheet and save to file for using in application.

Downloads

95

Readme

Localizer

Localizer is a script for retrieve locales data on google sheet and save to file for using in application.

How it looks like?

Usage

yarn add 20scoops-localizer
yarn localizer

Step 1

Create file called localizer.js. The only minimum config required is url which is google sheet url you want to retrieve locales data from

module.exports = {
  url:
    'https://docs.google.com/spreadsheets/d/1RzakawKOAo9JLz-MTkM9Iz5dqYmC6XvqcVmegUCos48/edit#gid=0',
}

and run script

yarn localizer

Step 2

Prompt will asked your secret key (What is secret key and how to retrieve it?).

It only ask for the first time when you install this package.

Step 3

Prompt will asked to visit the url and provide token (What is token and how to retrieve it?). This is for retrieve private google sheet.

It only ask for the first time when you install this package.

Step 4

That's it. If you provide correctly, it will show where files are saved.

Don't worry if you provide incorrectly, just run again and you can provide correct token / secret.

How to retrieve secret key and token

Secret key

It's secret key of OAuth google. You can get it from slack channel #general-dev. I'll pin on there under "20scoops-localizer" section or you can ask in the channel.

Token

Token is authorization key so that script can retrieve data on private google sheet on behalf of you. You can get this token by following the url the script provide in Step 3 on Usage section or run script localizer --get-refresh-token

Continuous Integration (CI)

How to use on Continuous Integration (CI)

Set up LOCALIZER_CREDENTIAL_TOKEN and LOCALIZER_REFRESH_TOKEN on environtment

You can get refresh token from Option

Example for Github Actions

- name: Localizer
  env:
    LOCALIZER_CREDENTIAL_TOKEN: ${{ secrets.LOCALIZER_CREDENTIAL_TOKEN }}
    LOCALIZER_REFRESH_TOKEN: ${{ secrets.LOCALIZER_REFRESH_TOKEN }}
  run: yarn localizer

How localizer read/export locales from google sheet

Example google sheet

Can divide the headers by merge row of sheet.

google-sheet-example

Example output for esm format

//en.js

const en = {
  translation: {
    btnLogin: 'Login',
    username: 'Username',
    password: 'Password',
    welcome: 'Welcome',
    hello: 'Hello',
    morning: 'Morning',
  },
}
export default en
//de.js

const de = {
  translation: {
    btnLogin: 'Anmeldung',
    username: 'Nutzername',
    password: 'Passwort',
    welcome: 'herzlich willkommen',
    hello: 'Hallo',
    morning: 'Guten morgen',
  },
}
export default de

Example output for commonjs format

//en.js

module.exports = {
  btnLogin: 'Login',
  username: 'Username',
  password: 'Password',
  welcome: 'Welcome',
  hello: 'Hello',
  morning: 'Morning',
}
//de.js

module.exports = {
  btnLogin: 'Anmeldung',
  username: 'Nutzername',
  password: 'Passwort',
  welcome: 'herzlich willkommen',
  hello: 'Hallo',
  morning: 'Guten morgen',
}

localizer assume first row is for headline. it will start retrieve data after the first row.

In addition, the Localizer has the following rules

  • The first column is the key for developer.
  • The second to last column is the name of the language that is exported. There will be a key to each file.

Options

| Options | Parameters | Description | Default value | | -------------------------------- | ------------------------------------------- | ---------------------------------------------------------------------------------- | ---------------------------- | | --clientID=$clientID | Credential client_id in google credential. | If not organization 20Scoops-CNX. Can input new client_id from google credential. | client_id of 20Scoops CNX | | --projectID=$projectID | Credential project_id in google credential. | If not organization 20Scoops-CNX. Can input new project_id from google credential. | project_id of 20Scoops CNX | | --localizerFile=$localizerFile | Location file localizer | If file localizer isn't stay in root project can input location file | ./localizer.js | | --get-refresh-token | N/A | Get refresh token for run with CI. | N/A |

Config

You can config script by creating localizer.js on your root project.

Example

module.exports = {
  dest: './locales',
  filename: {
    en: 'en.js',
    de: 'de.js',
  },
  url:
    'https://docs.google.com/spreadsheets/d/1RzakawKOAo9JLz-MTkM9Iz5dqYmC6XvqcVmegUCos48/edit#gid=0',
  ignoreColumns: ['th', 'description'],
  sheetName: '',
  module: 'esm',
}

| Key | Value | Required | Default | | --------------- | ----------------------------------------------------------------------- | -------- | ---------------------------- | | url | Google Sheets URL. | Yes | N/A | | dest | Location of local file storage. | No | ./locales/ | | filename | Filename will corresponds to language. | No | {en: 'en.js',de: 'de.js',} | | ignoreColumns | Script will ignore columns is select | No | [] | | sheetName | Script will retrieve locales from specified sheet name via this config. | No | '' | | module | Type of output esm, commonjs, android-xml or ios-strings. | No | esm |

** If sheetName more than 1. You can set follow sheetName:['sheet1', 'sheet2']