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

@datareporter.eu/locint

v1.1.2

Published

Localize library for DataReporter locserver

Downloads

11

Readme

Localization Server Build Library

For usage in build processes

General usage

Translation of files

const loc = require("src/locint");

// set api key for project
loc.configure({apiKey: "<api key for project>"})

// initialize and load i18n files from server
await loc.initializeWithLanguages({
  isos: ["de", "en"],
  languageFilepath: "./test/_temp",
  invalidFilepath: "./test/_temp/incomplete.json",
  forceLoadFromServer: false,
  format: "json",
  filter: {
    keyFilter : null,
    noSubNodes: false,
    contentType: null,
    editorType : null
  }
});


// now translate all the files you need

// Variant 1: translate content (in memory) ------------------
let translatedContent = loc.translateContent("This is a [[Test]]", "en", "first readme call");

// Variant 2: translate file  ------------------
loc.translateFile(
    "./test/resource/translate_01.html",
    "./test/_temp/translate_en.html",
    "en"
    );

// Variant 3: translate directory with one call (even recursively)--------------
let options = {
  sourceDirectory: "./test/resource",  // path of the files with translation tokens
  recursive: false, // true: recursive search subdirectories
  extensions: ["html", "js"], // allowed file extensions
  destinationDirectory: "./test/_temp", // destination directory where files will be saved
  languages: [ // list of languages to translate to
    {
      iso: "de", // language iso
      appendIsoToFile: false  // true: append iso to filename ( e.g. xxx_de.json)
    },
    {
      iso: "en",
      appendIsoToFile: true
    }
  ]
};
loc.translateDirectory(options);



// after translation save invalid localization status (missing keys, unused keys)
await loc.saveInvalidStatus();

// optional: create missing keys for DE language in locale server
await loc.uploadSavedInvalidStatus("de");

Export files (like markdown) into directory

const loc = require("src/locint");

loc.configure({apiKey: "<api key for project>"})

let result = loc.exportMarkdownFiles({
      destinationPath: "./test/_temp", // destination path where files will be exported to
      isos: ["de", "en"], // iso codes to export
      appendHeader: true, // append language - agnostic header
      appendIsoToFiles: true, // append iso code to filename
      parentNode: null, // parent node key to export from
      extension: ".md" // extension of the generated files
    },
    {
      keyFilter : null, // keyword filter
      noSubNodes: false, // dont add subnodes
      contentType: null, // content type filter (file, !file, gui, ...)
      editorType : null // editor type filter (markdown, line, !text)
    }
);

/*
  result is a list of all exported files like:
    [
      "./test/_temp/gruppentest_01_de.md",
      "./test/_temp/gruppentest_01_en.md"
    ]
 */

Sync a folder to S3

Syncs a folder to S3. Only uploads changed files.

const loc = require("src/locint");

let c = loc.connectToS3("<user key>","<secret>", "test.datareporter.eu");
// c.deltaSync = false; to force upload all files 

let entries = await loc.syncFolderToS3(c, "/Users/mike/testfolder", "s3test");

Formats / Syntax

Translation syntax in templates

Used for downloading localization keys and replacing i18n syntax:

...
[[Abbrechen]] <!-- Token to replace - key is equal to "abbrechen" -->
...
[[!key:Das ist ein Key]] <!-- for longer texts: key is equal to "key" -->
...

Translation key file format

Localization file is a JSON file like:

{
  "list": [
    {
      "key": "Test",
      "description": "",
      "translation": "Übersetzung",
      "contentType": "auto",
      "editorType": "markdown",
      "contentHeader": null
    },
    ...
  ],
  "keys": {
    "key" : {...},
    ...
  }
}

Manual creation and upload of missing/unused keys

let invalids = loc.addInvalidKey();
loc.addInvalidKey(invalids, true, "de", "test-01", "Content-01"); // add missing key
loc.addInvalidKey(invalids, false, "de", "test-02", "Content-02"); // add unused key
// ...

loc.uploadInvalidStatusJson("de", invalids); // upload to server

REST request to translation server

Request to the https://locale.datareporter.eu server is like:

POST /rest/dev/locale-export/format-json HTTP/1.1
apiKey: <api key for project>
Content-Type: application/json; charset=utf-8
Host: locale.datareporter.eu
Connection: close
User-Agent: RapidAPI/4.0.0 (Macintosh; OS X/13.1.0) GCDHTTPRequest
Content-Length: 36

{"languageIso":"de","parentNode":"", mode: "keys,list"}