GithubHelp home page GithubHelp logo

i18next-static-analysis's Introduction

i18next-static-analysis

Looking for Contributors

This project is currently unmaintained and very out of date

I've moved on to different approach for static analysis using Typescript types. As such I do not have time to support/maintain/test this project. I hope to open-source my other solution in the future.

Description

Attempts to analyse statically your code to find calls to i18next and validates them for all your supported languages. Provide the i18next instance and the path to your source file and wait for the report.

Uses babel for all parsing and traversing of your code so it supports everything it does.

Installation

npm install i18next-static-analysis or yarn add i18next-static-analysis

Usage

const path = require("path");
const i18n = require("i18next");
const analyser = require("i18next-static-analysis");

/**
 * @typedef {Object} options
 * @property {Boolean} debug - Optional | Default: false | Print debug logs
 * @property {String[]} excludes - Optional | Default: ["node_modules", "bower_components"] | Path to exclude
 * @property {String[]} extensions - Optional | Default: [".js", ".jsx"] | File extensions to be analyzed
 * @property {String | String[]} keywords - Optional | Default: ["__"] | Callee Keywords
 * @property {String | String[]} paths - Required | Paths to be analyzed
 */
const options = {
  paths: [path.join(__dirname, "src")]
};

/**
 * @callback callback
 * @return {String} error - string
 */
function callback(err) {
  if (err) {
    throw new Error(err);
  } else {
    console.log("Successful Analysis");
  }
}

i18n.init({
  lng: "en",
  supportedLngs: ["en"],
  ns: {
    namespaces: ["general", "ns2"],
    defaultNs: "general"
  },
  nsseparator: "::",
  resGetPath: path.join(__dirname, "locales", "__lng__", "__ns__.json5"),
  }, function() {
    analyser(i18n, options, callback);
  }
);

Demo

An example of the analysis script is provided in the index.js file. Run the analysis script on the translation files in the provided /tests directory. npm run test or yarn test

Known Issues

  • Supports only literal values in i18next translate call.
  • No support for options in translation
  • babel options not passed to the parser

i18next-static-analysis's People

Contributors

cellule avatar travishoki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

i18next-static-analysis's Issues

Not compatible with newer versions of i18next

I have tested it against i18next 21.10.0 and got several issues.
For example i18n.sync.postMissing is no longer available, and many other options and API has changed.
Would be great to get this working with recent versions of i18next.

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.