pseudo-localization
Advanced tools
Comparing version 1.2.0 to 1.3.0
@@ -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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
392669
229
143
0