Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pseudo-localization

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pseudo-localization - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

5

CHANGELOG.md

@@ -0,1 +1,4 @@

##1.3.0
- Allow blacklisting nodes ([#9](https://github.com/tryggvigy/pseudo-localization/pull/9))
## 1.2.0

@@ -18,2 +21,2 @@ - Expose `localize` function

- Tidy up psuedo language symbols maps to contain more legibile symbols
- Make pseudo language deterministic. Always use the same pseudo symbol for the same english letter.
- Make pseudo language deterministic. Always use the same pseudo symbol for the same english letter.

22

index.js

@@ -1,4 +0,8 @@

const psuedoLocalizeString = require('./localize');
const psuedoLocalizeString = require("./localize");
const pseudoLocalization = (() => {
const opts = {
blacklistedNodeNames: ["STYLE"]
};
const textNodesUnder = element => {

@@ -11,2 +15,8 @@ const walker = document.createTreeWalker(

if (isAllWhitespace) return NodeFilter.FILTER_REJECT;
const isBlacklistedNode = opts.blacklistedNodeNames.includes(
node.parentElement.nodeName
);
if (isBlacklistedNode) return NodeFilter.FILTER_REJECT;
return NodeFilter.FILTER_ACCEPT;

@@ -61,3 +71,9 @@ }

const start = (options) => {
const start = (
options = {
strategy: "accented",
blacklistedNodeNames: opts.blacklistedNodeNames
}
) => {
opts.blacklistedNodeNames = options.blacklistedNodeNames;
pseudoLocalize(document.body, options);

@@ -74,3 +90,3 @@ observer.observe(document.body, observerConfig);

stop,
localize: psuedoLocalizeString,
localize: psuedoLocalizeString
};

@@ -77,0 +93,0 @@ })();

{
"name": "pseudo-localization",
"version": "1.2.0",
"version": "1.3.0",
"description": "Dynamic pseudo-localization in the browser",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -11,3 +11,3 @@ <sub>Inspired by pseudo-localization at [Netflix](https://medium.com/netflix-techblog/pseudo-localization-netflix-12fff76fbcbe) and [Firefox](https://reviewboard.mozilla.org/r/248606/diff/2#index_header)</sub>

`pseudo-localization` is a script that performs [pseudolocalization](https://en.wikipedia.org/wiki/Pseudolocalization) against the DOM.
`pseudo-localization` is a script that performs [pseudolocalization](https://en.wikipedia.org/wiki/Pseudolocalization) against the DOM.

@@ -84,2 +84,18 @@ [Demo here](https://tryggvigy.github.io/pseudo-localization/hamlet.html). Changing text nodes and adding or removing trees of elements will trigger a pseudolocalization run on all the new text added to the DOM. Try it using the devtools.

A good use-case for `localize` is testing that strings are _actually_ being localized and not hard coded.
```js
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

@@ -124,4 +140,6 @@ `pseudo-localization` supports two strategies:

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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc