Skip to content

Commit

Permalink
Fix extract of multiple phrases from single line, lvgl#31
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaly Puzrin committed Oct 29, 2020
1 parent 1357ed7 commit 4d99698
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
0.2.1 / 2020-10-29
------------------

- Fix extract of multiple phrases from single line, #31.


0.2.0 / 2020-10-29
------------------

Expand Down
4 changes: 2 additions & 2 deletions lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ const defaults = {

function create_singular_re(fn_name) {
return new RegExp(
'(?:^|[ =+,;\(])' + _.escapeRegExp(fn_name) + '\\("(.*)"\\)',
'(?:^|[ =+,;\(])' + _.escapeRegExp(fn_name) + '\\("(.*?)"\\)',
'g'
);
}

function create_plural_re(fn_name) {
return new RegExp(
'(?:^|[ =+,;\(])' + _.escapeRegExp(fn_name) + '\\("(.*)",',
'(?:^|[ =+,;\(])' + _.escapeRegExp(fn_name) + '\\("(.*?)",',
'g'
);
}
Expand Down
24 changes: 23 additions & 1 deletion test/js/test_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ describe('Parser', function () {
);
});


it('Should find scoped singular', function () {
assert.deepStrictEqual(
parse(`
Expand All @@ -47,7 +48,6 @@ describe('Parser', function () {
});



it('Should find plurals', function () {
assert.deepStrictEqual(
parse(`
Expand All @@ -70,6 +70,28 @@ describe('Parser', function () {
);
});


it('Should find multiple entries at the same line', function () {
assert.deepStrictEqual(
parse(`
foo(_("BAR"), _("BAZ"));;
`),
[
{
key: 'BAR',
line: 2,
plural: false
},
{
key: 'BAZ',
line: 2,
plural: false
}
]
);
});


it('Should keep order of results by lines', function () {
assert.deepStrictEqual(
parse(`
Expand Down

0 comments on commit 4d99698

Please sign in to comment.