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

app-localizer

v1.2.2

Published

Application Localizer

Downloads

2,107

Readme

Application Localizer

Application Localizer package that helps with localizing applications

Pseudo Locale Generator Web Site

NPM version Build Status Coverage Status

uses Intl MessageFormat Parser that parses ICU Message strings into an AST.

tested with Intl MessageFormat that formats ICU Message strings with number, date, plural, and select placeholders to create localized messages.

used by vscode-app-localizer vscode extension

VSCode Extension Release

Features

  • Locale validator - Check for missing labels - Multi-file locale support (see example below) _ Polymer file structure _ Angular flat file structure
  • Pseudo locale generator (char mapping is taken from pseudolocalization-tool)
    • Accents on letters
    • Longer sentence
    • Longer word
    • Right-to-Left
    • Enclose in exclamations
    • Enclose in brackets - Support ICU Message syntax
  • Cross-platform

Install

npm install app-localizer

API Reference

Pseudo locale generator options

  • expander Sentence expand factor 0.3 = 30%
  • wordexpander Word expand factor 0.5 = 50%
  • brackets Enclose sentence in brackets
  • exclamations Enclose sentence in exclamations
  • accents Convert letter to its accent version
  • rightToLeft RTL writing systems
  • forceException Force throwing syntax exception if any

Locale validator options

  • filePathPattern Locale files path (supports node glob pattern)
  • multiFile Each locale is in separate file in the same folder
  • fileStructure Structure of locale file content (polymer or angular.flat file structure)

Usage

Locale validator

Validate locale file(s) (e.g. gulp)

const gulp = require("gulp");
const localizer = require("app-localizer");

gulp.task("validateLocales", function validateLocales(callback) {
  localizer.validateLocales(
    "locales/app1/",
    { multiFile: true, fileStructure: "polymer" },
    undefined,
    result => {
      // result contains missing labels if any
      callback(result);
    }
  );
});

gulp.task("validateMultipleLocales", function validateMultipleLocales(
  callback
) {
  localizer.validateMultipleLocales(
    ["locales/app1/", "locales/app2/"],
    { multiFile: true, fileStructure: "polymer" },
    undefined,
    result => {
      // result contains missing labels if any
      callback(result);
    }
  );
});

Pseudo locale generator

Generate pseudo locale json file from source (gulp)

const gulp = require("gulp");
const localizer = require("app-localizer");
const rename = require("gulp-rename");

gulp.task("locales", function generatePseudoLocale() {
  gulp
    .src("app/locales/en-us.json")
    .pipe(rename("pseudo.json"))
    .pipe(
      localizer.pseudoLocalize({
        expander: 0.2,
        accents: true,
        rightToLeft: false,
        exclamations: true,
        brackets: true,
        wordexpander: 0.5,
        forceException: false,
        pseudoLocaleName: "en-us"
      })
    )
    .pipe(gulp.dest("dist/locales/"));
});

Generate pseudo locale json file from source (grunt)

const localizer = require("app-localizer");

module.exports = function gruntEntry(grunt) {
  grunt.initConfig({
    pkg: grunt.file.readJSON("package.json"),
    pseudo: {
      options: {
        expander: 0.2,
        exclamations: true,
        brackets: true,
        accents: true,
        rightToLeft: false,
        wordexpander: 0.5,
        forceException: false,
        pseudoLocaleName: "en-us"
      },
      dist: {
        files: {
          "app/locales/pseudo.json": ["app/locales/en-us.json"]
        }
      }
    }
  });

  grunt.registerMultiTask("pseudo", "Pseudolocalize locale", function() {
    const options = this.options();
    this.files.forEach(file => {
      if (file.dest) {
        file.src.forEach(source => {
          const text = grunt.file.read(source);
          const result = localizer.pseudoLocalizeContent(options, text);

          grunt.file.write(file.dest, result);
        });
      }
    });
  });
};

Generate pseudo pseudo text (browser)

npm install intl-messageformat-parser
npm install app-localizer
	<script type="text/javascript" src="/node_modules/intl-messageformat-parser/dist/parser.js" defer></script>
	<script type="text/javascript" src="/node_modules/app-localizer/localizer.js" defer></script>
	<script type="text/javascript">
		function transform() {
			'use strict';
			const text = AppLocalizer.toPseudoText('some text', { expander: 0.5, accents: true, wordexpander: 0.2 }, IntlMessageFormatParser);
			console.log(text);
		}
	</script>

Generate pseudo locale text (try it)

transforms

!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_abcdefghijklmnopqrstuvwxyz|~

into

¡″♯€‰⅋´{}⁎⁺،‐·⁄⓪①②③④⑤⑥⑦⑧⑨∶⁏≤≂≥¿՞ÅƁÇÐÉƑĜĤÎĴĶĻṀÑÖÞǪŔŠŢÛṼŴẊÝŽ⁅∖⁆˄‿‵åƀçðéƒĝĥîĵķļɱñöþǫŕšţûṽŵẋýž¦˞

const localizer = require("app-localizer");

const pseudoText = localizer.toPseudoText(text, {
  expander: 0.2,
  exclamations: true,
  brackets: true,
  accents: true,
  rightToLeft: false,
  wordexpander: 0.5,
  forceException: false
});

Single-File locale example

file with locales /locales/locale.json

{
  "en-us": {
    "label3": "blah3 {token}",
    "label1": "blah1",
    "label2": "blah2",
    "label4": "blah4"
  },
  "de-de": {
    "label3": "blah3 {token}",
    "label1": "blah1",
    "label2": "blah2",
    "label4": "blah4"
  }
}

Multi-File locale example

locale files should be in the same folder

file with en-us locale /locales/en-us.json (polymer file structure)

{
  "en-us": {
    "label3": "blah3 {token}",
    "label1": "blah1",
    "label2": "blah2",
    "label4": "blah4"
  }
}

file with fr locale /locales/fr.locale.json (angular flat file structure)

{
  "label1": "blah1 {{token}}",
  "label2": "blah2",
  "label5": "blah3",
  "label3": "blah4"
}

Change Log

Change Log

License

MIT