Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update command line to handle nested json objects #7

Open
wants to merge 38 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
09ef708
Update Readme.md
jacalata Aug 5, 2014
7b419a6
Update command line to handle nested json objects
jacalata Sep 29, 2014
cc9f772
Pseudolocalize strings in an object
sierawski Apr 3, 2016
c4a93a3
Merge remote-tracking branch 'refs/remotes/bunkat/master'
jacalata Jul 1, 2017
3768c8f
Merge remote-tracking branch 'refs/remotes/origin/patch-1'
jacalata Aug 6, 2017
4769b7e
Revert "Update command line to handle nested json objects"
jacalata Aug 6, 2017
5789fdb
Merge remote-tracking branch 'refs/remotes/patch1/master'
jacalata Aug 6, 2017
1351a1e
change package.json to publish on npm
jacalata Aug 6, 2017
e36b168
spacefix
Johnken-S Feb 20, 2018
aa75ec9
Array of Exotic strings
Johnken-S Feb 22, 2018
3e8f1b9
variable name change
Johnken-S Feb 23, 2018
6e2d4fd
Merge pull request #1 from Johnken-S/fixpad
jacalata Feb 23, 2018
18b8d6b
Merge pull request #1 from Johnken-S/fixpad
Johnken-S Feb 28, 2018
1c61420
Updated Extend section
Johnken-S Feb 28, 2018
7061cde
update based on Mick's suggesstions
Johnken-S Mar 1, 2018
461c1f7
Merge pull request #2 from Johnken-S/update_Readme
jacalata Mar 1, 2018
ebb59ad
update tests for double-byte padding characters
jacalata Mar 11, 2018
ebb425a
update package number for publishing
jacalata Mar 11, 2018
153f24e
Apply changes from 18b8d6b to source
probertson-hv Jun 1, 2018
a505c61
Add `build` and `minify` entries to package.json scripts
probertson-hv Jun 1, 2018
211fb6c
Remove Makefile
probertson-hv Jun 2, 2018
43eb3a2
Update built files
probertson-hv Jun 2, 2018
422463e
Update README
probertson-hv Jun 2, 2018
db2e941
Add support for specifying multiple delimiter pairs (or singles)
probertson-hv Jun 2, 2018
2d85820
Add documentation for `delimiters` option
probertson-hv Jun 2, 2018
09ec791
Merge pull request #3 from probertson/update-build-process
jacalata Jun 5, 2018
8d377dc
Merge pull request #4 from probertson/multi-delimiter-support
jacalata Jun 6, 2018
2ca0954
Remove one more reference to 'pseudoloc.cov'
probertson-hv Jun 19, 2018
8203694
Merge pull request #5 from probertson/remove-pseudoloc-cov
jacalata Jun 20, 2018
97ce82f
Fixes to padding algorithm and tests
micktm Jun 28, 2018
539c811
bump version to 1.2.0
jacalata Sep 12, 2018
8839ada
Merge pull request #6 from MickMonaghan/extend-characters
jacalata Sep 12, 2018
fec3888
Merge branch 'master' of https://github.com/jacalata/pseudoloc
jacalata Sep 12, 2018
355aba8
bump version to include padding fix and test fix
jacalata Sep 12, 2018
3f04bf2
Add bin configuration to package.json
nigelzor Jan 9, 2019
35b827f
Merge pull request #7 from nigelzor/patch-1
jacalata Jan 9, 2019
e8a1143
Merge branch 'master' of https://github.com/jacalata/pseudoloc
jacalata Jan 31, 2019
6313c7f
add more build scripts to make it easier on windows
jacalata Jan 31, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
node_modules
src-cov
pseudoloc-cov.js
53 changes: 0 additions & 53 deletions Makefile

This file was deleted.

81 changes: 66 additions & 15 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Pseudoloc v1.1.0 [![Build Status](https://travis-ci.org/bunkat/pseudoloc.png)](https://travis-ci.org/bunkat/pseudoloc)
# Pseudoloc v1.2.1 [![Build Status](https://travis-ci.org/bunkat/pseudoloc.png)](https://travis-ci.org/bunkat/pseudoloc)

_Pseudoloc_ is a small library for quickly pseudolocalizing strings. [Pseudolocalization](http://en.wikipedia.org/wiki/Pseudolocalization) is a method for testing the internationalization aspects of your application by replacing your strings with altered versions that maintains string readability while including the most problematic characteristics including text length and character length. It also makes hard coded strings and improperly concatenated strings easy to spot so that they can be properly localized.

Expand All @@ -21,33 +21,43 @@ _Pseudoloc_ is a small library for quickly pseudolocalizing strings. [Pseudoloca

## Using from the commandline

_Pseudoloc_ includes a commandline interface to make it easy to incorporate it into your build process. Currently it supports passing in individual strings (great for trying things out) or passing in a valid `JSON` document that contains a set of keys and strings. Each of the strings in the file will then be pseudolocalized.
_Pseudoloc_ includes a commandline interface to make it easy to incorporate it into your build process. Currently it supports passing in individual strings (great for trying things out) or passing in a valid `JSON` document. Each of the value in the file that is a string will then be pseudolocalized.

Note: Nodejs must be installed to use the commandline interface.

./bin/pseudoloc -string 'A test string with a %token%.'
node ./bin/pseudoloc --string 'A test string with a %token%.'
// [!!Á ţȇšŧ śťřīņğ ŵıţħ ą %token%.!!]


// example.json
{
"string1": "this is the first string",
"string2": "a string with a %token%",
"string3": "a string with a %couple% of %tokens%"
"string3": "a string with a %couple% of %tokens%",
"obj1": {
"string1": "this is the first string",
"string2": "a string with a %token%",
"string3": "a string with a %couple% of %tokens%"
}
}

./bin/pseudoloc -readFile example.json -writeFile example-pseudo.json
node ./bin/pseudoloc -readFile example.json -writeFile example-pseudo.json

// example-pseudo.json
{
"string1": "[!!ţĥĩş ĭś ťĥě ƒĩŗśŧ şţřįƞĝ!!]",
"string2": "[!!ȁ ŝťŗĩňğ ŵįťĥ ã %token%!!]",
"string3": "[!!ȃ şťřīňğ ŵĩťħ ä %couple% ŏƒ %tokens%!!]"
"string1": "[!!ţĥıś ıś ţĥę ƒıŕśţ śţŕıńĝ!!]",
"string2": "[!!ȃ šŧřįƞģ ŵįŧħ ȃ %token%!!]",
"string3": "[!!à śţŕīńĝ ŵīţĥ à %couple% ōƒ %tokens%!!]",
"obj1": {
"string1": "[!!ţĥıś ıś ţĥę ƒıŕśţ śţŕıńĝ!!]",
"string2": "[!!ȃ šŧřįƞģ ŵįŧħ ȃ %token%!!]",
"string3": "[!!à śţŕīńĝ ŵīţĥ à %couple% ōƒ %tokens%!!]"
}
}

The commandline tool uses the same options as the library. For additional help and more examples:

./bin/pseudoloc --help
node ./bin/pseudoloc --help

## Options

Expand All @@ -71,7 +81,7 @@ Default is `!!]`.
pseudoloc.str('A test string with a %token%.')
// [!!Á ţȇšŧ śťřīņğ ŵıţħ ą %token%.##]

#### Delimiter, StartDelimiter, EndDelimiter
#### Delimiter, StartDelimiter, EndDelimiter, Delimiters

Specifies the token delimiter. Any characters between token delimiters will not be pseudolocalized. Tokens are used to replace data within localized strings. You can either specify a single delimiter or use startDelimiter and endDelimiter to specify the delimiters seperately.

Expand All @@ -86,16 +96,51 @@ Default is `%`.
pseudoloc.str('A test string with a {{token}}.')
// [!!Á ţȇšŧ śťřīņğ ŵıţħ ą {{token}}.!!]

If you need to support multiple types of delimiters, you can pass an array of delimiters (single or pairs) to the `delimiters` option.

The `delimiters` option takes an array of objects. Set properties on the objects as follows:

* `{ start, end }`: specifies a pair of start and end delimiters, just like using `startDelimiter` and `endDelimiter`:
```
{ start: '<', end: '>' }
```

* `{ both }`: specifies a marker to use as both the start and end delimiters, just like using `delimiter`
```
{ both: '$$' }
```

* `{ full }`: specifies the entire pattern for the delimiter. This is useful for cases where the token doesn't have a start marker, name, and end marker, for example with printf-style placeholders `%s`, `%d`, etc.
```
{ full: '%d' }
```

Under the hood these strings are combined into a pattern that eventually is compiled into a RegExp. That can affect you in a couple of ways:

1. You can use regular expression matchers in your delimiters
2. If your delimiter includes any characters that are special characters in regular expressions, they will need to be escaped

For example, to match named sprintf-style placeholders (such as `%(name)s`), you need to escape the parentheses:

// Note the double-backslash, which becomes a `\(` in the string
pseudoloc.option.startDelimiter = '%\\(';
// Note the square brackets, so it matches `)s` or `)d`
pseudoloc.option.endDelimiter = '\\)[sd]';
pseudoloc.str('A test string with a %(token)s.');
// [!!Á ţȇšŧ śťřīņğ ŵıţħ ą %(token)s.!!]

#### Extend

Extends the width of the string by the specified percentage. Useful if you will be localizing into languages such as German which can be 30% longer than English.
We extend the string by randomly selecting characters from a predefined array of non-ASCII characters.

Default is `0`.

pseudoloc.option.extend = 0.3; //30%
pseudoloc.str('A test string with a %token%.')
// [!!Ȃ ťēšť ŝťŕĩʼnğ ŵĩťħ â %token%. !!]
// [!!Ȃ ťēšť ŝťŕĩʼnğ ŵĩťħ â %token%. öఛฒそ!!]

New update: Extends the width of the string by the specified percentage will be filled with predefined array of non-ASCII characters.

#### Override

Expand All @@ -110,22 +155,28 @@ Default is `undefined`.
## Installation
Using npm:

$ npm install pseudoloc
$ npm install pseudoloc-js

## Building

To build the javascript files for _pseudoloc_, run `npm install` to install dependencies and then:

$ npm run build

## Making minified build

To build the minified javascript files for _pseudoloc_, run `npm install` to install dependencies and then:

$ make build
$ npm run minify

## Running tests

To run the tests for _pseudoloc_, run `npm install` to install dependencies and then:

$ make test
$ npm run test

## Running benchmarks

To run the benchmarks for _pseudoloc_, run `npm install` to install dependencies and then:

$ make benchmark
$ npm run benchmark
11 changes: 8 additions & 3 deletions bin/example-pseudo.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"string1": "[##ţĥĩş ĭś ťĥě ƒĩŗśŧ şţřįƞĝ@@]",
"string2": "[##ȁ ŝťŗĩňğ ŵįťĥ ã %token%@@]",
"string3": "[##ȃ şťřīňğ ŵĩťħ ä %couple% ŏƒ %tokens%@@]"
"string1": "[##ţĥıś ıś ţĥę ƒıŕśţ śţŕıńĝ@@]",
"string2": "[##ȃ šŧřįƞģ ŵįŧħ ȃ %token%@@]",
"string3": "[##à śţŕīńĝ ŵīţĥ à %couple% ōƒ %tokens%@@]",
"obj1": {
"string1": "[##ţĥıś ıś ţĥę ƒıŕśţ śţŕıńĝ@@]",
"string2": "[##ȃ šŧřįƞģ ŵįŧħ ȃ %token%@@]",
"string3": "[##à śţŕīńĝ ŵīţĥ à %couple% ōƒ %tokens%@@]"
}
}
7 changes: 6 additions & 1 deletion bin/example.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"string1": "this is the first string",
"string2": "a string with a %token%",
"string3": "a string with a %couple% of %tokens%"
"string3": "a string with a %couple% of %tokens%",
"obj1": {
"string1": "this is the first string",
"string2": "a string with a %token%",
"string3": "a string with a %couple% of %tokens%"
}
}
4 changes: 1 addition & 3 deletions bin/pseudoloc
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ else {
}

var result = JSON.parse(data);
for(var id in result) {
result[id] = pseudoloc.str(result[id]);
}
pseudoloc.obj(result);

var dir = path.dirname(program.readFile),
ext = path.extname(program.readFile),
Expand Down
5 changes: 0 additions & 5 deletions component.json

This file was deleted.

Loading