You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

app-localizer

Package Overview
Dependencies
1
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

app-localizer

Application Localizer


Version published
Weekly downloads
139
decreased by-43.5%
Maintainers
1
Created
Weekly downloads
 

Changelog

Source

1.2.2 (March 9, 2018)

  • Issue: angular.flat vscode base local handling issue fix

Readme

Source

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

Keywords

FAQs

Package last updated on 09 Mar 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc