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

google-sheet-localize-test1

v1.0.20

Published

Localization tool for nodejs apps. Uses google-sheet as a resource storage.

Downloads

4

Readme

google-sheet-localize-test1

Localization tool for nodejs apps. Uses google-sheet as a resource storage.

Installation

This is a Node.js module available through the npm registry. It can be installed using the npm

npm install google-sheet-localize-test1 --save

Usage

Important: Create your sheet for localization with following structure:

| Section | Field | EN | SE | | ------------- | ------------- | --------- | --------- | | XXX | YYY | ZZZ | ZZZ | | Header | Title | Hello | Hallå | | Content | Description | World | Värld |

Important: To enable access to your sheet by api, please turn on access by link:

  1. Click 'Share' button in the right top side.
  2. Then choose 'Anyone with the link' and hit 'Done'. google sheet enabling access

Example of google sheet:

You can copy data for testing from example table provided by link. google sheet document example

Don't forget change tab name to "tab_name_of_sheet_with_translations" for applying our example to work.

Example of configuring for expressjs(Be sure you have installed nodejs):

  1. Create new folder localize-test and init project. Provide info of your project in dialogue.

    npm init

    npm init example

  2. Install "express" web app framework and "express-handlebars" view engine npm modules for our example.

    npm install express
    npm install express-handlebars

    And of course:

    npm install google-sheet-localize-test1 --save
  3. Create "app.js" file in root folder of project.

    app.js

    var express = require('express'),
        exphbs = require('express-handlebars'),
        path = require('path'),
        loc = require('google-sheet-localize-test1');
    var app = express();
    // loc.synchronize() performs downloading translations from the google sheet
    // it must be called before we try to localize something!
    loc.synchronize();
    app.engine('.html', exphbs({
        extname: '.html'
    }));
    app.set('view engine', '.html');
       
    //Serving static files in Express 
    //details info: https://expressjs.com/en/starter/static-files.html
    app.set('views', path.join(__dirname,'/'));
    
    app.get('/sync', (req, res) => {
        loc.synchronize();
        res.sendStatus(200);
    });
    app.get('/:lang?', (req, res) => {
    res.render('start_page', (err, html) => {
        // loc.localize(...) performs localization of document html content
        // and returns it as a promise
        loc.localize(html, req.params.lang, 'start_page')
        .then(localizedHtml => res.send(localizedHtml));
            })
        });
    app.listen(3000);
  4. Create "start_page.html" in root folder of project.

    start_page.html

    <html>
    <h1>((XXX | YYY]))</h1>
    <h2>((Header | Title))</h2>
    <p>((Content | Description))</p>
    </html>

    Where:

    • XXX: name of section in google sheet.
    • YYY: name of field in google sheet.
  5. Finally create your "localize-config.json" in root folder of project.

    localize-config.json

    {
        "pages": [
        {
            "sheetId": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
            "tabName": "tab_name_of_sheet_with_translations",
            "pageName": "start_page"
        }
        ],
        "apiKey": "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY",
        "apiVersion": "v4",
        "defaultLanguage": "EN"
    }   
  6. Read configuring section to get 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
    and 'YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY' to spicify in our localize-config.json.

  7. Write in terminal(in project folder):

    node app.js
  8. Open in browser http://localhost:3000/se and see our translated page with content from created google sheet, yey!

  9. Open in browser http://localhost:3000/ and see our translated page to default "EN"!

  10. Open in browser http://localhost:3000/sync to synchronize your changes from Google Sheet any time.

Configuring

For applying tool to work create json config file, with following content:

localize-config.json

{
    "pages": [
    {
        "sheetId": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
        "tabName": "tab_name_of_sheet_with_translations",
        "pageName": "page_name_in_app"
    },
    {
        "sheetId": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
        "tabName": "another_tab_name_of_sheet_with_translations",
        "pageName": "another_page_name_in_app"
    }
    ],
    "apiKey": "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY",
    "apiVersion": "v4",
    "defaultLanguage": "EN"
}   

Where:

  • XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX: id of google sheet. You can take it from google sheet basic url:
    https://docs.google.com/spreadsheets/d/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/edit#gid=000000000
  • YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY: key for accessing your google api. You can create it very simple:

    1. Log in your google account.

    2. Go to https://console.developers.google.com/

    3. Create new project or select existing: Creating project: a. Highlight 'IAM & admin' and select 'Manage resources' in left menu. b. Click 'Create project button' fill 'Project name' and hit 'Create'.

      creating test project

    4. Enable "Google Sheets Api" by following link and clicking "Enable".

      enabling google sheets api

    5. Select 'Credentials' in left menu. Be sure your new project selected:

      test project selected

    6. Click 'Create credentials' and select 'API Key'.

  • tabName (optional) is tab name from your document.

  • apiVersion is google api version set it to "v4".

  • defaultLanguage (optional) is language wich must be rendered when requested non-existing or empty language.

Dependencies

  • fs-extra: fs-extra contains methods that aren't included in the vanilla Node.js fs package. Such as mkdir -p, cp -r, and rm -rf.
  • request: Simplified HTTP request client.
  • request-promise: The simplified HTTP request client 'request' with Promise support. Powered by Bluebird.

License

The MIT license

Copyright © 2018 Vladyslav Behashevskyi ([email protected])