All Projects → tryggvigy → Pseudo Localization

tryggvigy / Pseudo Localization

Licence: mit
Dynamic pseudo-localization in the browser and nodejs

Programming Languages

language
365 projects

Projects that are alternatives of or similar to Pseudo Localization

rosetta
A blazing fast internationalization (i18n) library for Crystal with compile-time key lookup.
Stars: ✭ 23 (-78.9%)
Mutual labels:  i18n, translation, internationalization, localization, l10n
labels
Bolt Labels extension - Translatable labels for Bolt
Stars: ✭ 18 (-83.49%)
Mutual labels:  i18n, translation, internationalization, localization, l10n
Mojito
An automation platform that enables continuous localization.
Stars: ✭ 256 (+134.86%)
Mutual labels:  translation, i18n, localization, internationalization, l10n
Node Gettext
A JavaScript implementation of gettext, a localization framework.
Stars: ✭ 175 (+60.55%)
Mutual labels:  translation, i18n, localization, internationalization, l10n
i18n
internationalize projects to Arabic
Stars: ✭ 67 (-38.53%)
Mutual labels:  i18n, translation, internationalization, localization, l10n
Weblate
Web based localization tool with tight version control integration.
Stars: ✭ 2,719 (+2394.5%)
Mutual labels:  translation, i18n, localization, internationalization, l10n
Dom I18n
Provides a very basic HTML multilingual support using JavaScript
Stars: ✭ 125 (+14.68%)
Mutual labels:  translation, i18n, localization, internationalization, l10n
inlang
Open Source Localization Solution for Software.
Stars: ✭ 160 (+46.79%)
Mutual labels:  i18n, translation, internationalization, localization, l10n
Fluent.js
JavaScript implementation of Project Fluent
Stars: ✭ 622 (+470.64%)
Mutual labels:  translation, i18n, localization, internationalization, l10n
Tower
i18n & L10n library for Clojure/Script
Stars: ✭ 264 (+142.2%)
Mutual labels:  translation, i18n, localization, l10n
Eo Locale
🌏Internationalize js apps 👔Elegant lightweight library based on Internationalization API
Stars: ✭ 290 (+166.06%)
Mutual labels:  translation, i18n, localization, internationalization
Gotext
Go (Golang) GNU gettext utilities package
Stars: ✭ 292 (+167.89%)
Mutual labels:  translation, i18n, internationalization, l10n
Laravel Js Localization
🌐 Convert your Laravel messages and consume them in the front-end!
Stars: ✭ 451 (+313.76%)
Mutual labels:  i18n, localization, internationalization, l10n
Js Lingui
🌍📖 A readable, automated, and optimized (5 kb) internationalization for JavaScript
Stars: ✭ 3,249 (+2880.73%)
Mutual labels:  translation, i18n, localization, internationalization
i18n
Package i18n is for app Internationalization and Localization.
Stars: ✭ 79 (-27.52%)
Mutual labels:  i18n, internationalization, localization, l10n
Easy localization
Easy and Fast internationalizing your Flutter Apps
Stars: ✭ 407 (+273.39%)
Mutual labels:  translation, i18n, localization, internationalization
python-fluent
Python implementation of Project Fluent
Stars: ✭ 142 (+30.28%)
Mutual labels:  i18n, internationalization, localization, l10n
React Localize Redux
Dead simple localization for your React components
Stars: ✭ 384 (+252.29%)
Mutual labels:  translation, i18n, localization, internationalization
Fluent
Fluent — planning, spec and documentation
Stars: ✭ 818 (+650.46%)
Mutual labels:  translation, localization, internationalization, l10n
Redux React I18n
An i18n solution for React/Redux and React Native projects
Stars: ✭ 64 (-41.28%)
Mutual labels:  i18n, localization, internationalization, l10n

Inspired by pseudo-localization at Netflix and Firefox

pseudo-localization

English Pseudo Language
screen shot 2018-08-12 at 1 23 18 pm after

Edit pseudo-localization-react

pseudo-localization is a script that performs pseudolocalization against the DOM or individual strings.

Demo here. Changing text nodes and adding or removing trees of elements will trigger a pseudo-localization run on all the new text added to the DOM. Try it yourself by changing text or adding/removing elements using the devtools.

Installation

Through npm

npm install pseudo-localization

Raw script (without npm)

Copy paste the files in src and use as you wish. It's not a lot of code.

Usage

import or require the npm module

pseudo-localization can be used like so:

import pseudoLocalization from 'pseudo-localization';
// Or using CommonJS
// const pseudoLocalization = require('pseudo-localization').default;

pseudoLocalization.start();

// Later, if needed
pseudoLocalization.stop();

To use pseudo-localization in React, Vue, Ember or anything else, hook the start and stop methods into your libraries component lifecycles. In React for example:

import React from 'react';
import pseudoLocalization from 'pseudo-localization';

class PseudoLocalization extends React.Component {
  componentDidMount() {
    pseudoLocalization.start();
  }
  componentWillUnmount() {
    pseudoLocalization.stop();
  }
}

// And use it

class Page extends React.Component {
  render() {
    return (
      <main>
       <PseudoLocalization />
       <h1>I will get pseudo localized along with everything else under document.body!</h1>
      <main>
    );
  }
}

Using hooks? Here's an example:

import React from 'react';
import pseudoLocalization from 'pseudo-localization';

function PseudoLocalization() {
  React.useEffect(() => {
    pseudoLocalization.start();

    return () => {
      pseudoLocalization.stop()
    };
  }, []);
}

// And use it

function Page() {
  return (
    <main>
      <PseudoLocalization />
      <h1>I will get pseudo localized along with everything else under document.body!</h1>
    <main>
  );
}

You can also call the underlying localize function to pseudo-localize any string. This is useful for non-browser environments like nodejs.

import { localize } from 'pseudo-localization';
// Or using CommonJS
// const { localize } = require('pseudo-localization');

console.log(localize('hello')); // --> ħḗḗŀŀǿǿ
console.log(localize('hello', { strategy: 'bidi' })); // --> oʅʅǝɥ

A good use-case for localize is testing that strings are actually being localized and not hard coded.

import { localize } from 'pseudo-localization';
import translate from './my-translation-lib';

// Pseudo localize every string returned from your normal translation function.
const _ = key => localize(translate(key, navigator.language));

_('Some Localized Text'); // Şǿǿḿḗḗ Ŀǿǿƈȧȧŀīẑḗḗḓ Ŧḗḗẋŧ
// Or, in React for example
const Header = () => <h1>{_('Localized Header Text')}</h1>;

Any strings that do not pass through the translation function will now stand out in the UI because the will not be pseudo-localized.

Strategies

pseudo-localization supports two strategies:

  1. accented
  2. bidi

accented - Ȧȧƈƈḗḗƞŧḗḗḓ Ḗḗƞɠŀīīşħ

Usage: pseudoLocalization.start({ strategy: 'accented' }); or simply pseudoLocalization.start();.

In Accented English all Latin letters are replaced by accented Unicode counterparts which don't impair the readability of the content. This allows developers to quickly test if any given string is being correctly displayed in its 'translated' form. Additionally, simple heuristics are used to make certain words longer to better simulate the experience of international users.

screen shot 2018-08-19 at 18 48 29

bidi - ɥsıʅƃuƎ ıpıԐ

Usage: pseudoLocalization.start({ strategy: 'bidi' });.

Bidi English is a fake RTL locale. All words are surrounded by Unicode formatting marks forcing the RTL directionality of characters. In addition, to make the reversed text easier to read, individual letters are flipped.

screen shot 2018-08-19 at 18 45 49

Why?

To catch localization problems like:

  • Translated text that is significantly longer than the source language, and does not fit within the UI constraints, or which causes text breaks at awkward positions.
  • Font glyphs that are significantly larger than, or possess diacritic marks not found in, the source language, and which may be cut off vertically.
  • Languages for which the reading order is not left-to-right, which is especially problematic for user input.
  • Application code that assumes all characters fit into a limited character set, such as ASCII or ANSI, which can produce actual logic bugs if left uncaught.

In addition, the pseudo-localization process may uncover places where an element should be localizable, but is hard coded in a source language.

Docs

pseudo-localization exports three functions.

  • pseudoLocalization.start(options)
  • pseudoLocalization.stop()
  • pseudoLocalization.localize(string, options)

pseudoLocalization.start(options)

Pseudo localizes the page and watched the DOM for additions/updates to continuously pseudo localize new content.

Accepts an options object as an argument. Here are the keys in the options object.

strategy - default ('accented')

The pseudo localization strategy to use when transforming strings. Accepted values are accented or bidi.

blacklistedNodeNames - default (['STYLE'])

An array of Node.nodeName strings that will be ignored when localizing. This is useful for skipping <style>, <text> svg nodes or other nodes that potentially doesn't make sense to apply pseudo localization to. <style> is skipped by default when blacklistedNodeNames is not provided.

pseudoLocalization.stop()

Stops watching the DOM for additions/updates to continuously pseudo localize new content.

pseudoLocalization.localize(string, options)

Accepts a string to apply pseudo localization to. Returns the pseudo localized version on the string. This function is used by pseudoLocalization.start internally.

Accepts an options object as an argument. Here are the keys in the options object.

strategy - default ('accented')

The pseudo localization strategy to use when transforming strings. Accepted values are accented or bidi.

CLI Interface

For easy scripting a CLI interface is exposed. The interface supports raw input, JSON files, and CommonJS modules.

npx pseudo-localization ./path/to/file.json

# pass in a JS transpiled ES module or an exported CJS module
npx pseudo-localization ./path/to/file

# pass in JSON files through STDIN
cat ./path/to/file.json | npx pseudo-localization --strategy bidi

# pass a string via a pipe
echo hello world | npx pseudo-localization

# direct input pseudo-localization
npx pseudo-localization -i "hello world"

CLI Options:

pseudo-localization [src] [options]

Pseudo localize a string, JSON file, or a JavaScript object

Positionals:
  src  The source as a path or from STDIN                               [string]

Options:
  -o, --output  Writes output to STDOUT by default. Optionally specify a JSON
                file to write the pseudo-localizations to               [string]
  -i, --input   Pass in direct input to pseudo-localization                 [string]
  --debug       Print out all stack traces and other debug info        [boolean]
  --pretty      Pretty print JSON output                               [boolean]
  --strategy    Set the strategy for localization
                             [choices: "accented", "bidi"] [default: "accented"]
  --help        Show help                                              [boolean]
  --version     Show version number                                    [boolean]

Support

Works in all evergreen browsers.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].