0.2.0 • Published 3 years ago

pseudo-localizer v0.2.0

Weekly downloads
4
License
MIT
Repository
github
Last release
3 years ago

Pseudo Localizer

A tiny utility that brings harmony to content authors and developers.

Why?

Most pseudo localization techniques mangle strings based on their ASCII values which creates two problems:

  1. Pseudo localization doesn't work with non-ASCII encodings
  2. Fuzzy matching doesn't work (ex: /Hello/.test('Ḥḛḛḽḽṓṓ') vs /Hello/.test('_Hello--_'))

pseudo-localizer works by taking the current string as-is and adds padding around the strings so fuzzy matches still behave properly.

Install

npm i pseudo-localizer

Usage

pseudo-localizer works in the browser, node, and deno. pseudo-localizer exports a single function that takes a string and options.

import { pseudo } from 'pseudo-localizer';

pseudo('Hello'); // Hello--
pseudo('Hello', { prefix: '_' }); // _Hello--
pseudo('Hello', { letterMultiplier: 2 }); // _Hello----

Fixed-Length Expansion

Sometimes you want to expand all strings by a percentage:

import { pseudo } from 'pseudo-localizer';

pseudo('Ahoy, matey!', { mode: 'fixed' }); // Ahoy, matey!---
pseudo('Ahoy, matey!', { mode: 'fixed', fixedMultiplier: 0.75 }); // Ahoy, matey!---------

Options

NameTypeDefault ValueRequiredDescription
mode'fixed' \| 'vowels''vowels'NoSet fixed to manually specify the string length multiplier
prefixstringNoSet a prefix to use before the pseudo string
suffixstringNoSet a suffix to use after the pseudo string
padstring'-'NoSet the pad character
vowelsstring[] \| Set<string>[a,e,i,o,u,A,E,I,O,U]NoOverride the vowels list for non-English locales
fixedMultipliernumber0.3NoIn fixed mode, override the fixed multiplier as a percentage of the original string length
letterMultipliernumber1NoSpecify a custom letter multiplier in vowel mode