GithubHelp home page GithubHelp logo

i18n2-scanner's Introduction

i18n2-scanner

Scanner utility for i18n2

Installation

$ npm install i18n2-scanner

Description

Scanner is used to parse source (using esniff) code and search for occurrences of _ function. It produces json parsable structure with all the messages found in the code.

Structure

The i18n2-scanner constists of index.js (main module) and merge-maps (module for merging scanner results). The scanner itself (index.js) takes source parameter and an optional options object. The source parameter is assumed to be content of a JavaScript file. The options parameter may contain i18Prefix field in which a string can be given. The i18Prefix can be used to specify the name of the i18n object (default i18n).

Usage

index.js

Scanner is meant to parse content of JavaScript files and extract the language keys with some meta information about them (for example key's location in files). The scanner assumes that the i18n function is named _. The standard usage would be to feed file contents of a a file that may use _ function to scanner (index.js). Scanner will return an object of the form:

{
 context: "context name",
 messages: {
  "n\u0000Singular\u0000Plural":[{"point":455,"line":12,"column":70}],
  "Regular Key":[{"point":825,"line":22,"column":70}],
  "Some other key":[{"point":1027,"line":29,"column":26}]
  }
}

merge-maps.js

If we have many contexts and many files in which _ function appears, we can create a more useful map by gathering all the particular scanner results in a map of the form:

{
 "path/to/file-with-tranlation": scannerResultObject,
 "path/to/file-with-tranlation-other": scannerResultObject2
}

We can use such map as an input for merge-maps. The merge-maps will produce the output of the form:

{
 "Some language key":
  {"Some Context":
    [
     {"fileName": "/path/to/file.js","point":991,"line":33,"column":23},
     {"fileName": "/path/to/file.js","point":1200,"line":50,"column":20}
    ]
 },
 "Other key":
  {"other context":
    [
     {"fileName":"path/to/otherfile.js","point":375,"line":11,"column":28}
    ]
  }
}

So the merge-maps module groups scanner results by language keys, then by context and gives information on where a specific _ function (or i18n method in case of contexts) invocation has ocurred.

Tests Build Status

$ npm test

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.