This package has been deprecated

Author message:

Plese use the namespaced version under @zakkudo

translation-static-analyzer

0.0.1 • Public • Published

translation-static-analyzer

A library for scanning javscript files to build translation mappings in json automatically.

There are three different concepts for this library.

  1. The source files which the translations are analyzed and extracted from
src/**/*.js
  1. The intermediary translations that are meant to be edited by humanes in json5 format
locales/ja.json
  1. The final translations which strip out untranslated strings and json5 comments and are optionally split between targets.
src/.locales/ja.json

Usage for just translating everything:

const TranslationStaticAnalyzer = require('translation-static-analyzer');
const analyzer = new TransalationStaticAnalyzer({
    //Analyzes all javscript files in the src directory
    files: 'src/**/*.js',
    //Enables verbose output
    debug: true,
    //generate a locales/fr.json as well as a locales/en.json
    locales: ['fr', 'en'],
    //Each page in the folder will get it's own subset of translations
    target: 'src'
});
analyzer.update();

Usage for splitting transaltions between dynamically imported pages of a web app:

const TranslationStaticAnalyzer = require('translation-static-analyzer');
const analyzer = new TransalationStaticAnalyzer({
    //Analyzes all javscript files in the src directory
    files: 'src/**/*.js',
    //Enables verbose output
    debug: true,
    //generate a locales/fr.json as well as a locales/en.json
    locales: ['fr', 'en'],
    //Each page in the folder will get it's own subset of translations
    target: 'src/pages/*'
});
analyzer.update();

You can incrementally update the written translation (such as for updates triggered by watch) by passing the files that changed: analyzer.update(['/src/index.js']);

Example of translation templates:

{
    // NEW
    // src/Application/pages/AboutPage/index.js:14
    "About": "",
    // UNUSED
    "This isn't used anymore": "So the text here doesn't really do anything",
    // src/Application/pages/AboutPage/index.js:38
    "Welcome to the about page!": "ようこそ"
}

Use the translations with a library like y18n by doing:

const y18n = require('y18n')({
    updateFiles: false
});
const japanese = require('./locales/ja.json');
 
y18n.cache['ja'] = japanese;
y18n.setLocale('ja');
 
//This library will add any translations to the json using __() or __n() as the translation function.
const translated = y18n.__('to be translated');

Readme

Keywords

Package Sidebar

Install

npm i translation-static-analyzer

Weekly Downloads

1

Version

0.0.1

License

BSD-3-Clause

Unpacked Size

47.9 kB

Total Files

32

Last publish

Collaborators

  • zakkudo