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

grunt-translation-spreadsheet-sync

v1.1.0

Published

A grunt plugin to manage translation import/export to and from a google spreadsheet

Downloads

45

Readme

grunt-translation-spreadsheet-sync

A grunt plugin to manage translation import/export to and from a google spreadsheet

Getting Started

This plugin requires Grunt ~0.4.5

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-translation-spreadsheet-sync --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-translation-spreadsheet-sync');

The "translation_spreadsheet_sync" task

Overview

In your project's Gruntfile, add a section named translation_spreadsheet_sync to the data object passed into grunt.initConfig().

An example config could look like:

grunt.initConfig({
  translation_spreadsheet_sync: {
    options: {
        spreadsheetId: '-your google spreadsheet id-',
        credentials: require('path/to/your/secret/credential/service')
    },
    import: {
        options: {
            mode: 'import'
        },
        files: {
            src: 'src/languages/'
        },
    },
    upload: {
        options: {
            mode: 'upload'
        },
        files: {
            src: 'src/languages/*.json'
        }
    }
  }
});

Options

options.credentials

Type: Object
Default value: Credentials for [email protected]

In order to authenticate to a google spreadsheet, you need a google drive api client.

If you trust me enough, you could also grant read/write access to your translation spreadsheet the the default service email [email protected]. Please note, that this will make you dependent on any changes that google or myself do to this service, it is recommended to use your own credentials.

The object needs to have this structure:

{
  "comment": "This is added by me, put here some info for yourself, to remind you what this is actually about, if you like ;)",

  "type": "service_account",
  "project_id": "...",
  "private_key_id": "...",
  "private_key": "never to be shared",
  "client_email": "e.g.: [email protected]",
  "client_id": "...",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://accounts.google.com/o/oauth2/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "..."
}

options.defaultLocaleName

Type: String
Default value: 'default'

If no locale is provided or could be parsed, the defaultLocaleName is used instead.

options.defaultFallback

Type: Boolean
Default value: false

Fills empty columns automatically with the value from the defaultLocale - usefull if always complete translations have to be provided per file.

options.fileBaseName

Type: String
Default value: (empty string)

If set, the translation files will be changed to <fileNaseName>-<lang code>_<country code>, for example myplugin-de_AT.

options.gid

Type: String
Default value: "0"

The selected Worksheet to work with. the gid can be taken from the spreatsheet url: #gid=1470321642

options.mode

Type: Enum
Default value: null

Put import, if you want to sync from google spreadsheet to your project or put upload if it should go the other way around.

options.namespaces

Type: Boolean
Default value: false

If multiple base filenames are used in a project, this can be turned on, to still have the properties uploaded to one spreadsheet. It will expect the first collumn of the sheet to be filled with the namespace.

options.namespaceSeparator

Type: String
Default value: '-'

If namespaces or fileBaseName is used, this is the separating character. For example the first _ in messages_en_US.json.

options.translationFormat

Type: Enum Default value: locale_json
Possible Values:

  • locale_json (translations are stored in simple key/value json files)
  • json_structure (translations are broken down to a json tree spereated by the . character)
  • gettext (for the work with po and mo files)
  • properties (for java property files)
  • yml (for symfony yml translation files)

Please feel free to create a PR or open an issue, if you need an additional translation format.

options.spreadsheetId

Type: String
Default value: null

This is absolutely required to make it work

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.