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

gulp-l10n-toolkit

v0.0.3

Published

Parse and collect localizable strings from html.

Downloads

5

Readme

gulp-l10n-toolkit

A plugin for localizing html.

Very heavily based on: https://github.com/bitjson/gulp-l10n/

Adds support for nested: true which generates a nested JSON locale similar to chrome locales.

Nested JSON

nested: false (Default)

{
  "8f7f4c1c": "About",
  "95a55af6": "Team page",
  "58270ff3": "Citizen Kane"
}

nested: true

{
  "about (8f7f4c1c)": {
    "message": "About",
    "_hash": "8f7f4c1c",
    "_tags": [
      "index",
      "about-us",
      "public.404",
      "public.error",
      "team"
    ]
  },
  "team-page (95a55af6)": {
    "message": "Team page",
    "_hash": "95a55af6",
    "_tags": [
      "index",
      "about-us",
      "public.404",
      "public.error",
      "team"
    ]
  },
  "citizen-kane (58270ff3)": {
    "message": "Citizen Kane",
    "_hash": "58270ff3",
    "_tags": [
      "index"
    ]
  }
}
  • Slugifies the key for better readibility.
  • Adds the sites where the string occurs to an _tags array.

extractLocale()

Parse and extract localizable strings from html. Passes on a single LOCALE.json, where LOCALE is the nativeLocale.

var gulp = require('gulp');
var l10n = require('gulp-l10n-toolkit');

gulp.task('extract-locale', function () {
  return gulp.src('src/**/*.html')
    .pipe(l10n.extractLocale())
    .pipe(gulp.dest('locales'));
});

options

// defaults included below

.pipe(l10n.extractLocale({
    // localize the contents of all of the following attributes
    attributes: ['alt', 'title'],

    // localize the contents of all elements with the following attributes
    directives: ['localize'],

    // localize the contents of all of the following elements
    elements: ['title', 'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'],

    // algorithm to hash each string
    hashAlgorithm: 'md5',

    // length at which to trim each hash
    hashLength: 8,

    // by default, the locale is written to the stream as `en.json`
    nativeLocale: 'en',

    // NEW: Create Chrome-like nested JSON with metadata and tags
    nested: false
  }))

localize()

Localizes files for each locale in locales. Localized files are nested in a subdirectory for each locale. The nativeLocale and locales options are required.

var gulp = require('gulp');
var l10n = require('gulp-l10n-toolkit');

gulp.task('localize', function () {
  return gulp.src('src/**/*.html')
    .pipe(l10n.localize({
      nativeLocale: 'locales/en.json',
      locales: 'locales/*.json'
    }))
    .pipe(gulp.dest('dist'));
});

gulp.task('default', ['localize']);

options

.pipe(l10n.localize({
    // Required: glob of locales to use in localizing files
    locales: 'locales/*.json',

    // Required: path of nativeLocale file
    nativeLocale: 'locales/en.json'
  }))

simulateTranslation()

This is a utility to quickly simulate translation of the native locale to a list of locales.

var gulp = require('gulp');
var l10n = require('gulp-l10n-toolkit');

gulp.task('simulate-translations', function () {
  return gulp.src('locales/en.json')
    .pipe(l10n.simulateTranslation())
    .pipe(gulp.dest('locales'));
});

options

.pipe(l10n.simulateTranslation({
    // dictionary of strings and string replacements, e.g.:
    // before: 'This is <a href="/">a test</a> string.'
    // after:  'Thís ís <a href="/">á tést</a> stríng.'
    dictionary: {
      'a': 'á',
      'e': 'é',
      'i': 'í',
      'o': 'ó',
      'u': 'ú'
    },

    // create the following simulated locales
    // defaults to: `de.json`, `es.json`, `fr.json`
    locales: ['de', 'es', 'fr']
  }))