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

lokse

v3.0.0

Published

Tool to efficient usage of translations stored in google spreadsheet

Downloads

5,441

Readme

lokse

A tool for efficient usage of translations stored in google spreadsheet

oclif Version Downloads/week License

🚀 Usage

$ npm install -g lokse
$ lokse COMMAND
running command...
$ lokse (-v|--version|version)
lokse/3.0.0 darwin-arm64 node-v20.11.1
$ lokse --help [COMMAND]
USAGE
  $ lokse COMMAND
...

🔑 Authentication

The last version of Google Spreadsheets API requires us to be authenticated to allow fetching spreadsheet data. Read more about authentication here

🔧 Configuration

CLI uses Cosmiconfig which means you can hold the configuration in any format it supports.

So just create lokse.config.js, .lokserc, .lokserc.yml, .lokserc.json or add lokse property into the package.json and there you can setup on of the options:

sheetId

Spreadsheet id. When you open your spreadsheet it's this string

dir

Output directory where generated translation files will be written to.

languages

List of languages you want to generate translations for. Also names of columns in spreadsheet.

column

Name of spreadsheet columm containing translation ids.

format

Format of output translation file.

sheets

Target spreadsheet can contain more than one sheet and default behaviour is to use all of them, but sometimes you need only some of them. This option determines sheets to fetch translations from. You can define sheets you want to use or those you don't want to or combine these definition.

You can choose from various formats to define sheets to use

  1. Special value * means to include all sheets and is the default behaviour when you omit the sheets option.

    {
      "sheets": "*",
    }
  2. Titles of sheets to use. Can be string or array of strings

      {
        "sheets": "Web translations",
      }
      // or
      {
        "sheets": ["App translations", "Legal docs"]
      }
  3. Definition of sheets to include or exclude from the list of all sheets. Can be one of formats mentioned above

      {
        "sheets": {
          "include": ["Web translations", "Legal docs"],
          "exclude": "CMS translations"
        }
      }
      // or
      {
        "sheets": {
          "exclude": ["CMS translations"]
        }
      }
      // or 
      {
        "sheets": {
          "include": ["Web translations", "Legal docs"],
        }
      }

splitTranslations

Enables splitting translations into multiple files which is useful for lazy loading of some big parts of translations (eg. translation of the whole legal document).

You have two ways of how to split your translations:

  • Split by sheets - splitTranslations: true - each sheet means one translations file and name of file is determined by sheet title. Given 3 sheets in yout spreadsheet named "App translations", "Legal docs", "Landing Page" the result will be 3 files named app-translations.cs.json, legal-docs.cs.json, landing-page.cs.json (of course the language and format depends on your settings).

  • Split by domains - splitTranslations: string[] - this configuration expects an array of domain names. Domain is a first part of your translation id, given translation id news.mostRead.error.text the domain is news. The domain name determines also the filename, news.cs.json in our example.
    Translations that starts with domain news. will be written into the news.cs.json, other translations that does not belong to any other group will be saved into general translations in file cs.json.

The splitTranslations option can be provided only through configuration not inline CLI parameter.

Plugins

List of plugins to use. Plugin can be either name of plugin, or object containing name and options. You must install first.

$ yarn add -D @lokse/plugin-prettify @lokse/plugin-transform-values
plugins: [
  "@lokse/plugin-prettify",
  {
    "name": "@lokse/plugin-transform-values",
    "options": {
      "uppercase": "true"
    }
  }
],

Example of .lokserc

{
  "sheetId": "1HKjvejcuHIY73WvEkipD7_dmF9dFeNLji3nS2RXcIzk",
  "dir": "locales",
  "languages": ["cs", "en", "fr"],
  "column": "key_web",
  "format": "json",
  "sheets": ["App translations", "Legal docs"],
  "splitTranslations": ["news", "documents"],
  "plugins": []
}

🕹 Commands

lokse help [COMMAND]

display help for lokse

USAGE
  $ lokse help [COMMAND]

ARGUMENTS
  COMMAND  command to show help for

OPTIONS
  --all  see all commands in CLI

See code: @oclif/plugin-help

lokse init

create a new config file

USAGE
  $ lokse init

OPTIONS
  -h, --help  show CLI help

EXAMPLE
  $ lokse init

See code: lib/commands/init.js

lokse open

open localization spreadsheet in default browser

USAGE
  $ lokse open

OPTIONS
  -h, --help   show CLI help
  -i, --id=id  spreadsheet id

EXAMPLE
  $ lokse open -i 1HKjvejcuHIY73WvEkipD7_dmF9dFeNLji3nS2RXcIzk

See code: lib/commands/open.js

lokse update

update translations from localization spreadsheet

USAGE
  $ lokse update

OPTIONS
  -c, --col=col                    column containing translations keys. For example key_web.
  -d, --dir=dir                    output folder
  -f, --format=(json|android|ios)  output format. Default is json.
  -h, --help                       show CLI help
  -i, --id=id                      spreadsheet id

  -l, --languages=languages        translation columns languages. Multiple values are comma separated. For example
                                   cs,en,fr

  -s, --sheets=sheets              sheets to get translations from. Name or list of names, comma separated. For example
                                   Translations1,Translations2

EXAMPLES
  $ lokse update
  $ lokse update -i 1HKjvejcuHIY73WvEkipD7_dmF9dFeNLji3nS2RXcIzk -d locales -l cz,en,fr -t key_web

See code: lib/commands/update.js